scheme - 方案:在这种情况下需要的变量
问题描述
我使用 mit-scheme 编译器来学习 Scheme。
我编写的程序必须通过 Vieta 定理计算方程根。
(define (roots p q x-begin x-end)
(let ((x1 0.0) (x2 0.0))
(set! (x1 x-begin)) ; Error here Variable required in this context: (x1 x-begin)
(set! (x2 x-begin))
; ...
)
)
我猜这个错误与 Scheme 中的静态范围有关。我做错了什么?
PS对不起我的英语。
解决方案
我不确定您打算如何计算根,但我可以提供一些有关 Scheme 语法的建议,这是不正确的:
(set! (x1 x-begin))
它应该是:
(set! x1 x-begin)
通常,set!
应尽可能避免使用:在 Scheme 中,我们非常努力地编写遵循函数式编程范式的程序,其中包括不重新分配变量。
推荐阅读
- wpf - 如何在 XAML 中创建模型并为其赋值
- sql - Nested INNER JOIN within LEFT JOIN in SAS
- java - Spring jdbcTemplate TNS:no appropriate service handler found
- javascript - 从生成的引导程序下拉菜单中查找下拉项
- reactjs - Why is there no error when requesting interface data?
- xamarin - Remove underline from Entry Control in Xamarin Forms
- azure - Executing code in azure example getting error as node already exists
- javascript - 箭头函数在反应组件中变成“普通”函数表达式
- android - why can't i run my app? why is it showing the message below?
- mongodb - MogoDB aggregate with $count and $lookup expected performance