The F in FOOP
When you do:
Code: Select all
> (new Class 'Person)
> (Person "JohnDoe")
The statement (Person "JohnDoe")
returns the same as an object. The object is
the functional statement to create itself. The constructor functor Person
is also the class id.
I'm sorry but it makes little sense to me. (Person "JohnDoe") is technically an expression, not a statement. It is indeed functional in the sense that it is a pure function, but so is (fn (x y) (+ x y)). The fact that Person is both in the result and is a class id is a neat generalisation of type tags that dynamic languages usually use internally. Calling statements or expressions "functional" doesn't make the language more functional.
If you talk to functional people, they'll tell you that the two main ideas of functional programming are immutability and side-effects management. When I removed (self), I overlooked the fact that (self) allowed to mutate the object, something that I cannot do any more because now the 'methods' receive a copy of the original object. To make it usable again, the method must return a new object:
(define (Person:rename p nn) (setf (p 1) nn) (p))
And that's exactly what a functional program does. Of course it has the downside of creating objects, but that's all the story about functional programming: mutability is a shortcut that saves memory and CPU cycles, but it can become a drawback (for debugging, for the gc, in the presence of threads, etc). If you observe functional programming languages, many features are there in order to deal with the lack of mutability.
Now if we talk about the OOP part, the first thing one could note is the lack of direct support for inheritance. As far as I understand it, (def-new) and (context)'s second syntax is supposed to help with that. The idea of inheritance is that the derived class "understands" the messages defined in its base class even though it doesn't define them explicitly.
What if we do:
(new Class 'Person)
> (Person "JohnDoe")
(new SubClass 'Person 'Worker)
>((Person Worker) "JaneDoe")
The newlisp engine could loop over the list in the first item until it finds the desired method symbol in the context.