1

ここでのスキームは初めてです。スキーム関数をコンパイルしようとしていますrange。それは非常に簡単です -とリストを取りstart、すべての要素 = stepAmt + curStep である新しいリストを作成します。stepstopL

例: (範囲 '(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))))))))

エラーが発生します

不正な特殊形式: (define helper2 (start stepamt stop curstep newlist) (if ... ... ...))

意味がわかりません。論理と括弧を再確認しましたが、わかりません。

これは、その関数を呼び出す関数です。

(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 '()))
)

)

どんな指針も素晴らしいでしょう。タイプミスなのか論理エラーなのかわかりません。ありがとうございました!

4

3 に答える 3

4

あなたはする必要はありません

(define helper2 (some arguments go here)
   definition goes here)

しかし

(define (helper2 some arguments go here)
  definition goes here)

これを覚えておく方法は、その後に続くdefineことは、定義している関数への呼び出しのように見えるということです。「次のような呼び出しに対処する方法は次の(helper2 some arguments go here)とおりです: ...」

于 2012-07-09T01:06:49.780 に答える
3

括弧を入れた場所を注意深く見てください。

(define helper2(start stepAmt stop curStep newList) ...

(define (example L) ...
于 2012-07-09T01:06:22.147 に答える
2

DrRacket を使用していますか? これは機能します:

#lang racket

(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))))))

(define (concat l elm)
  (append l (list elm)))

(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 '())
))
于 2012-07-09T03:29:37.317 に答える