On Thu, Jan 9, 2014 at 2:55 PM, Tony Duell <ard at p850ug1.demon.co.uk> wrote:
Head followed by parameters. f(a, b, c) or in
Lisp (f a b c)
YEs, but from what I rememeber there are no infix operators in LISP. So
even things like addition are writen (+ 2 5) rather than 2 + 5
Lisp doesn't really have "operators" in the sense of Algol-ish languages;
the
closest analogue are the special operators which are primitive forms. But
whereas '+' signifying addition is an operator in many languages, in Lisp
it's
(often) just a function. E.g., (apply #'+ (list 1 2 3)) yields 6 in a
Lisp-2.
But depending on the dialect, there are a few things that apply in an
infix-ish
way. Consider the '.' token in an improper list; one can sometimes think
of this as an infix stand-in for a CONS call. In Common Lisp:
CL-USER> '(a . (b . (c . nil)))
(A B C)
CL-USER> (cons 'a (cons 'b (cons 'c nil)))
(A B C)
CL-USER>
Or in Scheme:
guile> '(1 . (2 . (3 . ())))
(1 2 3)
guile>
In Common Lisp, the LOOP macro defines a language with lots of infix
operators:
CL-USER> (loop for (k . v) in '((1 . a) (2 . b) (3 . c))
do (format t "~A maps to ~A~%" k v))
1 maps to A
2 maps to B
3 maps to C
NIL
CL-USER>
Etc.
Further, if you *really* wanted to in Common Lisp, you could change
the read tables and redefine the syntax to essentially anything you
wanted, including an infix language. :-)
So while Lisp is *mostly* written using prefix notation, there are escape
hatches.
- Dan C.