0
(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"))

我将它与 MIT/GNU Scheme 实现一起使用,它可以让我运行此代码并正确响​​应。不过我的问题是,一旦将用户数据放入函数中,它就不会将任何类型的信息绑定到变量。IE 在输入数据并尝试访问任何参数后,我得到以下信息:

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

1 回答 1

0

对不起,对我有用:

$ 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.
于 2013-04-28T22:57:14.557 回答