GassaFM / interpr

Toy language to learn parallel computing
MIT License
5 stars 4 forks source link

Function-in-function #26

Open eqimd opened 4 years ago

eqimd commented 4 years ago

There's no way to use returned function's value by another function (like print(receive(0))), but it's an useful thing.

GassaFM commented 4 years ago

The receive function is unfortunately special.

Consider a statement x := receive (0) + receive (1). Suppose the queue from process 0 contains an integer, but queue from process 1 doesn't. The interpreter starts by taking the number from queue 0, and then learns there is no number in queue 1. So we have to try again on the next step.

Now we have to either roll back the state of queue 0, or store intermediate state of expression evaluation. Both require nontrivial effort to implement.

To avoid such cases, receive is restricted to statements of the form var <assignOp> receive (num), a single assignment operator.

eqimd commented 4 years ago

So, there's no another functions(excluding send) and perhaps this thing will be added later as far as will be added user's functions.

GassaFM commented 4 years ago

There are send, receive, array, and print, but all of them are special. And print(fun(...)) would work right now if there was a non-special function fun... :)

eqimd commented 4 years ago

Sure? Didn't know. But we still need user's functions or recursion on the main function :)