Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: the utility of 'bind

From: krobillard:cox at: 21-Jan-2004 20:30

You can use bind to execute functions in a protected context. I have done this in a compiler for a game scripting language. I could have implemented the compiler with parse, but then I could not make use of Rebol constructs within my custom game dialect. By making the game commands normal functions the capabilities of Rebol can be leveraged to expand macros and templates, evaluate mathematical expressions, do conditional compilation, etc. In order not to pollute the global namespace, these game commands are placed within a context, and to compile a block of code in that context requires bind. REBOL [] game-script-compiler: context [ commands: context [ ; These emit bytecode. run: func [speed] [print ["emit run" speed "here"] ] jump: func [height] [print ["emit jump" height "here"] ] laugh: does [print "emit laugh here"] ] set 'compile func [code] [ do bind code in commands 'run ] ] compile [ run 1.4 jump 2.0 laugh run 1.4 * 0.8 ; Rebol will evaluate this for us as normal. ] -Karl On Wednesday 21 January 2004 09:41 am, Andreas Bolka wrote: