entrypoint : () -> (){ operate(41, increment) operate(43, decrement)}increment : (integer(number)) -> (integer(result, 0)){ assign(result, add(number, 1))}decrement : (integer(number)) -> (integer(result, 0)){ assign(result, subtract(number, 1))}operate : (integer(number), function op : (integer)->(integer)) -> (){ debugwritestring(cast(string, op(number)))}
The increment function is applied to the value 41, which is then written out to the debugger by the operate function. Something similar then happens with decrement and the value 43.
The result, of course, is a shiny little "42/42" output in the debugger window.
Besides being just a plain damn handy feature by itself, higher-order function support will make it trivial to pass functions to external APIs. This means that, shortly, it will be possible to have a callback from an external API into Epoch code, via the marshaling interface of course.
I still have a lot of technical decisions to make about how exactly callbacks will work, but that's a ways down the road; I have to get higher-order functions totally polished off first.
Notably missing is the ability to statically validate a function to make sure it is acceptable. For example, in the above demo, the operate function expects as its second parameter a function that maps an integer onto another integer. Right now, I could pass a function that, say, maps an integer onto null; this would trash the VM's stack and cause chaos.
It's straightforward (but not exactly simple) to validate the function call statically, so that I can't do evil shenanigans like that. Well, to be honest, it is pretty simple - I'm 80% of the way there already - but it requires some refactoring of the way I handle function call validation in general, and I'm too lazy to mess with that right away.
So for now I'll be content with my "42/42" demo program, and we'll tackle static validation another day. I have a feeling there's generally a lot of miscellaneous type work I can do to the VM, so I'll probably sit down and have a hardcore cleanup session sometime in the near future.