简体   繁体   English

scheme - 评估真假列表

[英]scheme - Evaluate true or false list

I have a true/false list (like this (#f #f #f #f #f #t)) and I want to loop through it, making an if statement and making appends. 我有一个真/假列表(像这样(#f #f #f #f #f #t)),我想循环遍历它,制作一个if语句并进行追加。

But my map/if iterator does not work as I expected 但我的map / if迭代器不能像我预期的那样工作

I`m trying this: 我试着这个:

(map (if (false? lst) "do this" "do that" ) lst)

In pseudo code I would have something like this 在伪代码中我会有类似的东西

for each value in lst
  if value
    "do that"
  else
    "do this"

Remember that map receives as parameters a list and a function that operates on each element. 请记住, map作为参数接收列表和对每个元素进行操作的函数 Try this: 尝试这个:

(map (lambda (e)
       (if (false? e)
           "do this"
           "do that"))
     lst)

For example, if we define lst as '(#f #f #f #f #f #t) the result is: 例如,如果我们将lst定义为'(#f #f #f #f #f #t) ,结果是:

'("do this" "do this" "do this" "do this" "do this" "do that")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM