World: r3wp
[Core] Discuss core issues
older newer | first last |
Geomol 23-Feb-2005 [453] | Does REBOL miss a way to go up one level of blocks within blocks? Example: >> blk: [[a b c] [d e f]] == [[a b c] [d e f]] >> p: first blk == [a b c] Now I would like to have p go up one level, so I can continue to the next block (the [d e f] block) within blk. Using blk to do it is not a solution, because we could have blocks within blocks within blocks ... to any level. What about a parent function like: >> p: parent p |
DideC 23-Feb-2005 [454] | It require bidirectinnal pointer: - parent -> child (we have that : parent/child-index) - child -> parent (we DON'T have that !) You have to hold the reference yourself. |
Volker 23-Feb-2005 [455] | you can put the same block in two others, which one is parent? |
Sunanda 23-Feb-2005 [456] | Not really possible without an extra data structure. Why not simply make the parent the 1st entry in the block? >> blk: copy [] == [] >> append/only blk blk == [[...]] >> append blk "a" == [[...] "a"] (One drawback is that this sort of recursive structure cannoy easily be molded and later loaded_ >> |
DideC 23-Feb-2005 [457] | Use a block and Push reference to the parent when you go into the child. Then Pop the reference when you want to go up one level. |
Geomol 23-Feb-2005 [458] | Volker is right! Which one is the parent? Ergo we can't have a parent function. And then again, we have to use a trick, where we store the block at any level. (You other guys are right too, and I think the actual design is the best way, I just have to keep in mind, why it is like this.) :-) |
Chris 23-Feb-2005 [459] | DideC, do you have an example? I've seen the terms 'push and 'pop before, but have not seen a comprehensive example of it... |
DideC 23-Feb-2005 [460] | There was a discussion about stack implementation the 27-jan in this group. Go up, there is the code from Robert and others |
Chris 23-Feb-2005 [461] | Thanks, missed that... |
Geomol 23-Feb-2005 [462x3] | I find this a bit strange and problematic: >> blk: [/] == [/] >> type? blk/1 == word! >> parse blk [/] == false How do I parse a slash within a block? |
Answer: parse [/] [set w word!] Sorry to bother you. ;-) | |
Well, I'm not 100% satisfied. Look at these: >> parse [a] ['a] == true >> parse [/] ['/] ** Syntax Error: Invalid word-lit -- ' ** Near: (line 1) parse [/] ['/] Shouldn't '/ be a valid lit-word? | |
Pekr 23-Feb-2005 [465] | imo Rebol is so free form, that you imo can find lot of such inconsistencies here ... |
Chris 23-Feb-2005 [466] | >> slash: to-lit-word "/" == '/ >> parse [/] [slash] == true |
Geomol 23-Feb-2005 [467] | Thank you very much! :-) |
Anton 23-Feb-2005 [468x2] | Careful, by default: >> slash == #"/" |
It might be used in some other code. | |
Geomol 24-Feb-2005 [470] | Yes, I called mine lit-slash. |
JaimeVargas 24-Feb-2005 [471] | ;I find this amazing. >> o: make object! [sub-o: make object! [name: 'sub-o f: func [v][2 * v]]] >> ? o O is an object of value: sub-o object! [name f] >> var: in o 'sub-o == sub-o >> ? var VAR is a word of value: sub-o >> value: get var >> ? value VALUE is an object of value: name word! sub-o f function! [v] ;What I find amazing is that you can get the content of the object SUB-O by doing GET VAR ;Some how the context where 'SUB-O is defined gets attached to VAR or SUB-O by IN O 'SUB-O ;just to check, the global context doesn't know anything about SUB-O >> ? sub-o No information on sub-o (word has no value) >> sub-o ** Script Error: sub-o has no value ** Near: sub-o |
Ammon 24-Feb-2005 [472x2] | It is because the VALUE not the word contains the CONTEXT information meaning that VAR (as you defined it) referenced the value SUB-O which happened to be a word with the context of O |
...a word WITHIN the context of the object that the WORD O refers to... | |
JaimeVargas 24-Feb-2005 [474] | It surely allows for some very neat programing tricks ;-) |
Ammon 24-Feb-2005 [475] | Yes, it does. ;-) |
Anton 24-Feb-2005 [476x3] | Each word "knows" which context it lives in. When you make a new object, the top-level set-words are BINDed to it. So each word knows its binding. |
I think Ladislav used to have a nice example where each of the words in this block could refer to different values, because they were bound to different contexts: [word word word word] | |
They all look the same, but just looking at this you cannot tell which context each word is bound to. | |
BrianW 24-Feb-2005 [479] | sounds kinda cool but scary from a code maintenance perspective. |
Anton 24-Feb-2005 [480x3] | Bah.. We use this feature all the time without thinking about it. Take a look at this: |
context [v: 12 print v] | |
(it prints "12" to the console :) Now luckily for us, 'print was not bound to the new context. It "remembers" its context is the global context. That's how we can get its value (a function) to actually do something. The set-word, v: , on the other hand was bound to the new context, so we know it won't affect anything outside. | |
Gabriele 25-Feb-2005 [483x2] | >> b: [] repeat i 5 [use [x] [x: i append b 'x]] == [x x x x x] >> reduce b == [1 2 3 4 5] >> same? b/1 b/2 == false |
you can think of a word as if it was a block that could only keep one element. so each word keeps its value, in a similar way as each block keeps its values. (this is not 100% correct, but maybe it helps understanding) | |
DideC 25-Feb-2005 [485x4] | Ah yes, this one is tricky ! |
but I suppose the same line must be done before the block reducing, as "same? 1 2" can't answer true. | |
...the same? line... | |
Ups, sorry. Block is reduced but not reassigned to B | |
Robert 25-Feb-2005 [489x2] | I always wanted a way to dump all contexts a word is defined in: like "dump-context myword" and get a list of named and unnamed contexts. Anamonitor can do this. |
>> split-path %/c/test/bla.txt == [%/c/test/ %bla.txt] >> split-path %/c/test/bla/ == [%/c/test/ %bla/] Isn't this inconsitent? I think the last should give: == [%/c/test/bla/ none] | |
Romano 25-Feb-2005 [491x3] | yes Robert anamonitor can do it (i do not remember if the last released version does it, but my version does it :-) |
and yes Robert, i do not like split-path behaviour in many cases (see RAMBO discussions about this), but i do not think that your request is good, from my pov %a/b/ should give %a/ %b/ = the dir b inside the dir a or %a/b/ %./ = the current dir inside the dir %a/b/ this is inconsistent with: >> split-path %./ ; == [%./ none] but i think the last behavior should change in this %./ %./ | |
none should never appear in a splith-path result | |
Anton 26-Feb-2005 [494] | Well, maybe split-path is not so useful sometimes, but at least it says what it is doing :) I think what we want most of the time is the dir-part and the file-part of a path (actually these are functions I use). I think they are more useful in general. The problem is in coming up with a good name to describe this behaviour..... maybe: to-dir-file-parts %my/path ;== [%my/ %path] ? |
Robert 27-Feb-2005 [495] | As you said: file-part, dir-part |
JaimeVargas 1-Mar-2005 [496x4] | Does rebol has some form of inheritance? Well not according to the docs. But when intializing within context there seems to be an initialization chain that look like a bit like inheritance to me. |
o: context [ a: 0 b: none o1: context [ a: 1 c: 3 set 'b 2 o2: context [ set 'b 4 set 'c 5 set 'd 6 ] ] ] | |
O is an object of value: a integer! 0 b integer! 4 o1 object! [a c o2] >> ? o/o1 O/O1 is an object of value: a integer! 1 c integer! 5 o2 object! [] >> ? o/o1/o2 O/O1/O2 is an object of value: >> d == 6 | |
The slots got the last value set by the child context of each parent. | |
Ammon 2-Mar-2005 [500] | Uhm... But that isn't inheritance, it is simply context. |
Anton 2-Mar-2005 [501x2] | o: context [ |
A new object begins to be created. | |
older newer | first last |