将Mapcar和Lambda与两个
我有一个公式:(setq Formula1 (/ (* 0.046 (expt(* LenPath 78.0)(/ 1.0 2.0))) (expt SlopePath (/ 1.0 5.0))))
带有两个变量“LenPath”“SlopePath”
我有两个清单。列表中的每个项目代表
“LenPath”或“SlopePath”
例如,在我的第一个列表中:
((setq LenList '(2.1 4.0 6.8 10.012.0 16.0))
所以每个项目都是“LenPath”
(setq SlopeList '(5.5 7.8 9.3 12.015.4 17.7))
每个项目都是“SlopePath”
生成的新列表如下所示:
(setq NewList '(0.418 0.538 0.678 0.781 0.814 0.914))
如果只有一个变量,那么使用mapcar和lambda很容易做到这一点
然而,如果有两个列表同时用于一个公式,我会感到困惑
有什么想法吗?谢谢 你需要这样的东西吗?
(mapcar
(function
(lambda ( _length _slope )
(/ (* 0.046 (expt (* _length 78.0) 0.5)) (expt _slope 0.2))
)
)
LenList
SlopeList
)
我绝对建议你看看这个教程 谢谢李
这很有效。是的,我以前看过它,但我无法从中找出如何同时使用两个变量。但这是一个非常有用的教程-很好的工作。
感谢SmallFish,我发现很难编写一个教程来满足不同经验层次的开发人员的需求,同时保持教程的简短和有趣。
你现在明白我上面用的方法了吗? 也许这对mapcar+lambda有帮助:
列出几个简单的列表
(setq l1 '(2 3 4))
(setq l2 '(2 4 )
基本(mapcar)调用:
Add the atoms of the lists together
(setq nl1 (mapcar '+ l1 l2))
'(4 7 12)
Multpily the atoms of the lists
(setq nl2 (mapcar '* l1 l2))
'(4 12 32)
生成匿名函数(lambda)
:从两条短边的长度中找出下凸的长度
(setq fun (lambda (a b) (sqrt (+ (* a a) (* b b)))))
mapcar the (lambda) function to the lists
(setq nl3 (mapcar 'fun l1 l2))
'(2.82843 5 8.94427)
在(mapcar)调用中包括(lambda)函数
:将列表中的原子划分为实数
(setq nl4 (mapcar '(lambda (a b) (/ (float a) (float b))) l1 l2))
'(1.0 0.75 0.5)
HTH-David 很好的例子大卫,干得好 谢谢李
我需要简单的事情来符合我的想法
页:
[1]