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

Web site update

 [1/9] from: lmecir::mbox::vol::cz at: 1-Jul-2004 15:43


My Rebol Web site http://www.fm.vslib.cz/~ladislav/rebol/ received an update (more to come soon). Innovations: 1. LFUNC http://www.fm.vslib.cz/~ladislav/rebol/lfunc.r now automatically defines static variables and can turn on simple error handling. Have a look to find out "what is cooking" 2. A BUILD-FUNC dialect added and used to innovate the CFUNC closure creating function. Improvements: the CFUNC implementation using BUILD-FUNC is now 40% simpler and 20% faster (shameless plug :-). BTW, I heard some rumours that there are other implementations of closures in Rebol. Could the respective authors compare their algorithms with this one? Any suggestions/improvements welcome. -Ladislav

 [2/9] 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/

 [3/9] 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
<<quoted lines omitted: 5>>
>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
<<quoted lines omitted: 23>>
>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

 [4/9] from: g:santilli:tiscalinet:it at: 2-Jul-2004 12:22


Hi Ladislav, On Thursday, July 1, 2004, 8:53:54 PM, you wrote: LM> You have got my permission to use my implementation if you like (there LM> is one little bug I have to correct). The corrected version should be: I'm still using LOCALIZE in a couple places, anyway I'll probably do as soon as I'll need to use a closure in a time-critical environment. :) LM> I see two exceptions above - 'localize and 'copy cannot be locals of the LM> function, i.e. they aren't allowed to occur in Spec. You would have to LM> use some trick or the BUILD-FUNC function to cure this. Yep, I just wanted to keep it simple, however I agree this is the kind of things that can lead to difficult to find bugs. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [5/9] from: lmecir:mbox:vol:cz at: 2-Jul-2004 15:27


Gabriele Santilli napsal(a):
>Yep, I just wanted to keep it simple, however I agree this is the >kind of things that can lead to difficult to find bugs. > >Regards, > Gabriele. >
Another "subtlety" is the fact, that your Localize doesn't use the [throw] attribute. -L

 [6/9] from: rotenca:telvia:it at: 2-Jul-2004 19:12


Hi Lad, smart method to pass arguments! Follow my cfunc which uses a variation.. My tests with a simple function: [[catch] "test" 'a b] [a + b] Creation 0:00:00.235 RT 0:00:01.093 romano 0:00:02.704 ladislav 0:00:00.671 gabriele Execution 0:00:00.016 RT 0:00:00.219 romano 0:00:00.328 ladislav 0:00:00.641 gabriele cfunc: func [ "Make a closure" [catch] spec [block!] body [block!] /local spc item ] [ body: reduce [1 2 3 spc: copy [[throw]] body] parse spec [ any [ to any-word! set item skip ( insert tail body to word! :item insert/only insert tail spc to get-word! :item copy [any-type!] ) ] ] throw-on-error [body: make function! spec body] change second :body [do make function!] :body ] --- Ciao Romano

 [7/9] from: lmecir:mbox:vol:cz at: 3-Jul-2004 8:16


Romano Paolo Tenca napsal(a):
>Follow my cfunc which uses a variation.. >
Yes, Romano. All my Func variants should use Make function! instead of Func to be faster. The BUILD-FUNC approach is designed to be more readable and useful in complicated cases. -L

 [8/9] from: lmecir:mbox:vol:cz at: 4-Jul-2004 13:49


Hi all, another announcement. See esp. the matrix/vector manipulation functions in http://www.fm.vslib.cz/~ladislav/rebol/matrix.r Do you think, that the "Global" Matrix object is OK, or would you prefer to use another namespace strategy? -L

 [9/9] from: greggirwin:mindspring at: 4-Jul-2004 9:41


Hi Ladislav, Thanks for posting that! LM> Do you think, that the "Global" Matrix object is OK, or would you prefer LM> to use another namespace strategy? Maybe ctx-matrix? This is always a tough call; probably not too critical in this case until a number of people start using it and have better real-world suggestions. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted