Error In Procedure Scm_i_lreadparen
#
procedure scm_i_lreadparen: #
VariablesTail Recursion Pros and Cons True or False (#t or #f) Relational Operators Compound Conditions If Statements Using cond to Implement Else If Statements Loops Some Gotchas Real Loops Demonstration of Scheme Power Data in Scheme Lists Command Line Arguments File http://www.troubleshooters.com/codecorn/scheme_guile/hello.htm I/OKludge: Printing DecimalsRandom Numbers in Scheme (Guile implementation) IntroductionThis page moves you from http://ideone.com/1e54XE zero Scheme knowledge to beginner level Scheme knowledge. To help the former C, C++, Java, Perl, Python, Ruby or Pascal programmer, there are a few references to similarities and differences between those languages and Scheme.Because of Scheme's syntactic consistency, once you get used to the profusion of parentheses, this language actually turns out to be error in easy to learn and remember.Hello World The following is the a "Hello World" Scheme program, run with GNU Guile, as is all code on this page: #!/usr/bin/guile!#(display "Hello World")(newline) Notice the reverse shebang (!#) on line 2. That's because in Scheme, any code starting with #! and ending in !# is a comment, so the top shebang line must be followed by the !# comment-end string.Scheme also has a error in procedure linewise comment, the semicolon (;). Anything between an unquoted, unescaped semicolon and the end of the line is a comment in Scheme.DefineIn Scheme, you declare and instantiate a variable with the define function: #!/usr/bin/guile!#(define hi "Hello World")(display hi)(newline) You just declared and instantiated a variable called hi. Variables declared with define are global variables. Local variables can be created with the let operator, as will be shown later. Once the variable is declared with define, further changes can be made using the set! operator, as will be shown later.Notice that every Scheme statement occurs between parentheses. It takes a little getting used to, but that's how Scheme works. Every Scheme statement looks like this:(operator operand operand ...)The number of operands is defined by the operator. Operator define takes two operands, the variable name and the value being assigned it. The display operator takes one operand, the object to be printed on the screen. The newline operator takes no operands. Some operands, such as the append operand for lists, which will be demonstrated later in this document, takes an indefinite number of operands.This "operator comes first" syntax makes Scheme a "prefix language", because the operator is a prefix to the operands. Consider the following three
function max for Nested list;(max ‘(1 (2 (3 4)) 5);5;;(max ‘(((4 2) 7) 5 3);7;;(max ‘(((1 2) 3) work);NIL(define (max_for_Nested_list k) (cond ((null? k) 'NIL) ;NIL回傳空值 (number? (car k) k) ;是數字傳數字 ((not (number? (car k))) 'NIL) ;不是數字就回傳NIL ;如果有NIL 就回傳NIL ((eq? (max_for_Nested_list (car k)) 'NIL) 'NIL) ((eq? (max_for_Nested_list (cdr k)) 'NIL) 'NIL) ((< (max_for_Nested_list(car k)) (max_for_Nested_list(cdr k)) (max_for_Nested_list (cdr k)) ) ( (max_for_Nested_list(car k)) ) )) (display (max_for_Nested_list '(1 (2 (3 4)) 5))) (newline) (display (max_for_Nested_list '(((4 2) 7) 5 3))) (newline) (display (max_for_Nested_list '(((1 2) 3) work))) (newline)(define (insert atom lis) ;lis=list (cond ((null? lis) ;list是不是NULL (cons atom lis) ) ((< atom (car lis)) ;a是否小於lis的第一個 (cons atom lis) ) (else (cons (car lis) (insert atom (cdr lis))) ) )) (display (insert 2 '(1 5 7))) (display (insert 9 '(1 5 7))) (display (insert 1 '(3 5 7)))(define (sort lis2) (cond ((null? (cdr lis2)) ; lis2是不是一個atom lis2 ) ((list? (car lis2)) ; list在前面 從前面找() (cons (sort(car lis2)) (sort(cdr lis2))) ; 找到前面那個是ATOM的時候然後才CONS起來 ) (else (insert (car lis2) (sort(cdr lis2))) ;把找到是ATOM的東西 到LIST中的位置 ) )) (display (sort '(3 1 5 7 ))) ;(1 3 5 7) (display (sort '(3 1 9 5 7 0))) ;(0 1 3 5 7 9) ;(hint: list 放前面) (display (sort '(((3 1) 9 5) 7 0))) ;(((1 3) 5 9) 0 7)) O0NPTlMg5ZCI5L21KENPTlMgYSwgYikgcmV0dXJuIChhLCBiKQo7Q0FS6YG45Ye656ys5LiA5YCLCjtDRFLliKrpmaTnrKzkuIDlgIsg5Ymp5LiL55qECgo7MS4JZnVuY3Rpb24gbWF4IGZvciBOZXN0ZWQgbGlzdAo7KG1heCDigJgoMSAoMiAoMyA0KSkgNSkKOzUKOwo7KG1heCDigJgoKCg0IDIpIDcpIDUgMykKOzcKOwo7KG1heCDigJgoKCgxIDIpIDMpIHdvcmspCjtOSUwKCihkZWZpbmUgKG1heF9mb3JfTmVzdGVkX2xpc3QgaykKC