(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