set!
. We glossed over it with the 'object' example. mcons, mcdr, mcar, set-mcdr!, set-mcar!
delay
and force
with mutable pairs.
; create a generator g on stream s
(define g (make-gen s))
; access first two elements generated by s
(+ (g) (g))
You want to make sure that your generator g does not fetch anything from the stream until g is invoked, otherwise for finite streams you could run off the end before you intended.
cons
and mcons
as representing edges between vertices in a graph. If v1
and v2
are vertices, then (cons v1 v2)
is the edge from v1
to v2
. For example, this list of edges ( cons(v2 v1) cons(v1 v4) cons(v4 v3) cons(v3 v4) cons(v3 v1) )
defines the graph: (dfs g root)
which does a depth-first traversal of the graph g
, starting at vertex root
, and returns a list of the vertices visited.
q-from-list
that takes a list and creates the queue with the same elements initially, q-to-list
that takes a queue and creates a list containing the current elements of the queue.
6. Week 4 - Jan 27 CMPUT 325 Schedule / Version 2.31 2014-04-04 |