[stack] Some thoughts on Object Cat
"Christopher Diggins" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
In the quest to add objects to Cat I am thinking of doing some rather
strange things.
==
1) Adding a new instruction to create an object:
object : ( -> object)
2) Adding a new instruction form (any word ending with '+') to
indicate adding a field to an object:
field+ : ('o 'a -> 'o+field:'a)
This is so that I can support prototype-style object oriented programming.
3) Adding a new instruction form (any word ending with '?') to
indicate a field getter
field? : ('o -> 'o 'o.field)
4) Adding a new instruction form (any word ending with '!') to
indicate a field setter
field! : ('o 'o.field -> 'o)
==
So here is how it would look:
>> object
stack: ()
>> 0 x+
stack: (x=0)
>> 0 y+
stack: (x=0,y=0)
>> 12 x!
stack: (x=12,y=0);
>> x? 30 + y!
stack: (x=12, y=42)
I love to hear any comments or suggestions. I am really not happy with
the syntax of types for adding fields (#2), but it seems like a
neccessary evil.
Christopher Diggins
http://www.cdiggins.com