scheme_语法备忘
1.list quote quasiquote
The list procedure takes in an arbitrary amount of arguments. Because it is a procedure, all operands are evaluated when list is called. A list is constructed with the values of these operands and is returned
scm> (define x 2) scm> (define y 3)
scm> (list 1 x 3) (1 2 3)
The quote special form takes in a single operand. It returns this operand exactly as is, without evaluating it. Note that this special form can be used to return any value, not just a list.
(quote (1 x 3)) (1 x 3) scm> '(1 x 3) ; Equivalent to the previous quote expression (1 x 3) scm> '(+ x y) (+ x y)
Similarly, a quasiquote, denoted with a backtick symbol, returns an expression without evaluating it. However, parts of that expression can be unquoted, denoted using a comma, and those unquoted parts are evaluated.
scm> `(+ x y) ;Quasiquotation (+ x y) scm> `(+ ,x y) ; Unquoted with a comma (+ 2 y) scm> `(+ ,x ,y) (+ 2 3)
2.=, eq?, equal?
• = can only be used for comparing numbers.
• eq? behaves like == in Python for comparing two non-pairs (numbers, booleans, etc.). Otherwise, eq? behaves like is in Python.
• equal? compares pairs by determining if their cars are equal? and their cdrs are equal?(that is, they have the same contents). Otherwise, equal? behaves like eq?.
The First Commandment (final version)
When recurring on a list of atoms, lat, ask two questions about it: (null? lat) and else.
When recurring on a number, n, ask two questions about it: (zero ? n) and else.
When recurring on a list of S-expressions, l, ask three question about it: (null? l), (atom? (car l)), and else.

浙公网安备 33010602011771号