6.10.13 Aliases

The defining word synonym allows you to define a word by name that has the same behaviour as some other word. Here are two situation where this can be useful:

Synonym ( "name" "oldname" –  ) tools-ext “Synonym”

Define name to behave the same way as oldname: Same interpretation semantics, same compilation semantics, same to/defer! and defer@ semantics.

Gforth also offers the non-standard alias, that does not inherit the compilation semantics, to name semantics etc. from its parent. You can then change, e.g., the compilation semantics with, e.g., immediate.

Alias ( xt "name" –  ) gforth-0.2 “Alias”

Define name as a word that performs xt. Unlike for deferred words, aliases don’t have an indirection overhead when compiled.

Example:

: foo ... ; immediate

' foo Alias bar1           \ bar1 is not an immediate word
' foo Alias bar2 immediate \ bar2 is an immediate word
synonym bar3 foo           \ bar3 is an immediate word

Both synonyms and aliases have a different nt than the original, but ticking it (or using name>interpret) produces the same xt as the original (see Tokens for Words).