did you know you do not need a real object for object-like behaviour.
This is not the solution to everything, but well used, it can be as effective.
note that in the following, there is no context. and no 'self word. (you could
define it, but I'll leave that little part as an exam. Actually, one solution is
included later ;-)
in short, just use a block which looks like the pairs of words and values you use to
define objects, but don't use set-word (word:) just simple words (word) .
blk: [
a 1
b 2
]
>> blk/a
== 1
>> blk/b
== 2
you can also add functions to it although its a little more complicated, but their
usage is as easy.
blk: compose [
a 1
b 2
pr (func [arg1][print [arg1 "...done!"]])
]
note the use of compose and the outer parenthesis surrounding the function definition
to use it though its as easy
>> blk/pr "hello world"
hello world ...done!
you can also assign values to the block like you would with objects:
blk/a: 44
when blocks are used for simple data storage, used properly, this trick makes blocks
behave almost identically like objects. With the difference that you can edit them
much more easily and that any references to them becomes safe.
adding a new thing to the object:
append blk [thing "thang"]
probe blk
[
a 1
b 2
pr (func [arg1][print [arg1 "...done!"]])
thing "thang"
]
but again, remember that there is no context, so functions do have limits unless you
really tear up your rebol mind and start doing run-time binding.. which is not the
easier task...
you can also add an argument to all functions called 'self, which then mimics the
useage of self. I this case, when calling a function in the block, just supply the
block as the first parameter of the function call...
with the tone of your mail, it seems that you are rather new to rebol.
if this is the case then Welcome!, and I hope this example is a true testatment to how
rebol can be used in many different ways.
Also note that rebol recycles most constructs you have learned, instead of forcing you
to learn completely new constructs for each different task. for example, arguments,
blocks of data, object specs code blocks, are all built up of BLOCK, which can be
expressed as rebol encounters them. in other languages, these are all built up of
different (similar) datatypes each allowing ONLY a (small?) subset of the capabilities
which they all share.
HTH!
-MAx
---
"You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun."
> -----Original Message-----
> From: Luke [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 13, 2004 5:22 AM
> To: [EMAIL PROTECTED]
> Subject: [REBOL] How to remove words from objects?
>
>
>
> Dear list
>
> I'm trying to dynamically add and remove words from an
> object. So far I can do the add words as follows:
>
> >> obj: make object! [a: 1 b: 2]
> >> probe obj
>
> make object! [
> a: 1
> b: 2
> ]
> >> obj: make obj [c: 3]
> >> probe obj
>
> make object! [
> a: 1
> b: 2
> c: 3
> ]
> >>
>
> now I want to remove c from obj. How do I do that. I
> know I could dynamically reconstruct it from scratch, but
> that is not very elegant. There must be a better way to
> get back to obj being:
>
> make object! [a: 1 b: 2]
>
> Any ideas?
>
> Thanks
>
> - Luke
> __________________________________________
>
> Various gadgets widgets, links and chat
> http://www.marmaladefoo.com
> __________________________________________
> --
> To unsubscribe from this list, just send an email to
> [EMAIL PROTECTED] with unsubscribe as the subject.
>
>
--
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.