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

World: r3wp

[Rebol School] Rebol School

kib2
26-Feb-2009
[2483]
I'm mising something here :

#!/usr/bin/rebol -q

REBOL [
    Title: "Tests with oo programming"
    Date: 26-Feb-2009
    Author: "Kib"
    File: "ooo1.r"
    Purpose: "nothing interesting"
]

son: make object! [
    parent: none
    name: "object b"
    get-parent: does [print parent]
]

mother: make object! [
    name: "object a"
    son-instance: make son [parent: self]
]

pony-mum: make mother []
print ["object name: " pony-mum/name]
print ["instance name: " pony-mum/son-instance/name]

print ["instance name:(other method) " pony-mum/son-instance/get-parent]

What's wrong with the last call ?
Graham
26-Feb-2009
[2484]
son-instance: make son [parent: self] 

self refers to son-instance
kib2
26-Feb-2009
[2485]
Graham : as i'm inside mother, self refers to a mother no ?
Graham
26-Feb-2009
[2486x2]
It looks like you're inside son-instance
mother: make object! [ name: "object a" myparent: self son-instance: 
make son [ parent: myparent ]]
kib2
26-Feb-2009
[2488]
>>it looks like you're inside son-instance


I don't understand why, sorry. I'm inside mother (I mean, when I 
write it "son-instance", but maybe it's a bad Python habit). 
 
mother: make object! [
    name: "object a"
    son-instance: make son [parent: self]
]
Graham
26-Feb-2009
[2489x2]
http://rebol.com/r3/docs/concepts/objects-self.html
you're creating a new object son-instance so self now refers to son-instance
kib2
26-Feb-2009
[2491x2]
You mean when I write "make son ..." I'm already inside the son object 
?
that may explain my problem
Graham
26-Feb-2009
[2493]
I think so.
kib2
26-Feb-2009
[2494x2]
ok: thanks !
Is there any lib somewhere to encode or decode a file to utf-8 ?
Anton
27-Feb-2009
[2496x2]
Test it:
>> son: context [parent: self]
>> son/parent = son
== true
You could do:

	mother: context [
		son: context compose [parent: (self)]
	]

so now

	>> mother/son/parent = mother
	== true
Graham
27-Feb-2009
[2498]
better idea :)
Anton
27-Feb-2009
[2499]
Oldes did some work with unicode, if I remember correctly.
kib2
27-Feb-2009
[2500]
Anton: hi! thanks a lot: what's the meaning of the parenthesis here 
?
Anton
27-Feb-2009
[2501x4]
The COMPOSE rebuilds the block, with anything in parens evaluated 
first.
So SELF will be evaluated before the second CONTEXT has a chance 
to see it.
But, if you're curious, you can always have a look yourself, using 
PROBE, eg:

	mother: context [son: context compose probe [parent: (self)]]

	mother: context [son: context probe compose [parent: (self)]]
mother: context [son: context probe compose [parent: (self)]]

etc..
kib2
27-Feb-2009
[2505x2]
ah...funny : nice example.
For the encoding, I was asking this because all my accented chars 
in HTML appear correctly but one, the "à".
Anton
27-Feb-2009
[2507x2]
Just move the probe from right to left to find out what's happening.
kib2, check rebol.org. I just did some quick searching.
http://www.rebol.org/view-script.r?script=utf8-encode.r
http://www.rebol.org/view-script.r?script=utf-8.r
kib2
27-Feb-2009
[2509]
Anton: thanks, exactly what I was looking for :)
kib2
2-Mar-2009
[2510]
Is it possible to draw something (lines, arrows, curves, etc) on 
top of buttons in a GUI app ?
Geomol
2-Mar-2009
[2511]
view layout [button 200 "Button with graphics" effect [draw [line 
0x0 10x20 40x0 60x20]]]
kib2
2-Mar-2009
[2512]
Geomol: sorry, I should have said "on top of several buttons". 

See http://farm4.static.flickr.com/3664/3323050539_dbd72b61e8_o.png
where I want to draw lines between numbers.
Geomol
2-Mar-2009
[2513]
view layout [origin 0 space 0 button 50x50 "1" button 50x50 "2" at 
0x0 box 50x100 effect [draw [line 0x0 30x20 0x60 40x100]]]
kib2
2-Mar-2009
[2514]
Extra: thank you!
Henrik
2-Mar-2009
[2515]
will events pass through the box?
kib2
2-Mar-2009
[2516]
Henrik: I think so, why ?
Geomol
2-Mar-2009
[2517]
:-) heh, prob. not. But I bet, kib can figure that out.

Don't you wanna interact the buttons with the mouse?
kib2
2-Mar-2009
[2518]
Geomol: yes with the mouse; in fact if you click on a number, i should 
draw all possible bridges (lines) coming from it.
Geomol
2-Mar-2009
[2519x2]
When you have the box with the lines on top over all the buttons, 
you can't press them directly.
Your mouse button press will 'hit' the box with graphics.
kib2
2-Mar-2009
[2521]
Ok, thanks for the hints : I think I have to study VID events a little 
more than what I've already done.
PatrickP61
2-Mar-2009
[2522]
I have a question on same?  Do the following:
a: "apple"
b: to-string 'apple
same? a b
== false


Why is that, they are both strings of the same length and datatype, 
just not created in the same way?
kib2
2-Mar-2009
[2523]
Good question : i really don't know. Moreover, a == b returns true.
PatrickP61
2-Mar-2009
[2524x2]
I tried this too:
a: "apple"
b: "apple
same? a b
== false


Does same? mean that it is the same object, not that the contents 
are the same?
I found the answer,  It is ONLY if the two are the same object
kib2
2-Mar-2009
[2526]
I know that = compares values, == compares values and types. Same? 
is native, and the docs says "Returns TRUE if the values are identical".
Henrik
2-Mar-2009
[2527x2]
same? means litterally the very same string.
same? is useful for identifying references.
kib2
2-Mar-2009
[2529]
Henrik: do you mean their location (via a pointer) ?
Henrik
2-Mar-2009
[2530x3]
yes
it's not entirely like pointers, but BrianH can explain that much 
better than me.
>> a: "boo"            
== "boo"
>> b: reduce [a copy a]
== ["boo" "boo"]
>> same? b/1 a
== true
>> same? b/2 a
== false