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

[REBOL] returning an object from a function, sort of Re:

From: larry:ecotope at: 17-Aug-2000 10:10

Hi Pete Not sure exactly what you want, but here is a start. Because you want the arg of the factory function to become the name of an object, it is probably best to require it to be a word. The interpreter will then throw an error if the arg is not a valid REBOL word before the function is called. This is also consistent with your stated call syntax
>> logo-factory Logo1 ; the arg Logo1 is a word in this call, not a
string We don't want the arg to be evaluated, so we need to quote it in the arg list (there are other ways of accomplishing the goal, but this is a good one). The following function generates the named object and also shows how to use the given arg in definitions local to the returned object.
>> logo-factory: func ['arg [word!]] [set arg make object! [name: arg]] >> logo-factory logo1 ;note REBOL is case insensitive >> probe logo1
make object! [ name: 'logo1 ]
>> logo1/name
== logo1
>> type? logo1/name
== word! HTH -Larry