janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.52k stars 227 forks source link

Discuss: lack of distinction between call and get in abstract types. #263

Closed andrewchambers closed 4 years ago

andrewchambers commented 4 years ago

Currently it is not possible to call an abstract type as a function, indeed calling an abstract type and getting from one are the same operation.

This became apparent to me when making the https://github.com/andrewchambers/janet-jcjit library:

(def f (jit/compile ....))
# impossible to call f (f)
(jit/call f args...)

I was curious if this is a specific design decision? I suppose you could say the current design assumes abstract types are more like data structures than anything else.

If it's something worth adding, I'd be willing to do the patch.

Of course, its easy to work around in the current form using a trampoline function.

bakpakin commented 4 years ago

Originally, I wanted to discourage making everything callable and only functions/cfunctions to be callable, simply because one cannot resume a fiber over C stack frames. When it became clear that I was being a bit paranoid and it was useful to make many things callable for indexing, methods, etc. I changed my mind. I just haven't yet added callable abstracts.

For various reasons, I don't think it's as big of an issue now. I can add such functionality.

andrewchambers commented 4 years ago

Thank you for explaining

pepe commented 4 years ago

This is now solved by https://github.com/janet-lang/janet/commit/b8d530da36d01cfd8e5b05879bfb5a51d8a1ce05 ?

andrewchambers commented 4 years ago

yes