alpaca-lang / alpaca

Functional programming inspired by ML for the Erlang VM
Other
1.44k stars 48 forks source link

kernel.apl - alpaca core functions #184

Open Licenser opened 7 years ago

Licenser commented 7 years ago

The thought is the following: let the compiler to the bare minimum work of bootstrapping the alpaca primitives and implement as much of the rest in alpaca itself. So everything that is in the compiler right now that could be a function ends up being a function.

There are a few advantages to that:

And some disadvantages:

I've not read every line of the compiler but most notabley are the mathematical operators. Instead of a special compiler case for them they'd turn into something like:

let (+) left right =
  match (left, right) with
   (l, r), is_integer i, is_integer r -> beam :erlang :+ [left, right]
Licenser commented 7 years ago

Oh I forgot the most important part, kernel.alp would be loaded into the global namespace like the + function in erlang is.

lpil commented 6 years ago

Would any overhead would be introduced by wrapping functions like that?

j14159 commented 6 years ago

I think the only overhead would be the guard functions, not sure what the impact is there though tbh. We could do this all with type specs now although I'm not sure that would set the best example :)