catala icon indicating copy to clipboard operation
catala copied to clipboard

Proper environment, including builtins

Open msprotz opened this issue 4 years ago • 1 comments
trafficstars

I think it's time for a general syntax for arbitrary function calls, not just built-in functions that each have their dedicated keywords.

I would envision things such as

definition foo equals builtin::min of (bar, baz)

where the namespace is optional

internally, this would be implemented as follows:

  • a generic "call" AST node
  • the head of the call is a qualified name (first-order)
  • later on, there is an environment that to each namespace (e.g. builtin) maps a set of functions (the dependencies)
  • on top of that, a current environment maps unqualified names (e.g. min) to their respective definitions, to take into account the shadowing of open statements
  • directly written by hand is "builtin", the set of functions in the built-in namespace (e.g. min, excess_of)
  • there is an implicit open builtin at the beginning of each file

That way we don't rely on a limited set of known keywords (this does not scale, even with a hash table of keywords in the lexer) and we can make it feasible to extend the set of compiler built-ins. Also, this paves the way for proper handling of names once we have proper modularity.

Thanks,

Jonathan

msprotz avatar Sep 17 '21 00:09 msprotz

There are two parts in this:

  • arbitrary function calls — we already have this with multiple arguments now
  • namespacing — I believe this will be handled by the upcoming module system

Regarding these, this issue could be closed; however…

Builtins still have added power though, e.g. they can be overloads. More importantly, while there may be no need for them to be keywords, the parser is the only place at the moment where we handle multi-lingual input ; so this raises the question of how to handle internationalised libraries…

AltGr avatar Mar 08 '23 17:03 AltGr