Scheme中的未绑定变量

Scheme中的未绑定变量,scheme,mit-scheme,Scheme,Mit Scheme,我将其用于MIT/GNU方案实现,它允许我运行此代码并正确响应。但我的问题是,一旦将用户数据放入函数中,它就不会将任何类型的信息绑定到变量。即,在输入数据并尝试访问任何参数后,我得到以下结果: (define input (read-line)) (define lngth (string-length input)) (define first-char (string-ref input 0)) (define test-num (string->number (subs

我将其用于MIT/GNU方案实现,它允许我运行此代码并正确响应。但我的问题是,一旦将用户数据放入函数中,它就不会将任何类型的信息绑定到变量。即,在输入数据并尝试访问任何参数后,我得到以下结果:

(define input (read-line))
(define lngth (string-length input))
(define first-char (string-ref input 0))
(define test-num 
  (string->number 
   (substring input 0 (- (string-search-forward " " input) 1))))
(define end (string-search-forward ")" input))
(define beginning (string-search-backward "(" input))
(define operation (string (substring input beginning (+ end 1))))
(define space1 (string-search-forward " " operation))
(define space2 (string-search-backward " " operation))
(define n1 (string->number (substring operation 1 space1)))
(define n2 (string->number (substring operation (+ space1 1) space2)))
(define result (1))
(define operator (substring operation (+ space2 1) end))

(if (or (equal? first-char #\() (number? test-num))
    (display "yay")
    (display "ERROR"))
对不起,对我有用:

1 ]=> (display input)
;Unbound variable : input

你是如何“运行”代码的?最有可能的是,您运行它的方式是在一个环境中对表单进行求值,然后当您访问在求值环境中找不到的变量时。我将它保存在一个文本文件中为.scm,然后直接用MIT/GNU Scheme解释器打开它。您可以说
(load file.scm)
然后加载等待您键入内容(因为您调用了
readline
)?还是发生了其他情况?它等待我键入内容,然后根据我键入的内容,在包含的if中显示任一选项。当我在输入后尝试调用任何定义变量的值时,问题就出现了。这时我得到了unbound变量消息;它对我有用。对不起,这很奇怪。我会试着用另一台电脑或者类似的东西。无论如何,非常感谢你的帮助。
$ mit-scheme 
MIT/GNU Scheme running under MacOSX
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2011 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Tuesday November 8, 2011 at 10:45:46 PM
  Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (load "bar.scm")

;Loading "bar.scm"...(a b c)           ;; (define input (read-line))
 done
;Value: len

1 ]=> input                            ;; 'input' is bound

;Value 13: "(a b c)"

1 ]=> ^D
End of input stream reached.
Moriturus te saluto.