[REBOL] 'dynamic append'
Dear List, Am at a loss here, i have failed trying to get a script with an "unknown" number of blocks working. I need to create "blocks on the fly", example: append/only test rejoin ["block1_"A ": copy []"] do last test will allow me to make blocks for any value of "A" but: at some point i would like to append stuff to one of these blocks, at that stage i know A (example: A: 12), and i need to: append block1_12 "some data" Question: how can i do append (join "block1_"A) "some data" perhaps someone can help me with this greetings, Hendrik-Jan Bosch
[REBOL] Bug in 'use? Re:(2)
Hi Eric, you wrote: I think it's needlessly complex to say that the g function "has access to f-arg". That is complex? It's much simpler to say that the word 'f-arg is bound to the context of the function F, That's "much simpler to say"? ;-). Perhaps. It does not say, however, if 'g has access to the f-arg that is defined in the context of the 'f function. and that the function G has no privileged access to that binding of 'f-arg by being within some kind of hierarchy. But the embedded function g (a function that is defined in the context of function f) *does* have privileged access to words local to the context of function f. That happens to be an empirical fact. The questionable *simplicity* of saying that function 'g "has no privileged access to that binding" does not help, since your statement is incorrect. A simple incorrect statement is not better than a correct one. Observe: x: "This is global x." f: func [x] [ [ g: func [] [ [print x [ ] [] f "this is f's argument x" h: func [] [ print x ] h This is global x. g this is f's argument x Why does the function associated with 'g (I'll call it the 'g function) report f's argument, and not the global 'x, as 'h does? It's because the 'g function, which is defined in f's context, inherits f's context table. Therefore the 'x it prints is the 'x bound in f's context, not the global context. The term "f's context table" is simply a shortcut for saying" "all word/value pairs defined in the context of the 'f function". Inheritance means that - without any programmatic efforts - REBOL automatically exposes f's context table to the g function, because the g function is embedded in f's context. Even though 'x is defined globally, the 'x binding effective for 'g is x's binding in 'f, because 'g is defined in 'f. (Mind you, I am not talking about the set-word g: being defined in 'f, I am talking about the function itself, the value 'g is associated with, being defined in 'f. Nor am I talking about 'f. I'm using 'f as a short way of saying "the function associated with f".) This inheritance is hierarchical. Observe: x: "This is global x." y: "This is global y." z: "This is global z." f: func [y z] [ [ g: func [z] [ [print ["g's x" x] [print ["g's y" y] [print ["g's z" z] [ ] [ print ["f's x" x] [ print ["f's y" y] [ print ["f's z" z] [ g "z argument passed to g." [] f "The y argument passed to f." "The z argument passed to f." f's x This is global x. f's y The y argument passed to f. f's z The z argument passed to f. g's x This is global x. g's y The y argument passed to f. g's z z argument passed to g. Both 'f and 'g inherited the global context table, see the value reported for 'x. The 'f function uses the values of its local context table for the words 'y and 'z. The 'g function inherits the global context table for 'x, inherits f's private context table for 'y and uses its own context table for 'z. I think this inheritance behavior is expressed fairly well with the word "hierarchical inheritance". There is a hierarchy of context tables. REBOL constructs this hierarchy top-to-bottom, from the higher-level function down to the lower-level function defined in the higher-level function's context. REBOL consults with context tables in the hierarchy bottom-up when it resolves words and looks up what the value they are bound to, beginning with the context table for the lower-level function, and, if it can't find the word's definition there, it searches in the next-higher context table, and so on, until it arrives at the global context table. (The binding of 'f-arg of course took place even before the function G was created.) Of course. Who was disputing that? I'm describing how g gets to access the 'f' functions f-arg, not when f-arg is bound to the f' function. Two different things. Here's proof, I think: f: func[x y][x + y] g: func[x y][x + y] f 1 2 == 3 g 5 6 == 11 b: copy second :f == [x + y] c: copy second :g == [x + y] append clear second :f c == [x + y] append clear second :g b == [x + y] f 1 2 == 11 g 5 6 == 3 f 10 11 == 11 g 5 6 == 21 Here I've rebuilt the code for F and G, and now their bodies contain words 'x and 'y bound within each other's contexts. I think it's simplest to say that those words "know" where they are bound. When you call F, it sets the values of all instances of 'x and 'y bound to its context, but in this case all those instances are now in the body of G, not within F's own body. F doesn't see the word 'x within its body, and look up the value of 'x in some table, it just uses the value that results when 'x is evaluated. Nice. I was talking about something else, something your proof does not address. I was talking about rules that guide REBOL when it defines in which context a word is bound in ambiguous situations. What's ambiguous about the situation? Given: x: "Global x."
[REBOL] Rebol Dictionary as Clipbook Library Re:
From: [EMAIL PROTECTED] For those that aren't familiar with "Notetab" you should go visit www.notetab.com. No I wasn't familiar with it. It is an absolutely brilliant program. Thanks for the reference! You can edit your rebol scripts in "Notetab" and view the dictionary file without loading your browser. Great! Brett.
[REBOL] 'dynamic append' Re:
Hi Hendrik-Jan, You're almost there - here is a simple solution. append/only test rejoin ["block1_"A ": copy []"] do last test test: [] a: 12 append/only test rejoin ["block1_"A ": copy []"] last-block: do last test append last-block "whatever you want" so now try: block1_12 == ["whatever you want"] Brett Handley
[REBOL] Words, Bindings and Contexts. (4)
Note: The last two sections (Context Hierarchy. Pardon?; "Context hierarchy"? Aye, aye, sir!) were complicated and not very useful, but they can be skipped. What are Rebol Contexts? * Rebol Contexts are existing data, sometimes available to the user. They are used internally by Rebol for the purposes of many Core functions. Their main purpose is to serve as attribute of Rebol Words - ie. Rebol Context is a part of any Word's Binding - in different wording: every Rebol Word knows its Context. Proof: see the function Same-context? defined in part 3. Known Rebol Contexts: Available directly as: a) Global ContextRebol/Words b) Objectsthemselves c) Function Contexts not available d) Use Contexts not available e) Special Contextsnot available Properties: a) Global Context is the Default Context - Words are normally Global Context Words, if not stated otherwise. b) Objects are Local Contexts - as opposed to Global Context. They are created by Make native. The list of Words object O "contains" - ie. the list of Words that are local to O is available as First O. But look out! There is a catch - the elements of First O are equal to local O's Words, but the elements of First O are Special Context Words. To obtain a list of Words really local to O, one must do: words-local-to-o: bind first o in o 'self c) Function Contexts are Local Contexts too. They are attributes of functions and are created when the respective functions are created. Function Contexts contain: all argument Words, all refinement Words, all optional argument Words and all local Words specified by /local refinement. (you can verify it for particular examples by using Same-context? function). d) Use Contexts are Local Contexts and are created when the respective Use function is evaluated. They contain the Local Words specified by the first argument of Use. e) Special Contexts - see a note under Object Contexts, other example: a: "q" a: make block! a get first a Here First A is a Special Context Word too. The problem is, that Bind doesn't work for Special Contexts, which means, that our Same-context? function doesn't work too. Here is an improved version: special-context?: func [ {determines, if a word is a Special Context Word} word [word!] ] [ error? try [error? get/any word] ] ; this function can help us explore the Contexts, that aren't directly available same-context?: func [ {find out, if the given Words are the Words of the same Context} word1 [word!] word2 [word!] ] [ either global? word1 [ global? word2 ] [ either special-context? word2 [ special-context? word1 ] [ same? word1 bind global word1 word2 ] ] ]
[REBOL] 'dynamic append' Re:(2)
hi Brett, it works great! thanks very very much! HJ
[REBOL] Re: Bug in 'use? Re:(2)
Hello Elan, Please see comments below. On 23-Jul-00, [EMAIL PROTECTED] wrote: Hi Eric, you wrote: I think it's needlessly complex to say that the g function "has access to f-arg". That is complex? It's much simpler to say that the word 'f-arg is bound to the context of the function F, That's "much simpler to say"? ;-). Perhaps. It does not say, however, if 'g has access to the f-arg that is defined in the context of the 'f function. and that the function G has no privileged access to that binding of 'f-arg by being within some kind of hierarchy. But the embedded function g (a function that is defined in the context of function f) *does* have privileged access to words local to the context of function f. That happens to be an empirical fact. The questionable *simplicity* of saying that function 'g "has no privileged access to that binding" does not help, since your statement is incorrect. A simple incorrect statement is not better than a correct one. Observe: x: "This is global x." f: func [x] [ [ g: func [] [ [print x [ ] [] f "this is f's argument x" h: func [] [ print x ] h This is global x. g this is f's argument x Why does the function associated with 'g (I'll call it the 'g function) report f's argument, and not the global 'x, as 'h does? It's because the 'g function, which is defined in f's context, inherits f's context table. Therefore the 'x it prints is the 'x bound in f's context, not the global context. The term "f's context table" is simply a shortcut for saying" "all word/value pairs defined in the context of the 'f function". Inheritance means that - without any programmatic efforts - REBOL automatically exposes f's context table to the g function, because the g function is embedded in f's context. Even though 'x is defined globally, the 'x binding effective for 'g is x's binding in 'f, because 'g is defined in 'f. (Mind you, I am not talking about the set-word g: being defined in 'f, I am talking about the function itself, the value 'g is associated with, being defined in 'f. Nor am I talking about 'f. I'm using 'f as a short way of saying "the function associated with f".) This inheritance is hierarchical. Observe: x: "This is global x." y: "This is global y." z: "This is global z." f: func [y z] [ [ g: func [z] [ [print ["g's x" x] [print ["g's y" y] [print ["g's z" z] [ ] [ print ["f's x" x] [ print ["f's y" y] [ print ["f's z" z] [ g "z argument passed to g." [] f "The y argument passed to f." "The z argument passed to f." f's x This is global x. f's y The y argument passed to f. f's z The z argument passed to f. g's x This is global x. g's y The y argument passed to f. g's z z argument passed to g. Both 'f and 'g inherited the global context table, see the value reported for 'x. The 'f function uses the values of its local context table for the words 'y and 'z. The 'g function inherits the global context table for 'x, inherits f's private context table for 'y and uses its own context table for 'z. I think this inheritance behavior is expressed fairly well with the word "hierarchical inheritance". There is a hierarchy of context tables. REBOL constructs this hierarchy top-to-bottom, from the higher-level function down to the lower-level function defined in the higher-level function's context. REBOL consults with context tables in the hierarchy bottom-up when it resolves words and looks up what the value they are bound to, beginning with the context table for the lower-level function, and, if it can't find the word's definition there, it searches in the next-higher context table, and so on, until it arrives at the global context table. Please let me interrupt. A few days ago, I'd have said the same thing, but some experiments I've done in the last couple of days (and the thread "REBOL's scoping rules") have convinced me othervice. I agree that some sort of hierarchy exists, but maybe it just "seems to be". I'd like to go thru an example, but to do that, I must make the presumption that each lit-word in REBOL can have it's own private binding (ie. each word can be bound to a specific context). The BIND function can be used to modify a words binding. (I which I could express this better, but well, I can't :-) First the sample script: REBOL [] x: "global x" y: "global y" code-1: [print [x y]] f: func [x] [ code-2: [print [x y]] do code-1 do code-2 g1: func [y] code-1 g2: func [y] code-2 g1 "g-arg-y" g2 "g-arg-y" ] f "f-arg-x" Ok, I'll try to explain what I *belive* goes on during the loading and execution of this script. I'll be using a notation like x@global, which means: lit-word 'x bound to the global context, and x@f means 'x bound to the context of
[REBOL] context exploration
Hello, While playing with contexts, I threw together this little function to show the words that are defined in a context (and their values in that context). (something like that have been discussed before AFAIR, but a 1min. search didn't find it, sooo :-) It goes like this: show-context: func [word [word!]] [ foreach x-word next first system/words [ if value? bind x-word :word [ print [:x-word "|" get bind x-word :word] ] ] ] Attached is a script that demonstrates the use of the function with contexts created with func, use and make object! Best regards Thomas Jensen REBOL [] show-context: func [word [word!]] [ foreach x-word next first system/words [ if value? bind x-word :word [ print [:x-word "|" get bind x-word :word] ] ] ] a: "global-a" b: "global-b" c: "global-c" x: "global-x" v: "global-v" o1: make object! [ a: 1 b: 2 o2: make object! [ b: 20 c: 30 test: func [test-arg /local x] [ x: "local-x" print [a b c] print "^/-- show-context 'a --" show-context 'a print "^/-- show-context 'b --" show-context 'b print "^/-- show-context 'x --" show-context 'x ] ] ] o1/o2/test "argument to o1/o2/test" print "^/-- show-context in o1/o2 'b --" show-context in o1/o2 'b use [v w] [ v: "local-v" w: "local-w" print "^/-- show-context 'v --" show-context 'v ]
[REBOL] Re: context exploration
Hello, forgot to say, that words that have the special value unset! will not be displayed. On 24-Jul-00, [EMAIL PROTECTED] wrote: Hello, While playing with contexts, I threw together this little function to show the words that are defined in a context (and their values in that context). (something like that have been discussed before AFAIR, but a 1min. search didn't find it, sooo :-) It goes like this: show-context: func [word [word!]] [ foreach x-word next first system/words [ if value? bind x-word :word [ print [:x-word "|" get bind x-word :word] ] ] ] Attached is a script that demonstrates the use of the function with contexts created with func, use and make object! Best regards Thomas Jensen Best regards Thomas Jensen
[REBOL] Bug in 'use? Re:
Hi Elan, I think you're going to be really busy refuting Ladislav, so I'll keep my comments brief. You wrote: Observe: x: "This is global x." f: func [x] [ [ g: func [] [ [print x [ ] [] f "this is f's argument x" h: func [] [ print x ] h This is global x. g this is f's argument x Why does the function associated with 'g (I'll call it the 'g function) report f's argument, and not the global 'x, as 'h does? It's because the 'g function, which is defined in f's context, inherits f's context table. Therefore the 'x it prints is the 'x bound in f's context, not the global context. Your explanation agrees with your example, but I don't think it's quite the best one. I think the best explanation (which I'm mostly basing on what Gabriele and others have said) is: Before the function G is constructed, its body block, [print x] is already bound to the context of the function F. Of the two words in this block, 'x is defined in the "context table" of F. So when G is constructed, this block is bound to G's context, but since 'x is not redefined in that context it simply retains its binding. You could say that G inherits the binding of 'x, but I don't see any proof that G "inherits f's context table". I think your explanation about embedded functions inheriting context tables has the potential of causing major confusion. My previous example was a lousy one, but here's an example involving embedded functions that can easily occur: b: [print x + y] == [print x + y] f: func[x][g: func[y] b print x] x: 100 == 100 f 10 10 g 1 101 If you think in terms of "inheriting context tables", wouldn't you expect G to print 11? That's certainly what I would think. What happens here accords with my explanation, though. When G is constructed, in its body block 'x hasn't been bound to the context of F, and that binding doesn't change - it's still bound to the global context. This happens because the body block wasn't actually in the block that was bound to F's context - only the word 'b referring to the body block was. (Actually, the bindings in the original B are unchanged, since a copy is used to construct G.) I think this inheritance behavior is expressed fairly well with the word "hierarchical inheritance". There is a hierarchy of context tables. REBOL constructs this hierarchy top-to-bottom, from the higher-level function down to the lower-level function defined in the higher-level function's context. REBOL consults with context tables in the hierarchy bottom-up when it resolves words and looks up what the value they are bound to, beginning with the context table for the lower-level function, and, if it can't find the word's definition there, it searches in the next-higher context table, and so on, until it arrives at the global context table. When is it that "REBOL consults with context tables"? At run time? When the function is constructed? Surely it's the latter. I think a simpler explanation than hierarchical inheritance is that when a function is constructed, it simply binds all the words in its body block that are defined in its own context (that is, its own arguments and local variables), and retains the binding of all other words. If one of the words in its body block happens to be bound to the context of another function, that word will retain its binding, whether or not one function is embedded in another one. Ladislav's tools for examining binding are very interesting. I'd just like to extract and adapt the crucial part of his argument that proves that contexts are not inherited: x: y: z: 0 == 0 f: func[x z][g: func[y] [print [x y z]]] f 10 30 g 20 10 20 30 b: reduce [ [bind 'x probe second second second :g [bind 'x probe third second second :g] y z == [x x] reduce b == [0 10] This shows that the word 'x is nowhere in G's context table. The word 'y which _is_ in G's context does not allow us to access any bindings for 'x except the global one. The word 'z which is in F's context table _does_ allow us to access F's binding for 'x. Wish I'd thought of that! See you, Eric
[REBOL] context exploration Re:
I really like your function Thomas. Very good! Brett. - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 24, 2000 1:03 PM Subject: [REBOL] context exploration Hello, While playing with contexts, I threw together this little function to show the words that are defined in a context (and their values in that context). (something like that have been discussed before AFAIR, but a 1min. search didn't find it, sooo :-) It goes like this: show-context: func [word [word!]] [ foreach x-word next first system/words [ if value? bind x-word :word [ print [:x-word "|" get bind x-word :word] ] ] ] Attached is a script that demonstrates the use of the function with contexts created with func, use and make object! Best regards Thomas Jensen
[REBOL] REBOL on phones? Re:
Hello Nitish and rebol friends, you are on the way. I have experience in the mobile and wireless industry, with different kinds of platforms, sw and hw and there is no doubt about it. I'd like have some like rebol in the mobile and wireless area. I am thinking since some months ago, and I consider that is time to build the answer. Obviously, I'd like very much contact whos belive the same. Best regards Cristian G. Amayo [EMAIL PROTECTED]