Changes by: Jason Hickey (jyh at cs.caltech.edu)
Date: 2007-04-29 18:48:47 -0700 (Sun, 29 Apr 2007)
Revision: 10559
Log message:
Folded the "export" branch into 0.9.8.x (by hand). It _is_ a change,
but again, it should be invisible/backwards-compatible to normal users.
The main reason for doing this is rather major, in terms of code
structure. With this, the type "value" is unlinked from "venv",
so it can be pulled back all the way into src/ir.
- This means Omake_env is no longer a bottleneck(!).
This commit doesn't nothing like that. The commit is not that major,
but it does generalize the meaning of "export".
************************************************************************
** export
Add export sections.
* Language changes:
** Exports take effect for all sections within their static scope.
section
export
section
public.X = 1
println($X) # Prints 1
In addition, exports augment any existing exports.
section
public.X = 1
public.Y = 2
export X
section
X = 3
Y = 4
export Y
# X is 3
# Y is 2
** Variable definitions also allow exports.
public.X = 1
public.f() =
X = 2
export
public.Y = $f
# X is 2
# Y is 2
Note: this is not the same as imperative programming, because functions
can always choose not to export.
public.X = 1
public.f() =
X = 2
export X
public.Y = $f
# X is 1
# Y is 2
In particular, the string "functions" do not export.
public.X = 1
export X
public.f() =
X = 2
Y = $"$f"
# X = 1
# Y = 2
* Implementations.
** ValEnv no longer exists.
Exporting is defined explicitly for each section of code:
- function bodies
- sections
- conditionals
- foreach and friends.
Export operations are explicit.
The evaluator no longer calls add_exports after evaluating each expression.
There is no need for cancel-export operations.
Note that foreach is a simultaneous fold-map.
public.A = 0
public.B =
foreach(i => 1 2 3)
A = $(add $A, $i)
add($i, 1)
export
println($"A = $A, B = $B")
# Prints "A = 0, B = 2 3 4")