[Omake] test/object/Test14
Jason Hickey
jyh at cs.caltech.edu
Wed Aug 1 11:11:45 PDT 2007
On Aug 1, 2007, at 9:55 AM, Aleksey Nogin wrote:
>> In any case, all I am arguing for now is that hoisting-exports
>> should be as simple as possible--no complicated logic.
>
> The basic semantic problem is IMO unavoidable, unless we either:
> - introduce strong typing capable of knowing all the object fields
> statically
> - change the "export" syntax to force the user to disambiguate for us
I guess I didn't really understand the issue. I had been assuming
that function parameters were private, but I see this is not yet the
case in 0.9.8.x.
Anyway, the new logic is complicated, and expensive too... You seem
to be arguing that, in the following, the "export map" should refer
to the function parameter, not the field of A. Is that right?
> Test(map) =
> A.foreach(key)
> map = $(map.add $(key), new)
> export map
I'm not sure I understand the argument you are making.
The issue is in mixing higher-order functions and methods: when a
function is called, is it called in the context of its caller, or in
its static context? So far, we have chosen that it is applied in the
context of the caller. Seems sensible enough.
If that is the case, then the standard (simple) semantics should be
used.
- A variable is either private, this, or public (0.9.8.x also has
a class called global).
- The export performs a binding into the appropriate place (one
of the three namespaces).
In the code above, the variable map belongs to the "this" namespace.
That means it gets added as an object field to A. Write the
namespace explicitly, and it should be easier to see.
Test(this.map) =
A.foreach(this.key) =>
this.map = $(this.map.add $(this.key), new)
export this.map
Note: function parameters are becoming private (they should have been
private already).
If you want some other semantics, I think what you really mean is
that the function
key =>
map = $(map.add $(key), new)
export map
should be evaluated in the context of Test, not in the context of A.
That is, the function should be evaluated in its static context.
That sort of makes sense, but it doesn't work well when functions
escape their static context. Imagine this:
TestFun(map) =
fun(key)
map = $(map.add $(key), new)
export map
Test(map) =
f = $(TestFun $(map))
A.foreach($f)
new = $(map.find key)
# IMHO, our map should not be affected.
Jason
--
Jason Hickey http://www.cs.caltech.edu/~jyh
Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257
More information about the OMake-Devel
mailing list