add mutation assignment lesson

This commit is contained in:
Peter Tillemans 2024-03-13 23:52:26 +01:00
parent 5ca2960b6b
commit 41a04a9d94

View 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)