Object problem
[1/5] from: cyphre::volny::cz at: 18-May-2001 11:21
Hello all at List,
Has anyone solution for that?
lets have object:
o: make object! [
a: 5
x: [a]
]
then
do o/x
== 5
thats ok
now try
o: make o [b: 10]
append o/x 'b
== [a b]
do o/x
** Script Error: b has no value
** Where: do-events
** Near: b
>>
huh, where is problem?
I awaiting your solutions.
Regards
Cyphre
[2/5] from: fsievert:uos at: 18-May-2001 11:47
On Fri, 18 May 2001, Richard Smolak wrote:
> o: make o [b: 10]
> append o/x 'b
<<quoted lines omitted: 5>>
> >>
> huh, where is problem?
You appended a b which is bound to the global context, not to the
objects's context. Try
append o/x in o 'b
Frank
[3/5] from: cyphre:volny:cz at: 18-May-2001 12:25
Hello Frank,
Thanks, it works great :-)
Regards,
Cyphre
[4/5] from: joel:neely:fedex at: 18-May-2001 7:12
Richard Smolak wrote:
> o: make object! [
> a: 5
> x: [a]
> ]
>
...
> o: make o [b: 10]
> append o/x 'b
<<quoted lines omitted: 4>>
> ** Near: b
> >>
I won't repeat the answer that Frank already provided, but
take the opportunity to make a sales pitch for our mental
model of REBOL to separate more carefully between source
notation and "inner REBOL". (I've been bitten myself, and
have recently found this distinction helpful.)
We can have multiple words whose names are spelled the same,
if those words "live" in different contexts. That was the
key to the above puzzler. We can also have words whose
names are not spelled according to the standard REBOL rules,
if we construct those words ourselves instead of having
REBOL create them by the default DO or LOAD behavior.
A "source code word" must be constructed by certain rules
(letters, digits, certain punctuation marks, etc.) because
that's how REBOL decides at LOAD time to construct a WORD!
instead of (e.g.) an INTEGER! or a URL! or whatever. But
Ladislav has published some little koans that can be put
together in the following block with curious behavior:
>> b
== [+1 a a a a a]
>> print b
0.9 42 -1 wot? impossible!
>> length? b
== 5
>> foreach thingie b [print get thingie]
0.9
42
-1
wot?
impossible!
>> foreach thingie b [
[ print [type? :thingie tab type? get thingie]]
word decimal
word integer
word integer
word string
word string
>>
*** If you want to ponder on this puzzle, don't read
*** beyond this point!
The curious block B was created as follows:
>> a: 42
== 42
>> b: [a]
== [a]
>> use [a] [a: -1 append b [a]]
== [a a]
>> do func [a][append b [a]] "wot?"
== [a a a]
>> do compose/deep [(to-set-word "a a") "impossible!"
[ append b [(to-word "a a")]]
== [a a a a a]
>> do compose/deep [(to-set-word "+1") .9
[ insert head b [(to-word "+1")]]
== [a a a a a]
>> b
== [+1 a a a a a]
Consequently, the first and last "real words" in B have names
that wouldn't have been legal as "source code words". This
could provide some interesting food for thought in the area
of code shrouding!
Just another illustration of the subtlety available with
an extensible, dynamic language!
-jn-
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com
[5/5] from: gjones05:mail:orion at: 18-May-2001 7:33
From: "Joel Neely"
<snip>
> Ladislav has published some little koans that can be put
> together in the following block with curious behavior:
<snip>
Koan -- new word for me. What I needed was a riddle in the form of a
paradox used in Zen Buddhism as an aid to meditation and a means of
gaining intuitive knowledge about the word koan, so I sat and meditated
(over an open dictionary). And guess what happened?!
;-)
Neat word!
--Scott Jones
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted