r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

DideC
21-Jun-2005
[1356]
Thanks, didn't remember that
Pekr
23-Jun-2005
[1357x2]
how is find/match supposed to work on blocks? I thought following 
will work? 

find/match ["Petr Krenzelok"] "Petr"
what I have in mind is very simple kind of select, not needing to 
enter whole search key ...
Henrik
23-Jun-2005
[1359x3]
with blocks, I don't think that'll work with match, because it searches 
for the full element in a series, thus you need to search in two 
levels...
the block level and the string level
a find/deep would be very useful... recursive searching of blocks 
and objects. it could allow you to find a value in large objects 
and blocks quickly
Pekr
23-Jun-2005
[1362x2]
find/deep is long requested feature, but it was said as not being 
as trivial, as blocks can contain self-references etc ...
and what is find/only about?
Volker
23-Jun-2005
[1364x6]
with find/match you can check for abbreviations
>> find/match "Hello World" "W"    
== none
>> find/match "Hello World" "H"
== "ello World"
>> find/match ["Pekr" "Krenzelok"] "Pekr"
== ["Krenzelok"]
>> find/match ["Pekr" "Krenzelok"] "Krenzelok"
== none
/only is for this:
>> find ["Pekr" "Krenzelok" "asking"] ["Pekr" "Krenzelok"]
== ["Pekr" "Krenzelok" "asking"]
>> find/only ["Pekr" "Krenzelok" "asking"] ["Pekr" "Krenzelok"]
>> find/only [["Pekr" "Krenzelok"] "asking"] ["Pekr" "Krenzelok"]
== [["Pekr" "Krenzelok"] "asking"]
Ladislav
23-Jun-2005
[1370]
I wrote some functions of this kind, but anyway, what is "the shortest" 
reverse of:

    y: to integer! x: #{80000000}
Anton
23-Jun-2005
[1371x2]
Maybe this ?
>> reverse third make struct! [i [int]] reduce [y]
== #{80000000}
; quick testing looks good

>> foreach v [-1 0 1 1000 7777 2000000][print same? v to-integer 
reverse third make struct! [i [int]] reduce [v]]
true
true
true
true
true
true
Gabriele
23-Jun-2005
[1373x3]
hmm, a "short" way could be:
>> to binary! reduce [y / 16777216 y / 65536 y / 256 y]
== #{80000000}
btw, is this on rambo? i really think that to binary! should work 
with integers.
JaimeVargas
23-Jun-2005
[1376]
I second that.
Anton
23-Jun-2005
[1377x2]
I don't remember seeing that in rambo.
Doesn't appear to be there. I searched "binary!" and "binary"
Ladislav
23-Jun-2005
[1379]
submitted
Piotr
23-Jun-2005
[1380]
does anybody know why code below give me diffrent results? looks 
like get/set funcs operate on diffrent contexts:

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] [set (to-word join "no-" x) "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
Ladislav
23-Jun-2005
[1381]
to-word creates global words
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 ...