Compare commits
2 commits
5ca2960b6b
...
3570252c1b
Author | SHA1 | Date | |
---|---|---|---|
3570252c1b | |||
41a04a9d94 |
2 changed files with 74 additions and 0 deletions
34
10_mutation_assignment.scm
Normal file
34
10_mutation_assignment.scm
Normal file
|
@ -0,0 +1,34 @@
|
|||
;; -*- geiser-scheme-implementation: guile -*-
|
||||
|
||||
(define chest 'sword)
|
||||
|
||||
chest ; sword
|
||||
|
||||
(set! chest 'gold) ; #<unspecified>
|
||||
|
||||
chest ; gold
|
||||
|
||||
|
||||
(define (make-countdown n)
|
||||
(lambda ()
|
||||
(define last-n n)
|
||||
(if (zero? n)
|
||||
0
|
||||
(begin
|
||||
(set! n (- n 1))
|
||||
last-n))))
|
||||
(define cdown (make-countdown 3))
|
||||
|
||||
(cdown) ; 3
|
||||
(cdown) ; 2
|
||||
(cdown) ; 1
|
||||
(cdown) ; 0
|
||||
(cdown) ; 0
|
||||
|
||||
(define vec (vector 'a 'b 'c))
|
||||
vec ; #(a b c)
|
||||
(vector-ref vec 1) ; b
|
||||
(vector-set! vec 1 'boop)
|
||||
(vector-ref vec 1) ; boop
|
||||
vec ; #(a boop c)
|
||||
|
40
11_extensibility.scm
Normal file
40
11_extensibility.scm
Normal file
|
@ -0,0 +1,40 @@
|
|||
;; -*- geiser-scheme-implementation: guile -*-
|
||||
|
||||
(if (our-test)
|
||||
(begin
|
||||
(do-thing-1)
|
||||
(do-thing-2)))
|
||||
|
||||
(define (when test . body)
|
||||
`(if ,test
|
||||
,(cons 'begin body)))
|
||||
|
||||
(when '(our-test)
|
||||
'(do-thing-1)
|
||||
'(do-thing-2))
|
||||
; (if (our-test) (begin (do-thing-1) (do-thing-2)))
|
||||
|
||||
(define-macro (when test . body)
|
||||
`(if ,test
|
||||
,(cons 'begin body)))
|
||||
|
||||
(when (our-test)
|
||||
(do-thing-1)
|
||||
(do-thing-2))
|
||||
|
||||
(define-syntax-rule (when test body ...)
|
||||
(if test
|
||||
(begin body ...)))
|
||||
|
||||
(define-syntax-rule (for (item lst) body ...)
|
||||
(for-each (lambda (item)
|
||||
body ...)
|
||||
lst))
|
||||
|
||||
(for (str '("strawberries" "bananas" "grapes"))
|
||||
(display
|
||||
(string-append "I just love "
|
||||
(string-upcase str)
|
||||
"!!!\n")))
|
||||
|
||||
; #<unspecified>
|
Loading…
Reference in a new issue