REBOL 3.0

Object APPEND, COPY, LENGTH?

Carl Sassenrath, CTO
REBOL Technologies
23-Mar-2007 21:17 GMT

Article #0073
Main page || Index || Prior Article [0072] || Next Article [0074] || 13 Comments || Send feedback

In addition to standard object actions, R3 allows:

 appendextends the object with new word/value pairs (the input object is modified). New words must not already be fields of the object, or an error will result. Words can be word or set-word values. No binding is done on the data value parts (so words within blocks and functions do not get bound to the new context).
 copyclone the object. Deep copy all series within it. Currently, no rebinding is done. (Words within blocks and functions do not get bound to the new context.)
 length?return the number of instance variables. (Faster and less garbage than doing a length? first operation.)

Example of append:

>> a: make object! [b: 10]
>> append a [c: 20]
== make object! [
        b: 10
        c: 20
   ]

To get the length:

>> length? a
== 2

The copy function works as you would expect.

Why not insert, remove, etc.?

Why not allow insert and other series modifying functions to work on objects? Because they would corrupt the bindings of words within the object.

13 Comments

REBOL 3.0
Updated 19-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net