Arc Forumnew | comments | leaders | submit | mascarenhas's commentslogin
8 points by mascarenhas 6159 days ago | link | parent | on: A proposal for a module system...

What is the problem with making packages be hashtables? Then you could use foo!bar to get function bar of package foo. Like this:

(use foo) (foo!bar 1 2 3)

With renaming:

(use foo as f) (f!bar 1 2 3)

I don't think Python-like importing into the global namespace is a good idea for a system where you are supposed to be able to change things in the REPL. Once you copy a module's function to your environment you aren't able to reload the module to change the function. This also means you need a module registry, so you don't load two copies of the same module.

-----

5 points by pau 6159 days ago | link

There is no problem with that, in fact I like it... ;) But as almkglor says, this doesn't play nicely with macros...

So what you say is to simplify it to a function 'use' that creates a table of symbols? How do you solve the references within modules? I don't see that, but otherwise it's very good. I would even remove the 'as', and make it a simple optional parameter:

  (use 'foo 'f)
  (f!bar 1 2 3)
Or maybe what (use ...) can do is simply return the table:

  (set f (use "foo"))
  (f!bar 1 2 3)

-----

5 points by almkglor 6159 days ago | link

> How do you solve the references within modules?

Easy: redefine "def" from within a 'use form (possibly using kennytilton's faux special globals) such that it keeps a table of defined functions (which is what you intend to do anyway). Replace all locals with (uniq)'ed names (in case someone uses uses a function name as a local - (def foo () nil) (def bar (foo) (foo))) ). Then for each expression in the file, replace all symbols (outside of quote-forms) that match a key in the table to references to the table itself.

-----

2 points by pau 6159 days ago | link

I have to start hacking this, so that the problems become apparent. But your solution seems about right...

-----

2 points by almkglor 6159 days ago | link

The hard part is the replacing of local variables with (uniq)'ed symbols. But I think local variables should be replaced anyway, because otherwise macros will override local variables with the same name.

-----

1 point by binx 6158 days ago | link

What if a "def" form is the result of macro expansion?

-----

1 point by almkglor 6157 days ago | link

What about it? Redefine "def", right? The def that gets referenced is still the same "def" you specially defined.

-----

1 point by bogomipz 6159 days ago | link

Doesn't that mean you have to do an assignment in the normal case as well?

  (= foo (use 'foo))

-----

3 points by bramsundar 6159 days ago | link

I don't think so. Couldn't you just have use's macroexpansion add a global variable named foo?

-----

2 points by bogomipz 6158 days ago | link

Yes, I thought of that after I wrote the comment. Avoiding repetitions like this is exactly what macros are for. I guess I'm not used to thinking in lisp yet.

pau wants 'use to be a function, though, so there would have to be a separate macro, or the other way around, or something.

-----

2 points by almkglor 6158 days ago | link

  (def function-that-assigns-one-to-a-global-symbol-of-your-choice (s)
    (eval `(= ,s 1)))

-----

1 point by mascarenhas 6169 days ago | link | parent | on: nifty :

I don't have an arc prompt to try this right now, but wouldn't (rmeol:system:string "echo" "hi") do the same? If this is too verbose you can do (def ssystem system:string), I think.

-----

2 points by CatDancer 6169 days ago | link

Not quite: you need tostring to capture the output of system (which is sent to stdout, not returned as a string). tostring is macro, so you can't compose it using :.

If I thought of a shorter name than "rmeol/ssystem" that I would still understand to mean "concatenate strings together, pass to system, capture the output, and remove the trailing newline", I would use it instead of "rmeol:ssystem". If "rmeol/ssystem" is the best I can come up with, then hey, I can save myself a function def and use "rmeol:ssystem". :-)

-----


Err, just to let you know that define-syntax (usually with its friend, syntax-rules) is the standard Scheme macro system, and while it is quite elegant I would certainly not call it simple, specially when compared with Lisp/Arc macros.

-----

1 point by chri1753 6170 days ago | link

SRFI-72 is an alternative and perhaps superior system to R6RS syntax-case and the forms of syntax-case which preceded it.

-----


Well, indexing will most certainly break, but making an encoding agnostic reader/writer is easy, I hope PG does that when/if Arc goes standalone.

-----

1 point by nex3 6177 days ago | link

I'm sure it'll be agnostic, if by "agnostic" you mean that it just reads in strings as a sequence of bytes. It would be easier to do that than to check for non-ASCII characters and handle them specially.

-----