what is foop
What is FOOP? | Artful Code
FOOP is the concept of functional object oriented programming in newLISP. It originated in a thread on the newLISP forum and was officially added to the interpreter for newLISP 9.3.
To be fair, the FOOP operator, :
, does not provide any truly new functionality to newLISP. However, it does make prototyping much more concise and expressive.
The basics
Prototyping is accomplished using a source context
(a lexical closure) and the new
keyword. Using the commonly contrived example of the Rectangle object:
(context 'Rectangle) (set 'x nil) (set 'y nil) (define (area) (* x y)) (context MAIN) (new Rectangle 'my-rectangle) (set 'my-rectangle:x 10) (set 'my-rectangle:y 20)
FOOP uses the convention of (object member member ...)
for storing object instances. Instance data, apart from the members, is encapsulated within the context, so all of the methods may access contextually set variables. Although not built into the interpreter, the functional convention,
(define (Class:Class) (cons (context) (args)))
…is typically used to create new contexts for FOOP. Using Class
, the above example would be written as:
(new Class 'Rectangle) (set 'my-rectangle (Rectangle 10 20))
Methods are attached via the normal syntax for declaring foreign context functions, but with the assumption of the argument being the (object member member ...)
convention and implicit indexing: