程序和映射在方案中的使用
我对Scheme很陌生,我正在慢慢找到解决它的方法。
我对程序和地图有一些疑问,希望能得到解答。
(map plus1 (list 1 2 3 4))
基本上会返回结果:
(2 3 4 5)
如果该过程将列表作为其唯一参数,那就没问题了。我的问题是我如何能够使用这样的过程,它在 Map 中接受 2 个参数?
(define plus(m list)
(+ m list))
预先感谢您的帮助和建议。
I am very new to Scheme and I am slowly finding my way around it.
I have some doubts on Procedures and Map which I hope could be answered.
(map plus1 (list 1 2 3 4))
will basically return me the result:
(2 3 4 5)
It is fine if the procedure takes in the list as its only parameter. My question is how am I able to use a procedure like such which takes in 2 parameters with Map?
(define plus(m list)
(+ m list))
Thanks in advance for help and advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许像这样?
(define (plus mn) (+ mn))
(map plus (list 1 2 3) (list 4 5 6))
; => (列表 5 7 9)
Maybe like this?
(define (plus m n) (+ m n))
(map plus (list 1 2 3) (list 4 5 6))
; => (list 5 7 9)
或
它允许您将
adder
函数重用于其他用途。or
Which allows you to reuse the
adder
function for other things as well.使用两个列表。看看会发生什么:
Use two lists. See what happens: