rebol_oopSome Purists would say Rebol is not a “true” OOP language because it lacks the concept of class. I remind that in OOP “oriented” actually means “just oriented” so that even traditional OOP languages like Java, C# etc. are themselves not true Object Languages.

Rather, one can consider two types of OOP languages: class-based and prototype-based. Historically class-based have been dominant. Rebol is of last type like Javascript.

But enough philosophy, let’s learn how to create a Rebol’s Object. Let’s create, for example an object modeling the price of the Dow Jones Industrial (DJI):

Launch Rebol’s Console, type or copy and paste the code below:


DJI: make object! [
Open: 0
High: 0
Low: 0
Close: 0
]

DJI/Open: 8556.96
DJI/High: 8616.59
DJI/Low: 8496.73
DJI/Close: 8539.73

Let’s add some methods (Range and Percentage):


DJI: make object! [
Open: 0
High: 0
Low: 0
Close: 0
Range: func[][Self/High - Self/Low]
Percentage: func[Previous-Close][
        Ratio: (Self/Close - Previous-Close) / Previous-Close
        round/to (Ratio * 100) 0.01
    ]
]

;test phase
;init attributes
DJI/Open: 8556.96
DJI/High: 8616.59
DJI/Low: 8496.73
DJI/Close: 8539.73

;call methods
DJI/Range
DJI/Percentage 8555.60

There’s a lot more to say about Rebol’s “Objectology” see “How to create an object dynamically from a persistent storage”

Note: we have already used object persistence for application configuration.

Reference: Rebol/Core Users Guide

Bookmark and Share