方案:申请不是程序

问题描述 投票:1回答:1

我环顾四周,关于堆栈交换的另一个答案说,我用括号括起了一些东西,我不应该这样做,因为那是在调用一个值作为函数。我找不到发生在cond中的位置。这是错误的过程

(define insert_labels (lambda (l)(
  ;; if the car is null, return empty list


  (cond 
   ;; if the next element is null, append and break
   [(null? l) ""]

   ;; Before it was recurring to the null pointer and adding the car of that to
   ;; my hash table. This was my attempt to try and stop that but now i'm getting
   ;; my current error
   [(eq? (cdr l) '()) 0]

   ;; if the car of the list is of type other, append the cadr and recur
   [(eq? (what-kind (car l)) 'other) (hash-set! label_hash (car l) (cadr l)) (insert_labels (cdr l))]

   ;; else, recur
   [else (insert_labels (cdr l))]
   )
  )
  )
)

弹出错误,因为我试图阻止我的过程重复通过空指针。但是现在它给了我当前的错误。其他地方提到它会引发此错误,因为我正在使用()来调用函数调用,但我看不出该行的方式会导致该错误,这不仅是cond的格式吗?

scheme racket
1个回答
0
投票

在cond外面看:

(lambda (l)(
  ;; if the car is null, return empty list


  (cond 

cond返回的值由于(而被用作函数。

将其更改为:

(lambda (l)
  ;; if the car is null, return empty list


  (cond 
© www.soinside.com 2019 - 2024. All rights reserved.