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

[REBOL] Re: Web site update

From: g:santilli:tiscalinet:it at: 1-Jul-2004 16:42

Hi Ladislav, On Thursday, July 1, 2004, 3:43:16 PM, you wrote: LM> 2. A BUILD-FUNC dialect added and used to innovate the CFUNC closure LM> creating function. Improvements: the CFUNC implementation using LM> BUILD-FUNC is now 40% simpler and 20% faster (shameless plug :-). BTW, I LM> heard some rumours that there are other implementations of closures in LM> Rebol. Could the respective authors compare their algorithms with this one? Mine is surely slower because it isn't using the nice trick you are using. :-) #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). }] get-all: func [ "Get (without evaluating) all words in a block" [catch] words [block!] ] [ words: copy words if not parse words [any [words: word! (change/only words get/any words/1)] end] [ invalid-argument pick words 1 ] head words ] #do [document { LOCALIZE (which probably needs a new name) is just like USE, except that keeps the values of the words it makes local. Example: a: 1 b: 2 localize [a b] [ ; here a = 1 and b = 2 b: 3 ] ; b is still 2 here }] localize: func [ "Defines words local to a block, but keeps their value" [catch] words [block!] body [block!] ] [ use words reduce [ 'set copy words throw-on-error [get-all words] 'do body ] ] #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. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/