www.delorie.com/gnu/docs/gforth/gforth_50.html   search  
 
Buy GNU books!


Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.33 Literal

You cannot POSTPONE numbers:

 
: [FOO] POSTPONE 500 ; immediate

Instead, you can use LITERAL (compilation: n --; run-time: -- n ):

 
: [FOO] ( compilation: --; run-time: -- n )
  500 POSTPONE literal ; immediate

: flip [FOO] ;
flip .
see flip

LITERAL consumes a number at compile-time (when it's compilation semantics are executed) and pushes it at run-time (when the code it compiled is executed). A frequent use of LITERAL is to compile a number computed at compile time into the current word:

 
: bar ( -- n )
  [ 2 2 + ] literal ;
see bar

Assignment:
Write ]L which allows writing the example above as : bar ( -- n ) [ 2 2 + ]L ;


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003