3 ms·
is the environment also available? are environments first class? it talks only about expressions - the environment in which they are evaluated seems to be imp
by andrewcooke 13y ago
is the environment also available? are environments first class? it talks only about expressions - the environment in which they are evaluated seems to be implicit.
what could you do with first class environments? could you implement logic variables and backtracking? something like oz?
also, i think julia is optionally typed? what's the type system like for expressions? i saw an 'Any' in the link, which looked worryingly vague.
[having said all that, as a "scientific programmer", i am worrying more and more that this is a language i really should be using]
[edit: thanks for the informative replies]
- StefanKarpinski 13y agoEnvironments are intentionally not first class: that particular dynamic feature really sabotages optimization and can generally be worked around (e.g. instead of letting the full environment escape, expose a closure that mutates only what must be mutated). Julia has optional type annotations, but this doesn't mean that code without types is dynamic while code with types is static – all code is dynamic, the type annotations just limit the set of types that values can have. It's a subtle but important distinction.
- KenoFischer 13y agoAll toplevel expressions are evaluated within a module which is a first class object. Other than that you always need to place the expression into its environment (to construct top-level expressions). If you just place macros the environment is not accessible (i.e. macros operate solely on their arguments), however, you can distinguish whether a symbol will be evaluated within the defining scope (of the macro) or the scope in which it is used. Regarding types, all expressions are of type Expr or Symbol (there's a few other things that can be in the AST, but that's mostly it). What kind of expression it is is determined by the head field. There as some discussion about making the Expr type parametric on its head field so you can dispatch on that, but nothing in that direction recently.