Re: Designing my own Programming Language
Posted: Wed Sep 02, 2009 11:17 pm
I've modified the syntax just slightly, but it's essentially the same. I'd like to show you how basic flow-control blocks could be defined just using built-in data matching and recursion.
Now I'm wondering if I really want to be so reflective or if I want to build in basic functions like this... Someone also suggested constructs like the following, for advanced control over the data matching with a 'where' keyword:
Still, that's easily done with an if statement and doesn't really help with typing, so I doubt its use.
Code: Select all
if:
{ x: true, y.
y.
}
{ x: false, y. } <-- no error, but do nothing
while:
{ x: bool, y.
if x,
{ .
y.
while x, y.
}
}
for:
{ stop: int, block.
start: 0.
step: 1.
for start, stop, step, block.
}
{ start: int, stop: int, block.
step: 1.
for start, stop, step, block.
}
{ start: int, stop: int, step: int, block.
i: int; = start.
while (i between start, stop),
{ .
block start.
i += step.
}
}
foreach:
{ x: enumerable, block. <-- enumerable is the prototype to a bunch of objects, like lists
for 0, x length, 1,
{ i.
block (x i). <-- i is the index in the enumerable x
}
}
Code: Select all
isEven:
{ x: Int where (x % 2 == 0).
^true.
}
{ x: Int. <-- less specific so gets called otherwise
^false.
}