2013-04-28 3 views
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 구현과 함께 사용하고 있습니다. 내 문제는 비록 사용자 데이터가 일단 변수에 어떤 종류의 정보도 바인딩하지 않는다면 함수에 넣는다는 것입니다. I.E. 다음 데이터에 넣고 내가 할 매개 변수에 액세스하려고 후 :스키마의 언 바운드 변수

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

어떻게 코드를 '실행'있다? 대부분 한 환경에서 양식을 평가하는 방식으로 실행하고 평가 환경에서 찾을 수없는 변수에 액세스해야 할 가능성이 큽니다. – GoZoner

+0

.scm으로 텍스트 파일에 저장 한 다음 MIT/GNU Scheme 인터프리터로 직접 열려고합니다. –

+0

'(load file.scm)'이라고 말하면 로딩은 ('read-line'을 호출했기 때문에) 어떤 것을 타이핑 할 때까지 기다릴 것입니까? 아니면 다른 일이 발생 했습니까? – GoZoner

답변

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. 
+0

그건 이상합니다. 나는 다른 컴퓨터 나 그 선을 따라 가려고 노력할 것이다. 어쨌든 도와 주셔서 대단히 감사합니다. –