stream - 执行流程序时违反合同 - 方案
问题描述
我正在实现一个过程,它接受一个数字 n 和一个流,并返回一个新流,其中包含流中的 n 个第一个元素
(define (stream-take n stream)
(cond ((stream-null? stream)
(the-empty-stream))
((= n 0) ('()))
(else
(cons (car stream)
(stream-take (- n 1)
(force (cdr stream))
)))))
(stream-take 10 nats)
此代码给出错误消息
=: contract violation
expected: number?
given: (2 . #<promise>)
argument position: 1st
other arguments...:
解决方案
('()))
不是流。它应该返回
(the-empty-stream)
反而。
PS:
另请注意,我已经编辑了您的原始帖子并在最后一个条款中添加了(else ...)。
('()))
表示调用函数'()
,这肯定不是函数。
推荐阅读
- java - 如何通过 glassfish 服务器上的容器管理身份验证实现“首次登录时更改密码”
- python - 如何改进我的 python openCV 视频流?
- r - 为要在数据表的搜索栏中使用的特定值指定不同的名称
- sql - 获取在 2 列中具有相同值但在第 3 列中具有不同值的记录
- c# - .NET DateTime 在序列化时添加本地时间偏移量?
- java - 如何在房间持久性中返回数据的行数
- python - QuantLib-Python:使用 VanillaSwap 仪器的 quantlib Schedule 解决非正时间前向误差
- r - 计算 df2 的几列之间的平均值,该平均值可以根据 df1 的变量 `var1` 变化,并将该值添加到 df1 中的新变量
- pandas - 基于列中的值的示例 Pandas 数据框
- c# - 尝试从 VS 表单应用程序资源加载字体文件时出错