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

[REBOL] Re: Troube Calling Function within Object

From: larry:ecotope at: 28-Nov-2000 12:58

Hi Jamey You could try something along these lines.
>> player: make object! [f: func [x][x * x]] >> table: "player"
== "player"
>> do reduce [get in get to-word table 'f 6]
== 36 When the block is reduced TABLE evaluates to its string value "player", GET returns the object named player, IN returns a reference to the field named f, the outer GET returns the function f itself. This is the first element of the reduced block, the second is the reduced value of 6 which is still 6. Finally, the do applies the function to the argument 6. Using this approach will cause the argument of the function to be evaluated twice, once by reduce and again when the do applies the function to the argument. Or, more simply, you can also just create a word in the outer context to hold the function and use it normally.
>> ff: get in get to-word table 'f >> ff 5
== 25 HTH -Larry