version 1.131, 2004/09/13 07:32:37
|
version 1.132, 2004/11/28 20:20:37
|
Line 6619 Defer greet ( -- )
|
Line 6619 Defer greet ( -- )
|
: bar ... greet ... ; |
: bar ... greet ... ; |
: greet1 ( -- ) ." Good morning" ; |
: greet1 ( -- ) ." Good morning" ; |
: greet2 ( -- ) ." Hello" ; |
: greet2 ( -- ) ." Hello" ; |
' greet2 <IS> greet \ make greet behave like greet2 |
' greet2 IS greet \ make greet behave like greet2 |
@end example |
@end example |
|
|
@progstyle |
@progstyle |
Line 6635 this:
|
Line 6635 this:
|
@example |
@example |
: real: : ; \ retain access to the original |
: real: : ; \ retain access to the original |
defer : \ redefine as a deferred word |
defer : \ redefine as a deferred word |
' my: <IS> : \ use special version of : |
' my: IS : \ use special version of : |
\ |
\ |
\ load application here |
\ load application here |
\ |
\ |
' real: <IS> : \ go back to the original |
' real: IS : \ go back to the original |
@end example |
@end example |
|
|
|
|
One thing to note is that @code{<IS>} consumes its name when it is |
One thing to note is that @code{IS} has special compilation semantics, |
executed. If you want to specify the name at compile time, use |
such that it parses the name at compile time (like @code{TO}): |
@code{[IS]}: |
|
|
|
@example |
@example |
: set-greet ( xt -- ) |
: set-greet ( xt -- ) |
[IS] greet ; |
IS greet ; |
|
|
' greet1 set-greet |
' greet1 set-greet |
@end example |
@end example |
|
|
|
In situations where @code{IS} does not fit, use @code{defer!} instead. |
|
|
A deferred word can only inherit execution semantics from the xt |
A deferred word can only inherit execution semantics from the xt |
(because that is all that an xt can represent -- for more discussion of |
(because that is all that an xt can represent -- for more discussion of |
this @pxref{Tokens for Words}); by default it will have default |
this @pxref{Tokens for Words}); by default it will have default |
Line 6662 semantics. However, you can change the
|
Line 6663 semantics. However, you can change the
|
semantics of the deferred word in the usual ways: |
semantics of the deferred word in the usual ways: |
|
|
@example |
@example |
: bar .... ; compile-only |
: bar .... ; immediate |
Defer fred immediate |
Defer fred immediate |
Defer jim |
Defer jim |
|
|
' bar <IS> jim \ jim has default semantics |
' bar IS jim \ jim has default semantics |
' bar <IS> fred \ fred is immediate |
' bar IS fred \ fred is immediate |
@end example |
@end example |
|
|
doc-defer |
doc-defer |
doc-<is> |
doc-defer! |
doc-[is] |
|
doc-is |
doc-is |
|
doc-defer@ |
|
doc-action-of |
@comment TODO document these: what's defers [is] |
@comment TODO document these: what's defers [is] |
doc-what's |
|
doc-defers |
doc-defers |
|
|
@c Use @code{words-deferred} to see a list of deferred words. |
@c Use @code{words-deferred} to see a list of deferred words. |
|
|
Definitions in ANS Forth for @code{defer}, @code{<is>} and @code{[is]} |
Definitions of these words (except @code{defers}) in ANS Forth are |
are provided in @file{compat/defer.fs}. |
provided in @file{compat/defer.fs}. |
|
|
|
|
@node Aliases, , Deferred words, Defining Words |
@node Aliases, , Deferred words, Defining Words |