REBOL 3.0

Typed Object Variables

Carl Sassenrath, CTO
REBOL Technologies
2-May-2006 16:47 GMT

Article #0016
Main page || Index || Prior Article [0015] || Next Article [0017] || 33 Comments || Send feedback

REBOL 3.0 has the ability to keep type information about the fields (variables) of an object. For example, if your object has a name, and you only want it to be a string, you can require that.

The type information for the fields is held in the new R3 context structure. It is a typeset value so you can specify multiple types, just like you can with function arguments (in fact it uses the same mechanism as functions, reducing the size of REBOL).

Question is: how best to specify object field datatypes? This is a somewhat difficult question because in REBOL object definitions are also object field initializers. You write:

make object! [
    name: "Bob"
    age: 27
    city: "Mendocino"
]

The object specification block is a valid REBOL block that is evaluated, and the initial values are set.

One solution might be to allow an object attribute block similar to function attributes. If the first value of the object definition is a block, it can mean something special:

make object! [
    [name: city: [string!] age: [integer!]]
    name: "Bob"
    age: 27
    city: "Mendocino"
]

Of course, we also want to consider what other attributes we may want to allow for objects in the future, because we don't want to add this nice attribute method and find that we cannot add other types of attributes later (such as field locking, change monitoring, etc.)

Post your comments. Thanks.

33 Comments

REBOL 3.0
Updated 25-Dec-2024 - Edit - Copyright REBOL Technologies - REBOL.net