(mac >> body
`(let it ,(car body)
,(if (cdr body) `(>> ,@(cdr body))
'it)))
It works a little bit like CL's let* but is anaphoric and it's much easier to read. It's a pipeline: each expression is evaluated and it is bound to the result for the next expression to use. Example:
It's very convenient sometimes. Plus, since most of Arc's functions have their main argument at the end (thanks devteam!) it could be modified so that it appends "it" to every expression in the body. This depends on how it's used in the real world.
(def ablast (l)
(if (no (cdr l))
nil
(cons (car l) (ablast (cdr l)))))
(def replc (x y l)
(if (atom l) (if (is x l) y l)
(no l) nil
(is x (car l)) (cons y (replc x y (cdr l)))
(acons (car l)) (cons (replc x y (car l)) (replc x y (cdr l)))
(cons (car l) (replc x y (cdr l)))))
(mac imp body
(if (no body) nil
(replc 'it `(imp ,@(ablast body)) (last body))))
I translated into Arc a little program I wrote a few months ago to compare the distribution of characters in Qwerty vs. Dvorak by hands, fingers, etc. It currently outputs text; the next step of course is to output HTML.
Getting the program to work was a bitch as there doesn't seem to be any debugging support at all. Nevertheless, I'm extremely pleased with the language itself.
The utility at the beginning reflects the only serious issue I ran into: objs don't seem to be able refer to themselves. I had to write a new obj macro that binds the current object to 'this'.
Also, although it's not a serious problem, I'd love to be able to refer to obj fields with a simpler syntax, e.g. x.foo instead of (x 'foo). In particular, that quote before the field name is kind of a wart.
(def prime (n)
(if (~isa n 'int) nil
(< (= n (truncate n)) 2) nil
(is n 2) t
(multiple n 2) nil
(with (div 3
lim (truncate (sqrt n))
result t)
(while (and (or (~multiple n div)
(= result nil))
(< div lim))
(++ div 2))
result)))
You don't have to connect it. Copy the above into a file called 'fortune.arc' inside your Arc source code directory, then type the following from an Arc REPL:
(load "fortune.arc")
(asv)
The 'asv' function spawns the built-in web server, as shown in the blog example.
Sometimes the program fails with the error below, on clicking on the link. A blank webpage is shown. After F5 (refresh), all back to normal.
Looks to me, that the system call fails because 'fortune' returns -1.
date: 1202019843: No such file or directory
make-string: expects argument of type <non-negative exact integer>; given -1
=== context ===
subseq
memodate
srvlog
gs899
handle-request-thread
This same idea of having the "step" parameter maps nicely into subseq syntax in Python, as I noted in this thread: http://www.arclanguage.org/item?id=479