Arc Forumnew | comments | leaders | submit | pau's commentslogin
4 points by pau 6267 days ago | link | parent | on: Question on '() and nil in ac.scm

I don't think it is so easy. The problem is that it is not the contents of 'nil' that you should set to '(), but the symbol itself (which you quote):

  > (define nil '())
  > (eqv? '() 'nil)
  #f

-----

4 points by nlavine 6267 days ago | link

You're right, this wouldn't work with the current ac.scm. However, if we stop treating the symbol 'nil specially and just let it be a normal variable lookup, then I think everything will work.

The only hard bit, actually, will be making it output things using 'nil instead of '(), but making a fix like that, that's isolated in one small part of the program, seems like a small price to pay for making the main arc compiler sleeker and faster (oh, and the generated code, too).

-----

2 points by pau 6268 days ago | link | parent | on: A proposal for a module system...

I totally agree. I looked at the keyboard and I couldn't find anything else. '$' would have been even worse...

And I think you might have to hack the MzScheme reader really deeply to make it accept '|' as a conventional character, since it is used to be able to embed special characters into symbols...

-----

5 points by pau 6268 days ago | link | parent | on: A proposal for a module system...

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 6268 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 6268 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 6268 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 6266 days ago | link

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

-----

1 point by almkglor 6266 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 6268 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 6267 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 6267 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 6267 days ago | link

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

-----

2 points by pau 6268 days ago | link | parent | on: A proposal for a module system...

In Python, if you do

  import string
you still have to access symbols within string using the prefix, and I imagined Arc's (use ...) doing the same.

Arc should register in some way that the module was loaded, since if two other modules do (use 'x), then they have to reference the same table. This is, afaik, what Python does. So 'locally' (within the current module), you access the symbol table of another package with the name you want (if you don't supply one, then it's the same as in the file), but the system remembers who is who globally.

Each source file is a module, yes.

To be able to load a list of modules, like

  (map use '(string regex parser))
I think that it is important that the first parameter to the use function be a symbol, e.g. (use 'string) instead of (use string).

I like your suggestion (specially changing the names to avoid clashes)... Yes, it could be a nice way to avoid the prefix... ;)

-----

2 points by pau 6268 days ago | link | parent | on: A proposal for a module system...

I probably didn't make myself clear... It's like in Python:

  from long-named-module import foo1, foo2, foo3
would be

  (use* '(foo1 foo2 foo3) 'long-named-module)
With this, you use (foo1 ...), etc. without the module name.

-----

1 point by almkglor 6268 days ago | link

Sorry, I've been studiously avoiding Python. Can you give better examples, such as a module being used by another module?

-----

3 points by pau 6268 days ago | link

File 'a.arc':

  (set spam 1)
  (def myfun (x) (prn x))
File 'b.arc':

  ;; Uses 'a'
  (use 'a)
  (a@myfun "hi!")
File 'c.arc':

  ;; Uses all in 'a'
  (use* 'a)
  (myfun "hy!")
File 'd.arc':

  ;; Use 'a' as 'z'
  (useas 'z 'a)
  (z@myfun "ho!")
In Arc's repl:

  arc> (use 'a)
  t
  arc> a@spam
  1
  arc> (set a@spam 5)
  5
  arc> (use 'a)
  t
  arc> a@spam
  5
  arc> (use 'd)
  ho!
  t
  arc> (use 'b)
  hi!
  t

-----

1 point by pau 6283 days ago | link | parent | on: Arc Repo

Also excellent! I'm following it through RSS...

-----

1 point by akkartik 6283 days ago | link

Whoa, how'd ya do that?

-----

3 points by nex3 6282 days ago | link

http://git.nex-3.com/?p=arc-wiki.git;a=summary has both Atom and RSS feeds.

-----

1 point by akkartik 6282 days ago | link

Oh, so in general there's a mapping from git://hostname to git.hostname? I didn't know that.

-----

2 points by nex3 6282 days ago | link

I'm not sure how general it is... just how I chose to set up my server.

Edit: Speaking of nice URLs, you can now get at the browser through http://git.nex-3.com/arc-wiki.git.

-----

3 points by pau 6283 days ago | link | parent | on: Arc Repo

Excellent! I was about to do this myself... I also saw the SVN put by ambition, but git is just nicer... ;)

-----