Working with fields and functions

Accessing a variable or a function within an object is done using the / (path) notation, which we already encountered as the way to access the elements of a series by index, or using the file-path notation:

square1/length    ;== 10square1/display   ; Length of square1 is 10

This works the same as the . (dot) notation using the square1.length and square1.display() classes in other languages.

In the same way, you can change data in the object:

square1/length: 5   ;== 5square1/length      ;== 5

Another way to do this uses get in or set in to access a field using the literal ' word notation:

get in square1 'length      ;== 10set in square1 'length 5    ;== 5

The set word can also be used to initialize all fields to none, or to ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.