Tuesday 23 April 2013

A new way to use object! type

Rebol object! is a content, usually objects are made this way:

car: make object! [
wheels: 4
engine: 'broken
battery: 100
name: "polo"
]


or this way:


car: context [
wheels: 4
engine: 'broken
battery: 100
name: "polo"
]


Objects may be used also to create a lot of temporary variables, executing commands, and exit as nothing happened. See the following example:


>> context [
a: "Test string"
b: 2
c: 3
print a
print (b + c)
]
== "Test string"
5

>> value? 'a
== false


As you can see, a b and c variables are not effected!

Moreover, if a variable is not set in the object will be used the same variable out of the object (if defined). Let's see another example for more information:


>> a: "hello"
>> context [ print a]
== hello
>> context [
a: 20
print a
]
== 20
>> print a
== hello


It's the paradise of temporary variables!!!

No comments:

Post a Comment