racket

    1熱度

    2回答

    我似乎無法弄清楚如何編寫此功能。我試圖寫一個函數expand是獲得一個列表lst的形式'(a (2 b) (3 c))的參數,並進行評估,以'(a b b c c c)

    2熱度

    2回答

    如何在只有cons,first,rest和empty時將元素添加到列表末尾(空之前) ?並且可以使用cond遞歸

    3熱度

    2回答

    我試圖做一個函數,需要2個數字,並將創建一個列表,使用第一個數字作爲起始數字,第二個數字作爲結束值,同時填充開始和結束數字之間的值。 例如: 用戶通過在圖3和7: 輸出應爲(3 4 5 6) 我試圖做到這一點,利用遞歸但我奮力: (define (createlist start end) (if(= start end) '()) (cons start '())

    3熱度

    3回答

    我想下面的表達式的語法改變: (> 2 1) 喜歡的東西: (2 greater 1) 我的第一次嘗試是下面的宏: (define-syntax greater (lambda (x) (syntax-case x (greater) [(a greater b) (syntax (> a b))]))) 使用這個宏失敗:「壞語法:更大的」

    2熱度

    3回答

    我想創建一個函數,它將兩個函數作爲參數並執行它們。 我試過使用cond,但它只執行action1。 (define seq-action (lambda (action1 action2) (cond ((procedure? action1) (action1)) ((procedure? action2) (action2))))) 我覺得不應該太難

    0熱度

    2回答

    方案/球拍中的功能。 使用二叉搜索樹處理幾個函數。我已經定義了輔助功能是: ;; returns value of node (define (value node) (if (null? node) '() (car node))) ;; returns left subtree of node (define (left node) (if (null?

    1熱度

    1回答

    我想知道我寫的是否正確;這是一個學校項目,所以我想確保它在上傳之前提供正確的輸出。計算cos x = 1 - ((x^2)/(2!))+((x^4)/(4!)) - ((x^6)/(6!))的數學算法。 ))+ ... 因此,這裏是我的代碼: (define (calc-cos x n) (define (hulp ctr res prevPow prevFac switch)

    1熱度

    3回答

    我已經定義輔助功能是: ;; returns value of node (define (value node) (if (null? node) '() (car node))) ;; returns left subtree of node (define (left node) (if (null? node) '() (cadr nod

    0熱度

    1回答

    我需要一些幫助來理解這段代碼的作用。我不確定fcombine變量的作用是什麼?有人可以給我一個代碼正在做什麼的演練嗎? (define (reduce fcombine L) (cond ((null? (cdr L)) (car L)) (#t (fcombine (car L) (reduce fcombine (cdr L))))))

    2熱度

    2回答

    這是SICP中的一個示例,我輸入它但出現錯誤。 (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) 這是錯誤: function call: expected a function after the open parenthesis