World: r3wp
[Core] Discuss core issues
older newer | first last |
Piotr 23-Jun-2005 [1382x2] | oops |
then how construct local words? | |
Ladislav 23-Jun-2005 [1384x2] | bind to-word "no-b" 'no-a |
(if 'no-a is local) | |
Piotr 23-Jun-2005 [1386] | so, fifth line (of example above) looks like: foreach x [a b c] [ d: to-word join "no-" x bind d 'no-a set d "test-2" ] but his still does not work (for me) |
Ladislav 23-Jun-2005 [1387] | ctx: context [ no-a: no-b: no-c: none set 'test does [ foreach x [no-a no-b no-c] [set x "test-1"] foreach x [a b c] [ d: bind to-word join "no-" x 'no-a set d "test-2" ] foreach x [a b c] [print [join "no-" x get (to-word join "no-" x)]] foreach x [no-a no-b no-c] [print [x get x]] ] ] test probe no-a probe ctx/no-a |
Volker 23-Jun-2005 [1388x2] | i guess bind returns a new word here, but does not change the old? so it must be d: bind d 'no-a |
>> c: context[a: 123] >> a: 234 == 234 >> b: 'a == a >> get b == 234 >> bind b c == a >> get b == 234 >> b: bind b c == a >> get b == 123 | |
Piotr 23-Jun-2005 [1390x2] | thanks; |
maybe rebol need something like to-local-word and to-global-word? | |
Volker 23-Jun-2005 [1392x2] | thats to-word and 'bind. your problem was that bind does not change its argument, but returns a new different bound word. which may confuse because with a block, it changes that block. |
(to-local-word would not work, as rebol does not know what "local" means) | |
Piotr 23-Jun-2005 [1394] | i think that bind and varialbles "bounded to local or global context" are black magick for new rebolers; hard to understand and even harder to explain... |
Ladislav 23-Jun-2005 [1395] | what is easy to explain (in the doc at many places) is the warning, that you shouldn't use strings when you intend to use words, because strings don't "contain" any context information |
BrianH 23-Jun-2005 [1396] | Piotr, REBOL doesn't really have local contexts like a language with nested scopes does. REBOL fakes nested scopes with iterations of applied binding. The "local" context of a word is really just the context associated with that specific word object. The "global" context is nothing special in that respect, and "outer" contexts are just a side effect of the binding rather than a real physical structure like it is in Smalltalk. There is no lookup chain - it's just [word thing]->[context (keyed value collection) thing]->[value thing]. |
Romano 23-Jun-2005 [1397] | Ladislav: "what is "the shortest" reverse of: y: to integer! x: #{80000000}" debase/base to-hex y 16 is the fastest i know, i do not know about the shortest |
BrianH 23-Jun-2005 [1398] | Binding is just associating a [word thing] with a [context (keyed value collection) thing], and that just fails if there is no existing key in the context of the symbol associated with the word. The only context that actually expands to include new words is system/words, the closest thing REBOL has to a "global" context, more of a default really, but not quite. |
Gabriele 23-Jun-2005 [1399] | Piotr: you may be interested into this thread: http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlKVVC |
Pekr 25-Jun-2005 [1400x6] | >> a: [1 1 2 2 3 3] == [1 1 2 2 3 3] >> b: [x y] == [x y] >> foreach :b a [print x] 1 2 3 >> foreach :b a [print b/1] x x x >> foreach :b a [print get b/1] ** Script Error: x has no value ** Where: halt-view ** Near: print get b/1 |
Is it possible to get b/1 evaluated? I am not sure it is because of non-aggresive word evaluation, but maybe question for you 'bind gurus? :-) | |
foreach :b a [print bind b 'x] ? | |
and for gurus - what happens here? :-) foreach :b a [print bind b first :b] 3 3 3 3 3 3 | |
I want to use 'X, without using 'x :-), but somehow foreach :b a [print get b/1]] does not return result I expected (1 2 3), it returns (3 3 3) | |
sorry, my bug - I needed to restart concosole, "get b/1" in context of 'foreach is unknown ... | |
Volker 25-Jun-2005 [1406] | foreach makes new context, not touching the old vars. kind of locals. |
Pekr 25-Jun-2005 [1407] | I know, I just somehow wished to abstractly use b/1, to get x in a |
Volker 25-Jun-2005 [1408] | >> b: [x y] == [x y] >> foreach :b [1 2 3 4 5 6][bind b 'x print get b/1] |
Pekr 25-Jun-2005 [1409] | yes, I know, but you used 'x ... that is the tricky question - we wanted to create it dynamically, so we wanted to use bind b b/1 (we thought that instead of b/1 interpreter somehow will understand cleverly, that we mean x in context of foreach function :-) |
Volker 25-Jun-2005 [1410x2] | >> foreach :b [1 2 3 4 5 6] compose/only [b: (b) print get b/1] |
its ugly. problem is, the context exists only inside the foreach-body. here i put the same words (b) in the body and those they get rebound. but foreach copies the body before first run, so i have to assign b again. | |
Pekr 25-Jun-2005 [1412] | ha, that was easy ;-) ...we tried to struggle in context level and forgot about ability of dynamically building code for interpreter itself :-) |
Volker 25-Jun-2005 [1413] | but i guess once you start having ideas about it you will find something nicer ;) - yes, like building the whole code dynamic maybe. |
Pekr 25-Jun-2005 [1414x3] | but you redefined original 'b block in context of foreach body .... |
>> foreach :b [1 2 3 4 5 6] compose/only [b: [x y z] print get b/1] 1 3 5 >> b == [x y z] | |
so 'b in context of 'foreach body is global ... so it redefines original 'b, but it is ok for our example, thanks ... | |
Volker 25-Jun-2005 [1417x3] | You could use another var-name, i just reused 'b |
foreach :b [1 2 3 4 5 6] compose/only [words: (b) print get words/1] and done ;) | |
but its not necceary here, as it keeps the same word-names, only with different bindings. so if you run the code again, the names are the same, the binding shall change anyway. | |
Pekr 25-Jun-2005 [1420] | :-) |
Volker 25-Jun-2005 [1421x6] | Oops, i completely forgot about firskip ! Which you may use instead! |
>> b: [1 2 3 4 5 6] == [1 2 3 4 5 6] >> forskip b 2[print [b/1 b/2]] 1 2 3 4 5 6 | |
if you really need words, these would be global and easier to reach: | |
>> words: [x y] >> forskip b length? words[set words b print[x y]] 1 2 3 4 5 6 | |
(remember view begins with 1.3, because some little things on forskip have changed ;) | |
(but the foreach may be a little bit faster) | |
Graham 25-Jun-2005 [1427] | Hmm. I just noticed that rebcmd comes up saying "Component: Graphics 1.3.0 blah ... " ... what is Graphics doing in core ? |
PeterWood 25-Jun-2005 [1428] | Perhaps to allow image manipulation, for example in a CGI script? |
Gabriele 26-Jun-2005 [1429] | exactly (afaik). |
Maarten 26-Jun-2005 [1430] | yep, that is the 'face part without VID or X libs needed' |
DideC 27-Jun-2005 [1431] | Use the 'draw function to handle draw blocks. |
older newer | first last |