此處新方案。我試圖編譯一個方案功能,range
。這很簡單 - 它需要一個start
,step
和stop
列表L
並創建一個新的列表,其中每個元素= stepAmt + curStep。無法編譯方案功能
例如:(範圍 '(0 2 7))=>(0 2 4 6),(範圍'(2 2 0))=>()
當我試圖編譯
(define (helper2(start stepAmt stop curStep newList)
(if (> start stop)
'()
(if (> (+ stepAmt curStep) stop)
newList
(helper2 (start stepAmt stop (+ stepAmt curStep) (concat newList (+stepAmt curStep))))))))
我得到的錯誤
病態的特殊形式:(定義helper2(開始stepamt停止curstep newlist)(如果......))
我不確定這是什麼意思。我已經仔細檢查了我的邏輯和括號,並且無法弄清楚。
這是將調用該函數的功能:
(define (example L)
(let (
(start (car L))
(curStep (car (cdr L)))
(step (car (cdr L)))
(stop (car (cdr (cdr L))))
)
(helper2 (start step stop curStep '()))
)
)
任何指針將是巨大的。我不確定這是錯誤還是邏輯錯誤。謝謝!
嗨@iaacp。在示例函數中使用(helper2 start step stop curStep'()並在helper2中修復類似的問題。在Scheme中不允許插入額外的括號。(start step ...)中的括號表示:調用由請注意,Rajesh給出的解決方案沒有這樣的括號。 – soegaard 2012-07-09 07:32:19
如果你有第二個問題,請把它作爲一個單獨的問題發佈。 – Marcin 2012-07-09 20:10:59