REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
As with many other REBOL datatypes, you can access the components of objects in a manner that allows you to write useful tools and utilities for creating, monitoring, and debugging them.
The first and second functions allow you to access the components of an object. The first function returns the words defined for an object. The second function returns the values that the objects are set to. The following diagram shows the relationship between the return values of first and second:
The advantage to using first is that it allows you to obtain a list of the words for the function without knowing anything else about the function:
probe first luke
[self first-name last-name account balance]
In the above example, notice that the list contains the word, self , which is a reference to the object itself. You can exclude self when getting an object's word list by using next:
probe next first luke
[first-name last-name account balance]
Now you have a way to write a function that can probe the contents of an object:
probe-object: func [object][ foreach word next first object [ print rejoin [word ":" tab get in object word] ] ] probe-object fred first-name: Luke last-name: Lakeswimmer account: 89431 balance: $1204.52
When accessing objects in this fashion, care should be taken to avoid infinite loops. For instance, if you attempt to probe certain objects that contain references to themselves, your code may begin an endless loop. This is the reason why you cannot probe the system object directly. The system object contains many references to itself.
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |