Since you are familiar with the algol family language (python) I can tell you the lisp family has different syntax:
fun(a, b, c)
Is written like this:
(fun a b c)
Thus the source of your error is that the comma and parentheses are interpreted different in lisp languages.
What is the error message referring to?
In lisp family you can actually have code as data by adding characters that makes the code literals instead. So '(fun a b c)
becomes (fun a b c)
as a data structure after evaluation since you have a '
in front of it and it works like if you had code(a,b,c)
in python and surrounded it with quotes like 'code(a,b,c)'
. Python would evaluate it as string and not code right? Well lisp languages does the same with literal data structures. There are 2 additional ones. quasiquote
`
and unquote
,
. Looking familiar doesn't it? Well as an assimilation the normal quote
is like single quoted strings where the string is exactly literal while quasiquote
is like double quoted ones and the unquote is for interpolation for code so that what remains in the structure is the result of those expressions. Here is an example:
`(a b ,(+ 3 4)))
; ==> (a b 7)
Now in lisp languages the reader usually converts this at read time so that the code that gets interpreted never actually see the '
, `
, or ,
. Scheme standard doesn't say what it should be named so it's implementation defined, however most languages use these:
''`(a b ,(+ 3 4))
; ==> (quote (quasiquote (a b (unquote (+ 3 4)))))
Only the outermost quote is evaluated so in this case the other quotes you see in the result is data and not part of code. An implementation is free to show the short form when presenting a data structure so that:
'(quote (unquote quote))
; ==> ',quote
; ==> (quote (unquote quote))
It's actually the same value but rather how they display it is a variation if you were to take the car
of it it would present the symbol quote
since it really is the second structure that is the real value.
In your code the expression (a, (- b 1))
is read in as (a (unqote (- b 1)))
and after the successful subtraction the function unquote
is to be applied, then the function a
is to be applied to it's result. Neither would work but since the arguments must be evaluated before application the order is set so Scheme will complain about unquote
first, then a
later if you would remove the comma.