Yep, I did not try to handle sharedvars at all with my GC. I will eventuelly need to give them a type tag, but I deferred that to the next release :) Splitting polymorphic functions is something that has to be done too.
As for variadic +, I don't know : if we transform (+ a b c d) in (+ a (+ b (+ c d))) during the first phase of compilation, we obviously handle variadic +, but at the end (in the generated code), the ADD() primitives only handles + with 2 args, which I guess would be more efficient ? And, that way, we could translate (+ a 1 b 2) into (+ a (+ 3 b)), and (+) to 0, which will eventually have to be done.
How do you organize your directories for arc2c? In particular, where does Anarki go relative to arc2c? Do you overlap the git repositories? And then what directory do you start arc in? (I can't get the paths to work for the loads.)
I'm not sure I fully understand your question, but you are supposed to put all the arc2c files at the root level, where arc.sh lives, then load arc2c.sh and finally call (compile-file "foo.arc"). Tell me if I didn't answer your question or if you still get something wrong.
$ ls
arc2c/ arc-wiki/
$ cd arc-wiki/
$ cp -r ../arc2c/* .
$ ./arc.sh
Use (quit) to quit, (tl) to return here after an interrupt.
arc> (load "arc2c.arc")
nil
arc> (compile-file "t.arc")
<lots of stuff>
Yes, that's what I was looking for: where to put arc2c in the tree.
My next arc2c problems are a) gc.h is missing; do I need to download it somewhere? and b) ‘QUOTE_CONSTANTS’ undeclared - I can't figure out where it gets declared. I'm trying to compile simply "(+ 1 1)".
How do I push changes to the git? "git push" gives me "fatal: The remote end hung up unexpectedly". I set up a ssh public key. Do I need to get authorization from you guys? (I've never done a git push before, so assume I may be doing something stupid.)
Not sure for the case where (< pow 0), though. Just run the tests, but I think the tail-recursive function is at least as fast as the iterative one. Actually, in fine, iterative code is transformed into its tail-recursive equivalent : code involving for is transformed as a bunch of tail-recursive functions for example.
Macros have to be defined before they are used in a function, because they are expanded during the definition of the function.
Example :
(def hello () (blankpage (pr "Hello world")))
=> def is a macro, evaluated as (set hello (fn () (blankpage (pr "Hello world"))))
Once the function is "compiled", no macro expansion will ever happen. So, when you call 'hello, it's looking for a function named 'blankpage and cannot find it.
(mac blankpage body `(tag html (tag body ,@body)))
=> new macro saved
(def hello () (blankpage (pr "Hello world")))
=> def and blankpage are macros, expansion performed, evaluated as
=> (set hello (fn () (tag html (tag body (pr "Hello world")))))
=> tag is a macro, so another expansion has to be performed, etc.
Here, all macros are evaluated, only function calls are left in the compiled form. Thus, if you redefine 'blankpage or any other macro, don't forget to redefine all associated functions too.
But it does not apply to functions. They can be defined in any order.
That's quite interesting. After reading through your explanation it makes perfect sense why I am running into this problem. Thanks for the answer and for such a fast reply to my query.
If you implement your objects like hash tables (the way it is done in Lua, Javascript, Perl or -- secretly -- in Python), you can easily implement anything you need, including duck typing and inheritance : http://arclanguage.com/item?id=3155.
But not strong encapsulation, sorry. This can be done with closures however, if you really need it (but I don't think Arc is the right language if you want to constrain the developer at all).
You can also make any function doing dynamic dispatch based on the type of objects. For example, you can redefine the + function to perform a special operation when called with a foo object as a parameter, or behave the usual way in the other cases. That's a method-calling mechanism (even more powerful actually). Use any object representation you need (hash table, list, cons cell, integer, ...) and 'annotate, and you're done !