Arc Forumnew | comments | leaders | submitlogin
Summary of Arc differences from Common Lisp?
4 points by maxdeviant 3686 days ago | 6 comments
I am currently taking a university class which deals heavily with functional programming, which we have been learning using Common Lisp.

I was discussing Arc with my professor, and he is curious to know how the dialect differs from CL.

I read through "Arc at 3 Weeks" (http://paulgraham.com/arcll1.html) and found it very insightful, but I was wondering if there were any key differences worth noting between the two?



5 points by malisper 3683 days ago | link

I just want to start off by saying that you may want to show your professor Clamp[0]. It is a project I have been working on and my goal is to implement as many features from Arc as possible in Common Lisp. Most of the references are to code for Clamp.

Differences between Arc and Common Lisp.

Lisp-1 vs Lisp-2: Arc is what's know as a Lisp-1. That means that procedures are really just procedure objects stored in regular variables (ie "len" is just a variable in Arc, whose value is a procedure that can calculate the length of a sequence). Common Lisp on the other hand is a Lisp-2. This means that it is possible to have a procedure "len" (which can calculate the length of a sequence), and a variable "len" (which may be the length of a particular sequence), without any conflicts even though they are both named "len". Some people prefer a Lisp-1 because it makes code simpler and shorter (you never have to use something analogous to Common Lisp's funcall), and some people prefer a Lisp-2 because then don't have to deal with conflicts between procedures and variables having the same name.

Special Syntax: Arc provides a special kind of syntax called ssyntax, short for special syntax. Each ssyntax provides a shorter way for writing a common pattern. For example a&b is short for (andf a b), a:b is short for (compose a b), a.b is short for (a b), and a!b is short for (a 'b). The last two are extremely useful for accessing into data structures which I explain more in the next section. I just want to point out that it is possible to write a version of ssyntax in Common Lisp[1][2][3]. There are some issues that come up because Common Lisp is a Lisp-2.

Data Structure Access: In Arc, you can use data structures as procedures. Calling a list with an argument will get that place in the list [ie (x 5) will get the element at index 5 in x.]. Note that this is why the shorthand a.b and a!b are so useful. Anarki takes things a step further by allowing a programmer to define how to coerce types to other types and therefore allows one how to define what happens when you call an arbitrary object as a procedure. Common Lisp provides nothing like any of this.

Procedure Arguments: There are some differences in how procedures are defined and called between Common Lisp and Arc. Arc provides an easy way to destructure and argument. For example it is possible to a procedure to get the first element of a list as just (def car ((a . b)) a). It is possible to implement this feature in Common Lisp[4][5]. There are some slight differences with syntax to define a procedure that has optional arguments or rest arguments. Another difference between the two is that Common Lisp provides something called "keyword arguments". Keyword arguments provide a way of having arbitrary ordered optional arguments. For example I wrote a procedure "group"[6], which does roughly the same thing as both pair and tuple in Arc. There are some versions of Arc that provide keyword arguments (Anarki is not one of them).

Reader Macros: Arc provides a shorthand for lambda functions of one argument (Anarki has extended this feature to provide any number of arguments). It is possible to write [+ _ 5] instead of writing out (fn (_) (+ _ 5)). Common Lisp provides something much more general called "reader macros". Reader macros allow a programmer to design new syntax. While I won't go in depth about reader macros, they allow a programmer to create new syntax within Common Lisp. Using brackets as a shorthand for lambda functions is possible to implement with reader macros.

Module System: Most versions of Arc do not provide a module system.

Debugger: One of the most important differences between the two is Arc's lack of a debugger. AFAIK, the only way to debug Arc code is to include print statements throughout your code (using print statements is actually a really effective way to debug code), and there are ways of creating more advanced debugging techniques through the use of macros. Common Lisp provides a full debugger along with something called "restarts"[7]. The Common Lisp restart system is extremely useful, although it should be possible to implement something similar in Arc.

IDE: Arc does not have any sort of IDE, whereas Common Lisp has Emacs/Slime. I wrote about some of the features Slime provides here[8].

[0] https://github.com/malisper/Clamp

[1] https://github.com/malisper/Clamp/blob/master/tests/ssyntax-...

[2] https://github.com/malisper/Clamp/blob/master/experimental/s...

[3] https://github.com/malisper/Clamp/blob/master/experimental/s...

[4] https://github.com/malisper/Clamp/blob/master/tests/destruct...

[5] https://github.com/malisper/Clamp/blob/master/experimental/d...

[6] https://github.com/malisper/Clamp/blob/master/src/list.lisp

[7] http://en.wikibooks.org/wiki/Common_Lisp/Advanced_topics/Con...

[8] https://news.ycombinator.com/item?id=8474161

-----

2 points by maxdeviant 3680 days ago | link

Thank you for your very thorough reply!

This is exactly the kind of information I have been looking for and that I think he would be interested in.

Clamp sounds very interesting as well, especially since we just covered macros in class last week.

-----

3 points by Pauan 3685 days ago | link

One big difference is that Arc is very minimal, while Common Lisp has lots of libraries and a large standard library. In Arc, you'll end up writing a lot of stuff yourself. But because Arc tends to be more concise than Common Lisp, this can be fun rather than frustrating.

In large part because Arc is so minimal, it only really has two compound data structures: cons cells and mutable key/value dictionaries.

With a bit of effort, it's possible to use Racket libraries and Racket data structures. It's easier to do this in Arc/Nu and Anarki, compared to Arc 3.1.

Arc also does not have a module system, so name collisions are a very real possibility. If your code base is small this isn't a problem, but it does make it a bit trickier to use libraries written by other people.

Another difference is that Arc takes after Scheme, so it has tail-call optimization and full first-class continuations. Recursion is quite common.

Like Scheme, Arc has a single namespace for both functions and variables, unlike Common Lisp which has separate namespaces.

Arc intentionally makes no promises of backwards-compatibility: new versions of Arc might be radically different and completely break your code. Common Lisp, on the other hand, tends to be very stable, and cares a lot about backwards-compat.

Essentially, you can think of Arc as being very similar to Scheme, but much more minimal and concise, and with Common Lisp style unhygienic macros.

-----

2 points by akkartik 3686 days ago | link

My one-sentence summary of arc: minimalist common-lisp-flavored lisp-1 atop scheme. It takes quasiquoting and some other more dynamic design choices from common lisp and overlays them atop the more modern Racket runtime with as little code as possible. Other than that it's lots of tiny ergonomic conveniences. Maybe you should read/show him the tutorial next: http://ycombinator.com/arc/tut.txt. And arc.arc is a pretty fun read: https://github.com/arclanguage/anarki/blob/3fc14d16e9/arc.ar.... What really got me into arc was writing programs in one split window with the friggin compiler for my language in the other.

-----

2 points by maxdeviant 3686 days ago | link

I did have a short look at the tutorial, but I had a bit of a hard time diffing it mentally, as I am still fairly new to Lisp. But I will definitely point him in that direction if he is interested in having more than a cursory glance.

Also, are most "Arcers" using Anarki?

-----

1 point by akkartik 3686 days ago | link

It's hard to say. I think most people might be discovering arc and never coming to the forums or our community frontpage: http://arclanguage.github.io. They're probably still using arc 3.1.

I prefer anarki because Arc 3.1 has been around for five years without updates, and we've found some serious bugs in it, and also made some serious improvements (tests, online help).

-----