Page 1 of 1

Examples from my Programming Language

Posted: Sun Aug 21, 2011 8:12 pm
by xvedejas
I'm working on a purely-OO language inspired by self and Smalltalk. I'm writing it entirely within my OS, and I've recently implemented an interesting programming concept called worlds. Here is a working code example:

Code: Select all

| point, A |
 
point = Object new init:
{
    | x, y |
    set: _x and: _y
    {
        x = _x.
        y = _y.
    }
    print
    {
        Console print: x.
        Console print: " ".
        Console print: y.
        Console print: "\n".
    }
}.
 
point set: 5 and: 6.
point print.
A = thisWorld spawn.
A eval: { point set: 8 and: 9. }.
point print.
A eval: { point print. }.
A commit.
point print.
 
// output:
 
5 6
5 6
8 9
8 9
You can read more about worlds here: http://www.vpri.org/pdf/tr2011001_final_worlds.pdf

Re: Examples from my Programming Language

Posted: Mon Aug 22, 2011 10:21 am
by xvedejas
There are a few differences to smalltalk syntax; you can see that braces are preferred over brackets, which honestly should make C/C++/Java programmers etc more comfortable. Also statements are expressions, so you can do weird things like:

Code: Select all

a = (b = 5. b + 6) * 10.
And then a == 110. Also, right now (this might change) messages are sent strictly left-to-right (in smalltalk, unary messages have precedence over binary messages which have precedence over all other messages). I guess most of the other syntactic changes are cosmetic.

Since worlds help to control side effects, the preferred way to catch exceptions is to spawn a new world. Here's an example:

Code: Select all

thisWorld spawn eval: 
{
    Console print: (1 / 0).
} on: [ #DivideByZero ]
do:
{ error |
    Console print: "can't do that!".
}.