Reflection brings intelligence to language because their programs can do introspection upon themselves. Rebol is a meta-circular language based on its Homoiconicity property.
From Wikipedia:
In computer programming, homoiconicity is a property of some programming languages, in which the primary representation of programs is also a data structure in a primitive type of the language itself, from homo meaning the same and icon meaning representation.
That’s why there’s no need of a complex Reflection API as you can just use rebol standard functions to get the meta-structure of your Objects. This is how.
Let’s create a simple object (see “Rebol is a Prototype-Based OOP Language“):
Object: make Object! [
a: 1
printa: func[][print a]
]
We could also build this object from a data block:
Block: [
a: 1
printa: func[][print a]
]
Object: make Object! Block
You just have tackled the code-data duality in Rebol. If test in Rebol’s Console:
>> Object/a
== 1
>> Object/printa
1
To get the body block of the Object, you can type
pick to-block mold object 3
which will output in Rebol’s Console:
>> pick to-block mold object 3
== [
a: 1
printa: func [] [print a]
]
Now try this:
>> pick pick to-block mold object 3 1
== a:
>> pick pick to-block mold object 3 2
== 1
>> pick pick to-block mold object 3 3
== printa:
>> pick pick to-block mold object 3 4
== func
>> pick pick to-block mold object 3 5
== []
>> pick pick to-block mold object 3 6
== [print a]
>>
A shorter way to get the definition of ‘a and ‘printa is to use the Rebol get in function:
>> probe get in object 'a
1
== 1
>> probe get in object 'printa
func [][print a]
>> probe second get in object 'printa
[print a]
== [print a]
>>
Now what if you want to get the list of Objet members?
Let’s first experiment:
>> pick pick to-block mold object 3 1
== a:
>> type? pick pick to-block mold object 3 1
== set-word!
>> pick pick to-block mold object 3 2
== 1
>> type? pick pick to-block mold object 3 2
== integer!
>> pick pick to-block mold object 3 3
== printa:
>> type? pick pick to-block mold object 3 3
== set-word!
>> pick pick to-block mold object 3 4
== func
>> type? pick pick to-block mold object 3 4
== word!
>> pick pick to-block mold object 3 5
== []
>> type? pick pick to-block mold object 3 5
== block!
>> pick pick to-block mold object 3 6
== [print a]
>> type? pick pick to-block mold object 3 6
== block!
>>
As you can see a: and printa: are of type set-word! so that we can implement our functions:
members: func[Object /local block][
block: copy []
foreach element pick to-block mold object 3 [
if set-word? element [
append block element
]
]
block
]
Test the function:
>> object-members: members object
== [
a:
printa:
]
>> length? object-members
== 2
>> object-members/1
== a:
>> object-members/2
== printa:
>>
To learn more see chapter 10 of Rebolcore.















Hi RebolTutorial,
Very nice and usable colors (more reader friendly) since your last update.
And so cool contents.
By the way how can you get your banner contents ? is it automated from the contents of the twitter RSS or do you manually select this contents.
And if I wanted to get my own blog to share my future DSL and REBOL explorations with others like you what site can you recommend for me ?
What kind of tool are you using ? Online or standalone ?
Thanks for sharing the info.
I love your set-up - easy to follow, to read and to find information.
Keep up the good work,
Regards,
Gerard
If you want a webhosting there are plentifull over there. If you want Rebol support this one does it
Dreamhost
But if you just want to blog about rebol, I am offering to rebol’s community a free blogging space for example for you here http://reboltutorial.com/gerardcote/
Thanks for these explanations.
Today I tried this reflective part of the language, like you explain here.
I posted my explorations on the ML but finally I woud have needed more insights about the internals of REBOL to be able to get a hook on the embedded View Editor, to enhance it. Finally the ctx-edit/view-file is too deep for me but may be sometimes later I will be able to do what I need.
Really very powerful. Not many other tools seem to share this vision of the programmng and what some programmers need to keep exploring new concepts. It’s so easy with REBOL …
As for me, I only venture where I have still foot on the ground