[REBOL] Re: local vars in functions

2002-05-02 Thread Ladislav Mecir
Hi all, I updated the http://www.rebolforces.com/~ladislav/contexts.html as well as contexts.r at the same location to reflect the differences found by Romano. Thanks again, Romano. Cheers L -- To unsubscribe from this list, please send an email to [EMAIL PROTECTED] with unsubscribe in

[REBOL] Re: local vars in functions

2002-05-01 Thread Ladislav Mecir
Hi Romano, nice code samples. I can say that you revealed some bugs in the Rebol interpreter behaviour as well as in my simulator. To obtain accurate results I would have to modify my simulator as follows: blank-object: function [ {make a blank object} set-words [block!]

[REBOL] Re: local vars in functions

2002-05-01 Thread Romano Paolo Tenca
Hi Ladislav, blank-object: function [ {make a blank object} set-words [block!] ] [object] [ set-words: compose [return self (set-words)] object: do does [ make object! set-words ] set/any in object 'self ()

[REBOL] Re: local vars in functions

2002-05-01 Thread Romano Paolo Tenca
Hi Ladislav, looking at your sim-make-object!: function [ {MAKE OBJECT! simulation} [throw] spec [block!] ] [set-words object sw] [ ; find all set-words in SPEC set-words: copy [] parse spec [ any [ copy sw

[REBOL] Re: local vars in functions

2002-05-01 Thread Ladislav Mecir
Hi Romano, you got me again! My models are unable to demonstrate the behaviour your code relies on: Romano ... not so readable, i must admit (and 'object could be replaced by 'set-words to make it more unreadable): blank-object: func [ {make a blank object from a block of set-words}

[REBOL] Re: local vars in functions

2002-05-01 Thread Anton
Ladislav, I now understand your point, thanks. :) Anton. Hi Anton, a little discussion may be useful sometimes: Cheers L -- To unsubscribe from this list, please send an email to [EMAIL PROTECTED] with unsubscribe in the subject, without the quotes.

[REBOL] Re: local vars in functions

2002-05-01 Thread Romano Paolo Tenca
Hi Ladislav, cunset in blk: context compose [exit (blk)] 'self blk ] /Romano :-o I would have guessed, that the only way how to do that would be: blank-object: func [ {make a blank object} blk [block!] ] [ unset in blk: context compose [return self (blk)] 'self

[REBOL] Re: local vars in functions

2002-05-01 Thread Ladislav Mecir
Hi Romano, Romano Hi Ladislav, looking at your sim-make-object!: function [ {MAKE OBJECT! simulation} [throw] spec [block!] ] [set-words object sw] [ ; find all set-words in SPEC set-words: copy [] parse spec [ any [

[REBOL] Re: local vars in functions

2002-05-01 Thread Romano Paolo Tenca
Hi Ladislav, No, I think, that my code works. (Test it, please, and let me know if anything doesn't work as it should). ... Why do you suggest this form? (I never wrote code looking like that - loop 1 or catch are unusual for me in this case) For test, try the code at the end. The new

[REBOL] Re: local vars in functions

2002-05-01 Thread Ladislav Mecir
Hi Romano, thank you, Romano Hi Ladislav, cunset in blk: context compose [exit (blk)] 'self blk ] /Romano :-o I would have guessed, that the only way how to do that would be: blank-object: func [ {make a blank object} blk [block!] ] [ unset in blk: context compose

[REBOL] Re: local vars in functions

2002-04-30 Thread Ladislav Mecir
Hi Anton, a little discussion may be useful sometimes: Anton Ladislav, I disagree. I don't think this is an adequate proof. (You didn't observe the scan happening, so it's a theory, not an observation.) /Anton You are right. It is a theory supported by observation. In

[REBOL] Re: local vars in functions

2002-04-30 Thread Romano Paolo Tenca
- From: Anton [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, April 30, 2002 7:12 PM Subject: [REBOL] Re: local vars in functions Ladislav, I disagree. I don't think this is an adequate proof. (You didn't observe the scan happening, so it's a theory, not an observation.) In my

[REBOL] Re: local vars in functions

2002-04-30 Thread Romano Paolo Tenca
Hi, Rethinking at my previous message, i must change one thing. At the start of the block context, the first (set)word is a strange word which i don't understand well. Could it be a bug? This is OK: foo: 0 foo2: 1 make object! [get 'foo2 foo: 2 foo2: 3] ** Script Error: foo2 has no value **

[REBOL] Re: local vars in functions

2002-04-30 Thread Romano Paolo Tenca
Hi, because my example in the first message used the first strange-buggy word of context, it was wrong, a correct version could be: a: b: 1 make object! [print value? 'b a: b: ] false which confirms that 'b is local and unset. --- Ciao Romano -- To unsubscribe from this list, please

[REBOL] Re: local vars in functions

2002-04-29 Thread Ladislav Mecir
Hi, I don't think, that the difference between CONTEXT and FUNC is as clear as Holger states. First of all, I think, that it is a matter of preferences (which may differ). To demonstrate, that the difference is really small, let's have a look at the following code sample: blk: [change at

[REBOL] Re: local vars in functions

2002-04-25 Thread Ladislav Mecir
Hi, just a note: you would have to define print func as global too for your code to work (that is why this isn't a good alternative). I once suggested another possibility: what if every set-word automatically declared the word as local, while other word would be local by default (which is usual

[REBOL] Re: local vars in functions

2002-04-25 Thread rebol665
Hi Ladislav, 1. I am amazed to see such a long post from you (just kidding). 2. I am testing my new foxmail email reader. Patrick Hi, just a note: you would have to define print func as global too for your code to work (that is why this isn't a good alternative). I once suggested another

[REBOL] Re: local vars in functions

2002-04-25 Thread Ladislav Mecir
Hi, Holger It is the result of REBOL being an interpreter, not a compiler. A compiler examines the complete body of a function before generating code, so the variable declaration can be anywhere. For an interpreter there are only two options: 1. Make the context of a function static, i.e.

[REBOL] Re: local vars in functions

2002-04-24 Thread Anton
Interesting idea Rishi, but I don't really like it. I am sure I would go mad trying to distinguish single or double colons everywhere. I think it would replace one type of hard-to-detect bug with another. (ie. accidentally writing only one colon.) The way rebol is at the moment is explicit and

[REBOL] Re: local vars in functions

2002-04-24 Thread Carl Read
On 24-Apr-02, Rishi Oswal wrote: Using the :: shortcut in a global context would be the same as using a :. The disadvantage I see is that it adds another thing to the language.. But consider that now we could stop using the /local keyword, reduce bugs, and use it consistently everywhere,

[REBOL] Re: local vars in functions

2002-04-24 Thread Ladislav Mecir
Hi Rishi, Rishi One part of REBOL that can feel odd is when i have to define local variables of a function in the first block of the function. I find it a bit annoying to have to add new variables to the list for every little local variable I use. In addition, I feel it clutters up the first

[REBOL] Re: local vars in functions

2002-04-24 Thread Joel Neely
Hi, Rishi, My uninformed $0.02... (Note that I try to make an alternative suggestion at the end of my discussion. I'd be interested in feedback on that idea!) The main root problem I have with your suggestion is that it seems to make an assumption about REBOL that I do not believe to be true

[REBOL] Re: local vars in functions

2002-04-24 Thread Romano Paolo Tenca
myfunc: func [][ localvar:: $25 myinnerfunc: func [][ innerlocal:: $10 print localvar ; prints $25 ] print innerlocal; error! ] print localvar ; error! using the :: for local var will make it more convienient to create local vars (which i use all the time over global

[REBOL] Re: local vars in functions

2002-04-24 Thread Mat Bettinson
Hello Gregg, GI UNFREEZE context GI extend context GI FREEZE context Actually it would have felt a bit more intuitive for me to actually specify variables that were global, and not mention variables that are local specifically. If only because the way I code that would

[REBOL] Re: local vars in functions

2002-04-24 Thread Rishi Oswal
--- Carl Read wrote: I like the idea and the syntax, but what happens with the likes of this... a: 10 a:: 20 a: 30 Does that produce an 'a in both the global and local context? And if so, does the third expression above change the local or global value, or both?

[REBOL] Re: local vars in functions

2002-04-24 Thread Rishi Oswal
here is another possible brainstorming idea for int/adv users without changing things for beginners. REBOL [] globvar1: $1000 globvar2: $ myfunc: func [/global globvar1] [ localvar: $25 print globvar1 print globvar2 ; error myinnerfunc: func [/global

[REBOL] Re: local vars in functions

2002-04-24 Thread Holger Kruse
On Tue, Apr 23, 2002 at 08:08:15PM -0700, Rishi Oswal wrote: One part of REBOL that can feel odd is when i have to define local variables of a function in the first block of the function. I find it a bit annoying to have to add new variables to the list for every little local variable I use.

[REBOL] Re: local vars in functions

2002-04-24 Thread Gregg Irwin
Hi Rishi, *Syntactically backwards compatible with rebol I'm relatively new to REBOL (8 months or so now) but I've learned that Carl and Holger think about these kinds of things very carefully. As Carl has said, lexical space is very tight in REBOL because of the high number of native

[REBOL] Re: local vars in functions

2002-04-23 Thread Tim Johnson
* Rishi Oswal [EMAIL PROTECTED] [020423 19:18]: One part of REBOL that can feel odd is when i have to define local variables of a function in the first block of the function. I find it a bit annoying to have to add new variables to the list for every little local variable I use. In addition,

[REBOL] Re: local vars in functions

2002-04-23 Thread Christian Morency
Hi, Have you looked at function ? ie myfunc: function [arg1 arg2] [local1 local2] [source] or myfunc: function [ arg1 arg2 ] [ local1 local2 ] [ source ] it pretty much what you want, plus if you use the following -Original Message- From: [EMAIL

[REBOL] Re: local vars in functions

2002-04-23 Thread Charles
One part of REBOL that can feel odd is when i have to define local variables of a function in the first block of the function. I find it a bit annoying to have to add new variables to the list for every little local variable I use. In addition, I feel it clutters up the first block and

[REBOL] Re: local vars in functions

2002-04-23 Thread Rishi Oswal
I think the reason for making words global by default is simply because it is the natural thing for a newbie to the language or beginner to use. I think this was the right decision.. fits with the rebol philosophy.. The :: solution, i feel, has the benefit of not getting in the way of beginners