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

[REBOL] Re: variable scopes and recursive func

From: mokkel:gmx at: 12-Apr-2005 23:33

Hi Bernie, I'm not even sure whether the binding and context stuff is so incomprehensible. I somehow just have the feeling that its hard because: 1) it's not treated properly and explained well enough from RT side (most probably not to confuse beginners) 2) the bindings are not very visible, one has to have quite some understanding of the Rebol evaluation model and when it binds what, in order to get it 1) could be resolved to a certain extend by more tutorials, on the other side I think Rebols way of being makes the dynamic binding necessary. I don't think it's just to put some more power to the people. E.g. that's why I was asking/thinking that 'repeat wouldn't be possible without the dynamic binding. If it would be a build in keyword the interpreter could use special semantics for it and the binding of the repeat-word could be hidden better. But as it's just another function and could be equally done yourself one has to have the possibility to bind a word like repeat-word to the repeat-block and thus change it. An interesting question is why for simplicity reasons some things aren't used by default. E.g. always copy the repeat-block before use. Always use closures for the functions. This way for a normal person or newcomer some unexpected effects could be removed. This might a bit contradict the Rebol philosophy, but as Carl once told in one of the blocks, the default functions look like this so it's easier for people to lern Rebol as it has a certain functional style which people know. I'm also not so sure whether it is that easy to just put the bindology to the advanced Rebol section, as it happens every now and then that it also occurs in simple problems as well. 2) I don't know how the visibility could be improved. Most probably it's just like that. :-) E.g. I was a few days ago checking out once again Ladislavs closure function 'cfunc, because I forgot a little how it works and was for some time puzzled by the last line before the return: result: default [make function! spec result] 'error [throw error] --> change second :result [do make function!] There is this funny thing that when result: .... is evaluated one has already a function like result: func [x] [do make function! [some stuff...] So what does the last line really do. Just exchanges the three words 'do 'make 'function! again. Now I know that it's just to enable one to use these words as parameters to the function one wants to define, as the exchanged words are not anymore bound to the result-function, but to the constructing function(This is demonstrated there in an example in the cfunc.r file). What I wanna say is that the binding fun isn't visible exept one knows how something is going to be evaluated and bound to what when. Just to illustrate this funny thing. f: func [a b c] [print [a b c]] a: 5 b: 6 change second second :f [a b] f 1 2 3 output-> 5 6 3 So I would like to know what reasons speak against making some of these things by default behave more like other lexically scoped languages. (as said above always use closures, copy/deep blocks when they get modified) If the reason is just speed, there could be two versions, one for the average person which doesn't yet have the full glue or simply doesn't care and one which might be faster but one has to know the inner workings. Ok was a bit long mail. Sorry for the readers. :-) Michael On Tue, 12 Apr 2005 13:38:01 -0400, Bernie Schneider <[berniegs--prodigy--net]> wrote: