STk>(precedes 3 '(1 2 3 6 3 4)) (2 6) STk>(precedes 3 '(1 2 3 2 3 4)) (2 2) STk>(precedes 8 '(1 2 3 6 3 4)) ()
(define (append1! lst new) (set! lst (append lst new)) lst) (define (append2! lst new) (set-cdr! (last-pair lst) new) lst)
Suppose you execute the following:
STk> (define a (list 1 2 3)) a STk> (define b (list 1 2 3 4)) b STk> (append1! a (list 5 6)) .... STk> a .... STk> (append2! b (list 5 6)) .... STk> b ....
Fill in the dots above. Explain why a and b have the values you have given.
STk> (define a (list 1 2 3)) a STk> (delete! a) (1 2) STk> (delete! a) (1)
It is required that you write a procedure whose cost is INDEPENDENT on the length of the queues. Use the predicates/selectors/mutators (empty-queue? queue), (front-queue queue), (front-ptr queue), (rear-ptr queue), (set-front-ptr! queue item), (set-rear-ptr! queue item) from the texbook.
It should work like this.
STk> (define q1 (make-queue)) q1 STk> (insert-queue! q1 'a) ((a) a) STk> (insert-queue! q1 'b) ((a b) b) STk> (define q2 (make-queue)) q2 STk> (insert-queue! q2 'x) ((x) x) STk> (append-queue! q1 q2) ((a b x) x) STk> q1 ((a b x) x) STk> q2 (() x)
It should work like this: suppose you are given a table dictionary containing English words as keys and their Italian translation as values. Suppose you are also given a list text of words in English. (translate text dictionary) should return the word for word translation into Italian of text.
STk> (define dict '(*table* (noodles . pasta) (love . amo) (i . io))) STk> (translate '(i love noodles) dict) (io amo pasta)
STk> (define john (make-account 100)) ;; create new account with $100 STk> ((john 'deposit) 0) ;; check balance with a zero deposit 100 STk> (define mary ((john 'split))) ;; split the account in two. ;; NOTE the double parentheses mary STk> ((john 'deposit) 0) ;; john is left with half the money. 50 STk> ((mary 'deposit) 0) ;; mary is left with half the money. 50
|+||number||adds the number to the current value|
|clear!||resets the current value to 0|
|show||show the current value|
It should work like this:
STk> (define calc (make-adder)) calc STk> ((calc '+) 18) 18 STk> (calc 'show) 18 STk> (calc 'clear!) 0
>>> replace('a','b',['a',2,'c']) ['b', 2, 'c'] >>> replace('a','b',['b',2]) ['b', 2]
>>> zero(['a',2,'c']) [0, 0, 0]
Copyright: © 2006 by the Regents of the University
Department of Computer Science and Engineering. All rights reserved.
Comments to: Maria Gini
Changes and corrections are in red.