#!在 Scheme 中打印值时出现非特定错误
#!unspecific error while printing values in Scheme
我的输出一直是:
Exam Avg: 50.#!unspecific
每当我尝试在方案中打印我的程序时。我正在使用两个函数 print 和 secprint,我认为可能会发生错误:
(define (print cnt List)
(if (= cnt 1) (printEmp (car List))
(secprint cnt List )))
(define (secprint cnt List)
(printEmp (car List))
(newline)
(print (- cnt 1) (cdr List)))
Could someone please help with this? I am new to scheme and can't seem to figure out where I am going wrong.
Edit: Other code that might be useful.
(define (avg List)
(cond ((string=? "std" (car (split List)))
(display (/ (examTotals List) 3.0)))
(else 0))
)
display
过程写入输出,然后 return 是一个未指定的值。您使用 display
是因为它打印数据的副作用,而不是因为它的 return 值。
(define (avg List)
(cond ((string=? "std" (car (split List)))
(display (/ (examTotals List) 3.0)))
(else 0)))
avg
过程 return 是最后计算的表达式的值;当 display
分支计算时,未指定的值被 returned 给调用者。但是调用者 printEmp
不需要 avg
来显示其结果,它只需要一个 returned 值,然后由 printEmp
过程打印。
通过从 avg
过程中删除 display
来修复:
(define (avg List)
(cond ((string=? "std" (car (split List)))
(/ (examTotals List) 3.0))
(else 0)))
我的输出一直是:
Exam Avg: 50.#!unspecific
每当我尝试在方案中打印我的程序时。我正在使用两个函数 print 和 secprint,我认为可能会发生错误:
(define (print cnt List)
(if (= cnt 1) (printEmp (car List))
(secprint cnt List )))
(define (secprint cnt List)
(printEmp (car List))
(newline)
(print (- cnt 1) (cdr List)))
Could someone please help with this? I am new to scheme and can't seem to figure out where I am going wrong.
Edit: Other code that might be useful.
(define (avg List)
(cond ((string=? "std" (car (split List)))
(display (/ (examTotals List) 3.0)))
(else 0))
)
display
过程写入输出,然后 return 是一个未指定的值。您使用 display
是因为它打印数据的副作用,而不是因为它的 return 值。
(define (avg List)
(cond ((string=? "std" (car (split List)))
(display (/ (examTotals List) 3.0)))
(else 0)))
avg
过程 return 是最后计算的表达式的值;当 display
分支计算时,未指定的值被 returned 给调用者。但是调用者 printEmp
不需要 avg
来显示其结果,它只需要一个 returned 值,然后由 printEmp
过程打印。
通过从 avg
过程中删除 display
来修复:
(define (avg List)
(cond ((string=? "std" (car (split List)))
(/ (examTotals List) 3.0))
(else 0)))