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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?