User loginNavigation |
Functional single argument style object oriented programmingSo I had this thought as regards a programming language. Basically it would a lot like forth, only instead of a stack there would be a default initial object. You get new objects by sending messages to this initial object. Things like numbers would actually be messages that would result in the receiver producing a new object to act like a number. The only thing you could write would be messages. Messages would be represented in the source file as whitespace separated strings, much like forth. Other than that there would be no syntax. Basically, I want you guys who all know a lot more than me to point out the flaws in this idea. Heres some examples of what I envision: 1 + 2 This would break down into: 1 Send the message "1" to the default object, this will result in a new object being returned that results in the integer 1. 1 + This sends the "+" message to the 1 object, which returns a new object an "adder". 1 + 2 This sends the "2" message to the "1 +" adder object. this results in a new object, a three. As you can see, messages are evaluated from left to right, and there are no arguments. A program in this language could almost be viewed as one giant single argument function. Unlike FORTH, you don't have to use post-fix notation (although there is no operator precedence, just as in Smalltalk). Due to the syntactic baggage of a class based object system I would suggest this be implemented as a prototyped system. A clone message could be used to well clone an object. You could then add methods to it by sending it another message: clone define-response hello string hello display end-define-response hello I have named my method definition method "define-response" since messages are pretty much the only thing you got, and your more responding to messages than invoking methods. Of course if the above is confusing it can of course be written as (I will borrow FORTHs commenting convention here): clone ( Create a new object ) define-response hello ( define the hello method ) string hello ( Create a string with the contents "hello" ) display ( Display that string and return it ) end-define-response ( Finish the method definition and return the object ) hello ( Call the hello method of the newly created object )
Note that define-response creates an object that sets up some internal state. It receives its first message, it responds by naming the method for the object it is creating after the message it just receives. It then returns a new object that simply consumes and stores the messages it receives until it receives a message of end-define-response When it receives this response it creates the method in the object it was defining it for and returns that same object. You can now call additional methods on it, including defining more methods. You can see how any control structure can be implemented thru a combination of this kind of object and/or recursion. Nesting can be handling by having these objects maintain an internal stack, they need only recognize an invocation of themselves, any other nesting problems can be detected when the message is responded to. define-response x 1 end-response x display ( Prints 1 ) But that's verbose and creates the equivalent of global variables. It also has performance issues since x has to be evaluated every time it is called, this creates problems especially if the object created is complex. So I propose a slight modification to the define-response method. The creation of a define-response-immediate method. The only difference between the two would be that the body of a define immediate response would only be evaluated once, when the method was defined. Every other time the message was sent it would return the cached value. The rest of the issues with the verboseness of variables could be handled with additional methods, like copy_to e.g. 1 + 2 copy_to x It uses this "backwards assignment, since I'm trying to avoid parentheses, although they could be added. I look forward to any criticism. By Logan Capaldo at 2006-04-21 02:06 | LtU Forum | previous forum topic | next forum topic | other blogs | 9527 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 17 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago