Using objects
Now we will discover how Red works with objects, which is probably different from what you are used to in classical object-oriented languages, such as Java, C#, Python, and Ruby. But first, we meet the make
word.
The make word
In the Using error? section inChapter 4, Code-Controlling Structures, we usedprobe
to get more details of a specific error, and this returned an output starting withmake error! [ ... ]
. Theerror!
is effectively an object that was constructed withmake
.
It turns out that make
can be used to construct a new value for any datatype. It needs the type and, as a second argument, a specification for that type. This can be a value or a memory allocation, or another specification in the case of datatype!
, native!
, action!
, routine!
, and event!
Here are some examples:
;-- see Chapter06/objects.red: i: make integer!5; == 5 ; (1) output: make string!1000; == "" ; (2) blk: makeblock!20; == [] ; (3)
In line (1)
, the specification is the integer itself, in line (2)
, the...