[source]//
// LISTOFINTEGERS.EPOCH
//
// Simple implementation of a singly linked list holding integers
//
type listnode : list | nothing
structure list :
integer value,
listnode next
prepend : list ref thelist, integer value
{
list newlist = value, thelist
thelist = newlist
}
append : list ref thelist, integer value
{
append_recurse(thelist, thelist.next, value)
}
append_recurse : list ref thelist, nothing, integer value
{
list newlist = value, nothing
thelist.next = newlist
}
append_recurse : list ref thelist, list ref tail, integer value
{
append_recurse(tail, tail.next, value)
}
next : list ref thelist -> listnode tail = thelist.next
next : nothing -> listnode tail = nothing
checkvalue : list ref thelist, integer expected
{
assert(thelist.value == expected)
}
checkvalue : nothing, integer expected
{
print("Unexpected end of list")
assert(false)
}
dumplist : list ref thelist
{
listnode nn = thelist.next
dumplist(nn)
}
dumplist : nothing
{
}
entrypoint :
{
list numbers = 1, nothing
append(numbers, 2)
append(numbers, 3)
prepend(numbers, 0)
dumplist(numbers)
assert(numbers.value == 0)
listnode node = next(numbers)
checkvalue(node, 1)
node = next(node)
checkvalue(node, 2)
node = next(node)
checkvalue(node, 3)
print("Pass")
}[/source]
I'm pretty happy with that, considering I've been gone for the last several months (jeez... was it really April that I made the last release!?). (For the record, I haven't been slacking off... I just shipped this little game nobody's ever heard of during that time.)
Next up, I'm tackling generic programming. The easy part will be generic structures:
[source]structure testwrapper :
T contents,
string tag
entrypoint :
{
testwrapper intwrap = 42, "number"
testwrapper strwrap = "test", "text"
assert(intwrap.contents == 42)
assert(strwrap.contents == "test")
print("Pass")
}[/source]
It'll be much harder to implement generic functions:
[source]add : T a, T b -> T sum = a + b
entrypoint :
{
integer foo = add(40, 2)
integer bar = add(3.0, 0.14)
assert(foo == 42)
assert(bar == 3.14)
print("Pass")
}[/source]
Hopefully I can knock out the quick foundation of generic structures over this weekend (it's pretty trivial) and then dig into generic code gen later on.
So that's what's up.