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

[REBOL] Re: Web site update

From: lmecir:mbox:vol:cz at: 1-Jul-2004 20:53

Gabriele Santilli napsal(a):
>Mine is surely slower because it isn't using the nice trick you >are using. :-) >
You have got my permission to use my implementation if you like (there is one little bug I have to correct). The corrected version should be: cfunc: func [ {make a closure} [catch] spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] {The body block of the closure} /local spc locals ] [ body: copy/deep body spc: make block! 1 + length? spec insert/only spc [throw] locals: make block! length? spec parse spec [ any [ set item any-word! ( insert tail locals to word! :item insert tail spc to get-word! :item insert/only tail spc [any-type!] ) | skip ] ] throw-on-error [ build-func spec 'context [ do func only spc only body insert bind locals context ] ] ]
>#do [document { >GET-ALL takes a block of words (only WORD!s) and returns a block >with the respective values. For example: > a: 1 > b: 2 > get-all [a b] ; == [1 2] >The difference with REDUCE is that GET-ALL does not evaluate (just >uses GET/ANY). >}] >
BTW, I always thought, that reduce [:a] should be interpreted in such a way, that we could obtain a block containing *any* type value including unset! and error! type.
>#do [document { >CLOSURE creates functions with a dynamic context. It can be used just >like FUNC, except that it creates a new context at each invocation >of the function. >}] > >closure: > func [ > "Defines a closure with given spec and body." [catch] > spec [block!] "Help string (opt) followed by arg words (and opt type and string)" > body [block!] "The body block of the closure" > > /local word words > ] [ > words: make block! 2 + length? spec > parse spec [ > any [ > set word [word! | refinement!] (insert tail words to word! word) > | skip > ] > ] > throw-on-error [ > make function! spec reduce [ > 'localize words 'copy/deep body > ] > ] > ] > >Regards, > Gabriele. >
I see two exceptions above - 'localize and 'copy cannot be locals of the function, i.e. they aren't allowed to occur in Spec. You would have to use some trick or the BUILD-FUNC function to cure this. -L