Hacker News new | past | comments | ask | show | jobs | submit login
Cheat sheet for Lisp dialects (Common Lisp, Scheme, Clojure, Emacs Lisp) (wikidot.com)
74 points by alrex021 on April 20, 2010 | hide | past | favorite | 11 comments



It's Common Lisp and EMACS centric. Doesn't include native constructs from other languages, e.g. vector? is a fundamental type predicate in Scheme and Clojure but it's left out because it has no analog in CL. The basis for comparison is always the set of functions available in CL.

And of course, there is the assumption that you're programming in EMACS right from the second row. EMACS is not actually obligatory for programming. Maybe I'm an old man with carpal tunnel and have to use vi to avoid aggravating it. Some readers could be tiny toddlers still suckling on Eclipse or something.

I like the Clojure comment "cons cannot make a cons cell." Of course, Clojure is revolutionary in being a Lisp without lists so there are no cons cells.

There are some mistakes. dotimes does exist in Clojure and works fairly similarly. Clojure's loop is recursive by nature like Scheme and CL's loop example shows none of its horrible ugly glory. Clojure has lazy stream evaluation just like Scheme's built in but is listed without it. Scheme is listed with an optional arguments idea that is not standard Scheme.

Don't get me wrong; it's mostly right but I'm still finding more errors

Overall, I like it.

It needs to be a wiki, though, so non-CL'ers can fix the errors for their dialects.


vector? is a fundamental type predicate in Scheme and Clojure but it's left out because it has no analog in CL.

Uh, (typep foo 'vector)?


I think it's just incomplete. Coming from a CL perspective I see many problems. For example:

* missing equalp

* very non-idiomatic loop


Given the audience here, it would be super cool to add Arc in the fifth column for comparison.


I'll get it started here:

  =============arc (2008)=============
  version used        Arc 3.1
  version             
  repl                mzscheme -f as.scm
                      arc.sh
                      M-x run-arc
  shebang
  cell types          
  case sensitive      yes
  argument            whitespace
    separator
  falsehoods          nil ()
  true, is true       t, yes
    symbol?
  nil, is () null?,   nil
    is () symbol?
  type-of             type
  type predicates     (is (type x) 'int)
                      (is (type x) 'sym)
                      etc.
  set property        none
  get property        none
  remove              none
    property
  comment             (+ 1 1) ; adding
  ============ten primitives==========
  atom (or list?)     atom
  quote               quote
  eq                  is
  car                 car
  cdr                 cdr
  cons                cons
  cond                (if (> x 0)  1
                          (is x 0) 0
                                  -1)  
  lambda              (fn (x) (* x x))
                      [* _ _]
  label               =
  apply               ((fn (x) (* x x) 2)
                      ([* _ _] 2)
  =============arithmetic=============
  ==============strings===============
  ==========execution control=========
  =========functions and scope========
  ==============lists=================
  list literal        '(1 2 3)
  pair literal        '(1 2)
  (car '())           nil
  (cdr '())           nil
  (eval '())          nil
  list functions      list alist len append rev
  nth                 ('(0 1 2 3) 3)
  last butlast        (last l)
                      (firstn (- (length l) 1) l)
  sort                (sort < '(3 2 1 0))
  assoc               (assoc 3 '((1 2) (3 4)))
  getf                none
  map                 (map [* _ _] '(1 2 3))
  filter              (keep [* _ _] '(1 2 3))
  reduce              (reduce + '(1 2 3))
  push and pop        (= x '(1 2 3))
                      (push 4 x)
                      (pop x) 
  ============sequences===============
  predicate           alist
  ===========other containers=========
  =========i/o and environment========
  format string       (pr "Spain" 7 ": " 13.7)
    to stdout
  external            (system "ls /etc")
    command
  open file           (= in (infile "/etc/passwd"))
  read line           (readline in)
  close file          (close in)
  =======libraries and namespaces=====
  loading a file      (load "a.arc")
  ============compilation=============
  ==============macros================
  backquote and       (def op +)
    comma             (eval `(,op 1 1))

  defmacro            (mac rpn (arg1 arg2 op)
                        (list op arg1 arg2))

  defmacro w/         (mac rpn (arg1 arg2 op)
    backquote           `(,op arg1 arg2))

  recursive           (macex '(rpn 1 2 +))
    macroexpand
  single              (macex1 '(rpn 1 2 +))
    macroexpand
  splice quote        (mac add (args)
                        `(+ ,@args))
  hygenic?            no
  local values        using gensym
  ==============classes===============
  =============concurrency============
  create thread       (thread)
  ==========java interoperation=======
  version used        jarc
    on jvm


Well, it is useful but not universal, and may be a bit confusing in a few places. For example, the "repl" entry for Common Lisp is M-x slime which of course is Emacs-specific (and M-x shell for Clojure is setup-specific on top of that).

There are a few items missing (eg regex substitution in Emacs Lisp). But in general, a nice resource, thanks!


One minor point: you can use slime to get a clojure repl.


And I found it very easy to set up. However, I needed to use a different .emacs for clojure slime, so I just made a shell script 'ecj' to do the right thing.


And I am about to do a similar thing for clozure.


One thing: The 2^28-1 size limit on integers in emacs lisp also impacts max file size. You can't load a file larger than 256MB on a 32-bit version of emacs. However, a 64-bit emacs will support larger integers and file sizes.


I think this table actually highlights the true core of Lisp — the only entry that is the same for all 4 Lisps is:

quote




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: