add mutation assignment lesson
This commit is contained in:
parent
5ca2960b6b
commit
41a04a9d94
1 changed files with 34 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)
|
||||||
|
|
Loading…
Reference in a new issue