2014-02-17 90 views
0

我有一個真/假名單(像這樣(#f #f #f #f #f #t)),我想循環它,製作一個if語句並進行附加。scheme - 評估真假列表

但我的地圖/如果如我所料迭代器不工作

我真的想這樣:

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

在僞代碼,我可能有這樣的事情

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

回答

2

記住map接收作爲參數的列表和對每個元素進行操作的函數。試試這個:

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

例如,如果我們定義lst'(#f #f #f #f #f #t)結果是:

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