Some other questions
[1/7] from: WisD00M::gmx::net at: 22-Nov-2003 5:47
I hope you guys don't mind me asking some other questions I have come up
with meanwhile.
1) If I have an object - how do I create an array of objects with it ?
for example
chicken: make object! [
tasty: "wings"
]
now I would want to have an array of objects of that type.
I tried it like that:
chickenfarm: make chicken [] array 10
It doesn't seem to work that way, though ?
I've read all stuff available about objects and array on the REBOL pages,
but either I'm blind or there isn't anything about creating an array
of objects ?
2) How do you create custom types ?
I am talking of a way to emulate the typedef behavour in C ?
How would you go to create an "enum" type in REBOL ?
3) Back on objects:
objects seem to be pretty neat in REBOL - but I didn't find anything about
implementing
and using constructor/destructors ?
I know I could manually add a function that serves as constructor each time
I create an object, but is that the way REBOL requires it ?
4) In the same context:
how do I actually 'free' memory/variables ?
5) On the webpage about objects one passage mentioned that "sub-objects"
don't get cloned-
what does that mean ? Reading that I would expect that all objects within an
object aren't
available when I create an object on the basis of that object.
But I seem to be able to use it anyway. Maybe I am getting something wrong
here ?
6) in VIEW/VID: How do you open/create several windows simultaneously ?
I am also talking of being able to refresh each window.
7) Trying to find a solution to the problem above I looked around the REBOL
webpages
and searched for a possibility to create threads - there doesn't seem to be
anything
like that - how is "parallel processing" achieved in REBOL ?
How would you update a dialog but also keep a timer running as well as
rotating an
image ?
8) On image rotation: is there any simple way to overcome the 90°
restriction -
I am not tallking of bitshifting manually ;-)
What's the reason for this restriction ?
9) Image creation/processing
I read it would be possible to create images on the fly and work with these
then -
is it possible to store an entire (view) layout within such an image ?
Could you for example draw a line on a "virtual" view and save this then to
an
image file ?
Or would you rather simply take the coordinates of the line and create the
image with that data ?
10) Image processing
Is it possible to create new images (in memory) by adding other images
to the original image at certain coordinates ?
Having tried to overlay transparent GIFs in a VIEW layout, I noticed
the transparency attribute doesn't seem to be preserved ?
At least transparent areas of my GIF didn't show the image below that
one, but rather a WHITE area.
IF transparent GIFs are supported: what do you need to do to really display
them properly ?
11) VID controls
If I need certain additional features for a basic control - like a progress
bar or slider,
how do I add these ? Do I need to edit the dialect ?
For example, I want a progress bar with tic-marks as well as a non-continous
filling of the bar.
So, is there any way to "sub-class" controls easily to enhace their
functionality/appearance without having to re-write everything from scratch?
12) Is there any really thorough information available on ACTIONS and EVENTS
with REBOL/VIEW ?
They documentation on the REBOL pages seems a bit 'poor' on that matter.
I don't know yet, how these things are really done behind the scenes.
13) I didn't see any designated function to set pixels at certain
coordinates in a layout-
my workaround was using the line word - with 1 width/height.
How is this really done ?
14) How do I catch mouse events - such as a mouseover event ?
I read about 'over' - it seems to do exactly what I need - I want to display
controls in a certain area only when the mouse cursor is in that said area.
Also, that functionality could be used to add tooltip-like behaviour to
buttons
and menus.
Again: thanks for your help and patience folks - it's really appreciated !!
--
regards
_________________
---------
Mike
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService
Jetzt kostenlos anmelden unter http://www.gmx.net
+++ GMX - die erste Adresse für Mail, Message, More! +++
[2/7] from: carl:cybercraft at: 24-Dec-2003 22:49
On 22-Nov-03, Mike Loolard wrote:
> I hope you guys don't mind me asking some other questions I have
> come up with meanwhile.
Hi Mike,
A few answers here, if not for all your questions...
> 1) If I have an object - how do I create an array of objects with it
> ? for example
<<quoted lines omitted: 7>>
> available about objects and array on the REBOL pages, but either I'm
> blind or there isn't anything about creating an array of objects ?
chickenfarm: array/initial 10 chicken
> 2) How do you create custom types ?
> I am talking of a way to emulate the typedef behavour in C ?
> How would you go to create an "enum" type in REBOL ?
Pass...
> 3) Back on objects:
> objects seem to be pretty neat in REBOL - but I didn't find anything
<<quoted lines omitted: 3>>
> each time I create an object, but is that the way REBOL requires it
> ?
Pass...
> 4) In the same context:
> how do I actually 'free' memory/variables ?
Memory's managed automatically with REBOL, so unless you're having
trouble with it, don't worry about it. For instance, if you have
this...
file: read %very-big-file
...
file: none
the memory used by very-big-file will be automatically reclaimed -
unless you've referenced it by another word. That said, you can force
a freeing up of memory with RECYCLE if needs be.
> 5) On the webpage about objects one passage mentioned that
> "sub-objects" don't get cloned-
<<quoted lines omitted: 3>>
> seem to be able to use it anyway. Maybe I am getting something wrong
> here ?
It means that sub-objects are the same object. ie...
>> obj: make object! [sub-object: make object! [test: "text"]]
>> obj2: make obj []
>> same? obj obj2
== false
>> same? obj/sub-object obj2/sub-object
== true
So, if you alter sub-object in obj2 there, sub-object in obj will also
be altered...
>> probe obj/sub-object/test
text
== "text"
>> obj2/sub-object/test: 10
== 10
>> probe obj/sub-object/test
10
== 10
> 6) in VIEW/VID: How do you open/create several windows
> simultaneously ? I am also talking of being able to refresh each
> window.
Here's one way...
win1: layout [f1: field "1" 100]
win2: layout [f2: field "2" 100]
win3: layout [f3: field "3" 100]
view layout [
button "Open Windows" [
view/new/offset win1 180x40
view/new/offset win2 330x40
view/new/offset win3 480x40
]
button "Update Windows" [
append f1/text first f1/text
append f2/text first f2/text
append f3/text first f3/text
show [win1 win2 win3]
]
]
> 7) Trying to find a solution to the problem above I looked around
> the REBOL webpages
<<quoted lines omitted: 3>>
> would you update a dialog but also keep a timer running as well as
> rotating an image ?
Each face in a layout can have its own event processing using FEEL.
Here's a window with the time being ubdated every second and a box
rotating four times a second...
pic: to-image layout [backdrop black box blue "A Box"]
view layout [
text to-string now/time 100 rate 1 feel [
engage: func [face action event][
if action = 'time [
face/text: to-string now/time
show face
]
]
]
image pic effect [rotate 90] rate 4 feel [
engage: func [face action event][
if action = 'time [
face/effect/2: face/effect/2 + 90 // 360
show face
]
]
]
]
There's a HowTo section on RT's site about FEEL...
http://www.rebol.com/how-to/feel.html
> 8) On image rotation: is there any simple way to overcome the 90°
> restriction -
> I am not tallking of bitshifting manually ;-)
I think you need to be. ;)
> What's the reason for this restriction ?
RT hasn't implimented it yet.
> 9) Image creation/processing
> I read it would be possible to create images on the fly and work
> with these then -
> is it possible to store an entire (view) layout within such an image
> ?
Yes -
to-image layout [whatever]
like I've done above.
> Could you for example draw a line on a "virtual" view and save this
> then to an image file ?
Yes, and to disk if you want...
save/png %test.png to-image layout [
box effect [draw[line 0x0 199x199]]
]
and to view it...
view layout [image load %test.png]
> Or would you rather simply take the coordinates of the line and
> create the image with that data ?
You can do that to...
start: 0x0
view layout [
b: box effect [draw[line start 199x199]]
button "+" [start/x: start/x + 10 show b]
button "-" [start/x: start/x - 10 show b]
]
> 10) Image processing
> Is it possible to create new images (in memory) by adding other
> images to the original image at certain coordinates ?
Doing it in a layout and then using TO-IMAGE is the simpliest, though
you can work directly on the image datatype...
>> pic: make image! 2x2
== make image! [2x2 #{000000000000000000000000}]
>> pic/1: 255.255.255.255
== make image! [2x2 #{FFFFFF000000000000000000}]
>> pic/3: 18.18.18.18
== make image! [2x2 #{FFFFFF000000121212000000}]
Gets a lot trickier to put images into images of course, but is
possible.
> Having tried to overlay transparent GIFs in a VIEW layout, I noticed
> the transparency attribute doesn't seem to be preserved ? At least
> transparent areas of my GIF didn't show the image below that one,
> but rather a WHITE area. IF transparent GIFs are supported: what do
> you need to do to really display them properly ?
Pass...
> 11) VID controls
> If I need certain additional features for a basic control - like a
<<quoted lines omitted: 5>>
> functionality/appearance without having to re-write everything from
> scratch?
Pass...
> 12) Is there any really thorough information available on ACTIONS
> and EVENTS with REBOL/VIEW ?
> They documentation on the REBOL pages seems a bit 'poor' on that
> matter. I don't know yet, how these things are really done behind
> the scenes.
Have you seen the HowTo on FEEL? (Link above.)
> 13) I didn't see any designated function to set pixels at certain
> coordinates in a layout-
> my workaround was using the line word - with 1 width/height.
> How is this really done ?
That's one way, the other being to work directly on an image in a
layout. ie...
pic: make image! 100x100
view layout [
image pic rate 10 feel [
engage: func [face action event][
if action = 'time [
poke face/image random (length? face/image) / 4
random 255.255.255
show face
]
]
]
]
> 14) How do I catch mouse events - such as a mouseover event ? I read
> about 'over' - it seems to do exactly what I need - I want to
> display controls in a certain area only when the mouse cursor is in
> that said area. Also, that functionality could be used to add
> tooltip-like behaviour to buttons
> and menus.
Once again, see the HowTo on FEEL mentioned above.
> Again: thanks for your help and patience folks - it's really
> appreciated !!
Hope that helps!
Hmm - the rugby's started... ;)
--
Carl Read
[3/7] from: carl:cybercraft at: 24-Dec-2003 22:49
On 23-Nov-03, A J Martin wrote:
> Hi, Joel!
> Joel wrote:
<<quoted lines omitted: 19>>
>>> x
> == ["abcdef" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc"]
Hmmm...
>> x: array/initial 10 "abc"
== ["abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc"]
>> insert tail x/1 "def"
== ""
>> x
== ["abcdef" "abcdef" "abcdef" "abcdef" "abcdef" "abcdef" "abcdef"
abcdef
"abcdef" "abcdef"]
I only get your result with View 1.2.10. With 1.2.1 and 1.2.5 I get
the above.
So, has the spec changed, or has a bug been added? (Or removed;)
--
Carl Read
[4/7] from: AJMartin:orcon at: 24-Dec-2003 22:49
Carl Read wrote:
> I only get your result with View 1.2.10. With 1.2.1 and 1.2.5 I get the
above.
> So, has the spec changed, or has a bug been added? (Or removed;)
Or removed. :)
; Replacement 'array function that copies objects and series.
array: func [
"Makes and initializes a series of a given size."
size [integer! block!] "Size or block of sizes for each dimension"
/initial "Specify an initial value for all elements"
value "Initial value"
/local block rest
][
if not initial [value: none]
if block? size [
rest: next size
if tail? rest [rest: none]
size: first size
if not integer? size [make error! "Integer size required"]
]
block: make block! size
either not rest [
any [
if series? value [
loop size [insert/only block copy/deep value]
]
if object? value [
loop size [insert/only block make value []]
]
insert/dup block value size
]
] [
loop size [
any [
if series? value [
value: copy/deep value
]
if object? value [
value: make value []
]
]
block: insert/only block array/initial rest value
]
]
head block
]
Andrew J Martin
Speaking in tongues and performing miracles.
ICQ: 26227169
http://www.rebol.it/Valley/
http://valley.orcon.net.nz/
http://Valley.150m.com/
[5/7] from: nitsch-lists:netcologne at: 23-Nov-2003 6:45
Am Sonntag, 23. November 2003 02:25 schrieb Carl Read:
> I only get your result with View 1.2.10. With 1.2.1 and 1.2.5 I get
> the above.
>
> So, has the spec changed, or has a bug been added? (Or removed;)
Spec changed. http://www.rebol.com/docs/changes.html#section-3.5 .
I would say cloning for object too is a good idea.
Ask feedback?
-Volker
[6/7] from: joel:neely:fedex at: 23-Nov-2003 0:01
Hi, Mike,
Mike Loolard wrote:
> 4) In the same context:
> how do I actually 'free' memory/variables ?
>
You don't need to do so, as memory management in REBOL is automatic
(including collection of circular garbage). However, if you are
doing some processing of large structures, you can limit the need
for REBOL to go back to the O/S and ask for more memory by clearing
out stuff you no longer need. If you only have one word that refers
e.g. to a large block, you can simply set that word to a trivial value,
such as NONE, to make the previous contents available for garbage
collection.
blort: make block! 100000
repeat i 100000 [append blort sine i] ; whatever
; then, after that block is no longer needed...
blort: none
You can also use CLEAR to remove all values from a series (from the
current position). This can be handy if you want to reuse the space
after the initial contents are no longer needed.
blort: make block! 100000
repeat i 100000 [append blort sine i]
; do something with sines
clear blort
repeat i 100000 [append blort cosine i]
; do something with cosines
clear blort
repeat i 100000 [append blort tangent i]
; do something with tangents
;... etc.
But, again, unless you're working on huge structures, have a long-
lived process, and are running on a small-memory or slow box, there's
seldom any reason to worry about such things.
-jn-
[7/7] from: joel:neely:fedex at: 23-Nov-2003 1:27
Hi, Mike,
Here we jump off the deep end... ;-)
Mike Loolard wrote:
> 5) On the webpage about objects one passage mentioned that "sub-objects"
> don't get cloned-
<<quoted lines omitted: 3>>
> But I seem to be able to use it anyway. Maybe I am getting something wrong
> here ?
If you have an object like this:
proto: make object! [
ID: 1
label: "My object"
]
then whenever you say
instance-1: make proto []
REBOL will implicitly clone/copy the string value for the LABEL
attribute, so that the new object doesn't have the *same* string
as the prototype.
Aside on Same-ness:
Consider this transcript:
>> a: "Whoopee!"
== "Whoopee!"
>> b: a
== "Whoopee!"
>> a/8: #"?"
== "Whoopee?"
>> b
== "Whoopee?"
The reason that the value for B changed is that B was set to (refer
to) the *same* string as A (i.e. not a copy):
>> a = b
== true
>> same? a b
== true
therefore there's only one string, but A and B can both "get at" it.
On the other hand, if we explicitly ask for copying:
>> a: "Whoopee!"
== "Whoopee!"
>> b: copy a
== "Whoopee!"
>> a = b
== true
>> same? a b
== false
>> a/8: #"?"
== "Whoopee?"
>> b
== "Whoopee!"
A similar situation (equal but not same) would result from saying
>> a: "Whoopee!"
== "Whoopee!"
>> b: "Whoopee!"
== "Whoopee!"
It's important to remember that "same" and "equal" aren't the same!
End of Aside on Same-ness
That means that we can examine our objects:
>> ? proto
PROTO is an object of value:
make object! [
ID: 1
label: "My object"
]
>> ? instance-1
INSTANCE-1 is an object of value:
make object! [
ID: 1
label: "My object"
]
>> same? proto/label instance-1/label
== false
and see that the LABEL attributes are equal strings, but are not the
same string.
Now, suppose that our prototype had an object as the value of one of
its attributes instead:
proto: make object! [
ID: 1
label: make object! [
part-nr: 38562
name: "Flanged widget"
]
]
and we used it as the basis of a new instance:
instance-1: make proto []
Now we can examine our objects
>> ? proto
PROTO is an object of value:
make object! [
ID: 1
label:
make object! [
part-nr: 38562
name: "Flanged widget"
]
]
>> ? instance-1
INSTANCE-1 is an object of value:
make object! [
ID: 1
label:
make object! [
part-nr: 38562
name: "Flanged widget"
]
]
>> same? proto/label instance-1/label
== true
and see that the "sub-object" referred to be the LABEL attribute
of INSTANCE-1 is the *same* object that is referred to by the LABEL
attribute of PROTO. That means (again) that changes/mutations of
that "sub-object" will be seen everywhere that it is referenced.
>> replace proto/label/name "widget" "blivet"
== "Flanged blivet"
>> ? instance-1
INSTANCE-1 is an object of value:
make object! [
ID: 1
label:
make object! [
part-nr: 38562
name: "Flanged blivet"
]
]
Now, to sum all of that up in a single sentence:
When a new object is created from a prototype object,
series-valued attributes of the prototype are copied,
but object-valued attributes are shared.
Hope this helps!
-jn-
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted