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:
Root
word list
in the Gforth source).
THEN
and ENDIF
can be
defined as synonyms).
Synonym
( "name" "oldname" – ) tools-ext “Synonym”
Define name to behave the same way as oldname: Same
interpretation semantics, same compilation semantics, same
to
, +to
, is
, action-of
and
addr
semantics.
Gforth also offers the Gforth-specific alias
, that allows to
define another word with the same execution token, but otherwise
default semantics (no copying of compilation or other semantics). 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 ." 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 : test-bar1 bar1 ; \ no output test-bar1 \ "foo" : test-bar2 bar2 ; \ "foo" test-bar2 \ no output : test-bar3 bar3 ; \ "foo" test-bar3 \ no output
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).