如何在 CHICKEN 方案脚本参数中使用数字

how to use number in CHICKEN scheme script parameter

这是我的方案代码:

(define (fact n)
  (if (= n 1)
      1
      (* n (fact (- n 1)))))
(define (main args)
  (fact (car args)))

然后我 运行 将此代码作为脚本与 bash 中的此命令一起使用:

csi -ss test.scm 4

但是,解释器收到此错误消息:

Error: (=) bad argument type: "4"

Call history:

<syntax>      (##core#lambda (n) (define (iter num result) (if (> num n) result (iter (+ num 1) (* result num)))) ...
<syntax>      [fact2] (##core#let ((iter (##core#undefined))) (##core#set! iter (##core#lambda (num result) (if (> num n) ...
<syntax>      [fact2] (##core#begin (##core#set! iter (##core#lambda (num result) (if (> num n) result (iter (+ num 1) (* ...
<syntax>      [fact2] (##core#set! iter (##core#lambda (num result) (if (> num n) result (iter (+ num 1) (* result num))))...
<syntax>      [fact2] (##core#lambda (num result) (if (> num n) result (iter (+ num 1) (* result num))))
<syntax>      [iter] (##core#begin (##core#if (> num n) result (iter (+ num 1) (* result num))))
<syntax>      [iter] (##core#if (> num n) result (iter (+ num 1) (* result num)))
<syntax>      [iter] (> num n)
<syntax>      [iter] (iter (+ num 1) (* result num))
<syntax>      [iter] (+ num 1)
<syntax>      [iter] (* result num)
<syntax>      [fact2] (iter 1 1)
<syntax>      [fact2] (##core#undefined)
<eval>    [main] (fact (car args))
<eval>    [main] (car args)
<eval>    [fact] (= n 1)    <--

我猜解释器将参数 4 作为字符串,那么如何在 CHICKEN 方案脚本参数中使用数字?

尝试string->number,这是一个标准的 R5RS 程序:

(define (main args)
  (fact (string->number (car args))))