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

[REBOL] context of a function - Enhancement request Re:

From: rebol:techscribe at: 21-Aug-2000 22:23

Hi Frank,
>Good idea?
Yes. Let's go:
>> f: func [a] [a] >> in-func :f 'a
== a
>> f 3
== 3
>> get in-func :f 'a
== 3
>> f 4
== 4
>> get in-func :f 'a
== 4 in-func is based on the the cfunc from my earlier email and a modified get-context-block function: in-func: func [f [function!] word [word!] /local cb ] [ cb: get-context-block :f return bind :word first cb ] get-context-block: func [f [function!] /local block] [ either all [ function? :f (pick second :f 1) = 'self ] [ fblock: make block! length? first :f foreach word first :f [ if not :word = /local [ append fblock to word! word ] ] return bind fblock first second :f ][ return none ] ] cfunc: func [spec body] [ "Defines a user function with given spec and body and adds the word self." [catch] spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] "The body block of the function" either found? find spec /local [ insert tail spec 'self ][ insert tail spec [/local self] ] insert body 'self throw-on-error [make function! spec body] ] BTW
>same? first second :f in :f 'a >== true
does not work for objects:
>> o: make object! [a: none b: none] >> second first :o
== a
>> in :o 'a
== a
>> same? (second first :o) (in :o 'a)
== false so I wouldn't expect it to work for functions either. At 01:23 PM 8/21/00 +0200, you wrote:
>The best sollution would be to enhance "in" so you can not only get words >out of object's context, but also out of functions context. > >f: func [a] [a] > >f 2 > >in :f 'a >== a > >same? first second :f in :f 'a >== true > >Good idea? >Frank >
;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com