Arc Forumnew | comments | leaders | submitlogin
About namespace (again..)
2 points by d0m 4831 days ago | 1 comment
Don't we already have the basic functionality to include namespaces in arc?

I'll just use the intersperse example from another thread.

  (= string (obj join string:intersperse))

  (string!join "," (list "a" "b")) -> "a,b"

  (let join string!join
    (join "," '(1 2 3))) -> "1,2,3"
Of course, a couple of useful macro could be used such as:

string/join instead of string!join to have better validation and errors messages.

and maybe a using macro which could be useful to load/define names.

As for the privacy, a simple convention such as: _private_fn could make the job.

----

So, I know this is pretty naive but I was wondering what was the arguments against that solution?

Thanks



2 points by rocketnia 4831 days ago | link

The most immediate concern is that you can't use macros that way. Lathe's[1] module system overcomes this by implementing namespaces as table-backed macros. However, for that to work it needs to store the namespace macros themselves as global variables, and you still need to refer to every utility using "name-of-the-namespace.name-of-the-utility" or the like. This is almost enough, IMO.

Recently I've been wondering whether there's something we can do to have unqualified imports in Arc (so we can just say "name-of-the-utility"). Essentially it would mean replacing the environment with another environment with different bindings (or different rules for looking up bindings), not just different values; that way we don't overwrite the variables from our existing environment and mess things up, and we get library hackability since the new bindings can be intentionally modified.

Technically we may be able to replace bindings in the environment rather than replacing the whole thing. I don't know which way is better.

Is Racket's environment mutable in the right ways for this? If not, aw's ar[2] can still do it, since it represents the Arc environment as a table. Penknife[3] represents it in the same sort of way, specifically motivated by this namespace strategy (but I'm not to that point yet).

[1] https://github.com/rocketnia/lathe

[2] https://github.com/awwx/ar

[3] https://github.com/rocketnia/penknife

-----