Arc Forumnew | comments | leaders | submitlogin
5 points by pau 6156 days ago | link | parent

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 6156 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 6156 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 6156 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 6155 days ago | link

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

-----

1 point by almkglor 6155 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 6156 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 6156 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 6156 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 6155 days ago | link

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

-----