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.

UCB

posted @   哎呦_不想学习哟~  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示