在条件中使用定义

问题描述 投票:1回答:1

在计划中,过程的一般形式是:

(定义({name} {parameters >>}){body})]

其中{body

}接受一个表达式序列,允许这种过程:
> (define (f) (define x 1) (define y 1) (define z 1) (+ x y z))
> (f)
3

同样,condition

的一般形式是:

(cond({predicate

} {expression})({predicate} {expression})…({predicate} {expression] >}))

其中每个子句中的<< [表达式

}接受一个表达式序列,从而允许这种条件:
> (cond (#t 1 2 3) (#t 4)) 3

但是为什么不能在过程的条件表达式序列中使用define

> (cond (#t (define x 1) (define y 1) (define z 1) (+ x y z)) (#t 4)) ERROR on line 1: unexpected define: (define x 1)

Note。

—我正在MacOS 10.15.2上使用Chibi-Scheme 0.8.0实现。
在Scheme中,过程的一般形式是:(define({name} {parameters}){body}),其中{body}接受一个表达式序列,允许这种过程:>(define(f)(定义x 1)...
scheme naming conditional-operator
1个回答
0
投票
正如@Barmar指出的那样,

definitions

不是expressions
© www.soinside.com 2019 - 2024. All rights reserved.