berkeley - ; berkeley.scm 4.03.01 Tue Jul 22 17:22:59 2003...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
;;; berkeley.scm 4.03.01 Tue Jul 22 17:22:59 2003 ; ; NOTE: THE MASTER COPY OF THIS FILE IS MAINTAINED BY EECS INSTRUCTIONAL ; SUPPORT. IF YOU MAKE CHANGES HERE THEY WILL GO AWAY. ; ;; Compatibility library for UCB Scheme (STk 4.0.1 derivative) as used ;; in CS61A and CS3. Over-hauled in May 2000 and April 2003 for ;; STk compatibility and to remove dead code. ;; (define nil '()) (define true #t) (define false #f) ;; 4.0: STk already has a time program, so I nuked time ;; 4.0: STk load already has glob built in, so I nuked redef. of load ;; 4.02.01: Remove definition of read. ;; Removed ;;; SICP stuff: (define (print x) (write x) (newline)) ;; Define tagged data ADT: (define (attach-tag type-tag contents) (cons type-tag contents)) (define (type-tag datum) (if (pair? datum) (car datum) (error "Bad tagged datum -- TYPE-TAG" datum))) (define (contents datum) (if (pair? datum) (cdr datum) (error "Bad tagged datum -- CONTENTS" datum))) ;;For Section 3.1.2 -- written as suggested in footnote, ;; though the values of a, b, m may not be very "appropriately chosen" (define (rand-update x) (let ((a 27) (b 26) (m 127)) (modulo (+ (* a x) b) m))) ;;For Section 3.3.4, used by and-gate ;;Note: logical-and should test for valid signals, as logical-not does (define (logical-and x y) (if (and (= x 1) (= y 1)) 1 0)) ;; concurrency stuff ;; 4.0: Simplified these somewhat -- removed tests for scm ;; and added alarm-signal-handler stuff
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
; For timer interrupts in STk: (define (alarm-signal-handler sig) (alarm-interrupt)) (add-signal-handler! 14 alarm-signal-handler) (require 'process) (define test-and-set! (let ((arb (make-arbiter 'scratchnsniff))) (lambda (cell) (if (try-arbiter arb) (begin (process:schedule!) (test-and-set! cell)) (let ((result (car cell))) (set-car! cell #t) (release-arbiter arb) result))))) (define (parallel-execute . thunks) (for-each (lambda (thunk) (add-process! (lambda (foo) (thunk)))) thunks) (alarm-interrupt) (process:schedule!)) (define (stop) (alarm 0) (set! process:queue (make-queue))) ;;For Section 3.5.2, to check power series (exercises 3.59-3.62) ;;Evaluate and accumulate n terms of the series s at the given x ;;Uses horner-eval from ex 2.34 (define (eval-power-series s x n) (horner-eval x (first-n-of-series s n))) (define (first-n-of-series s n) (if (= n 0) '() (cons (stream-car s) (first-n-of-series (stream-cdr s) (- n 1))))) ;; Streams: ;; 4.0: We do not redefine promises as procedures anymore. ; Restrict the domain of FORCE to include only promises. (define force (let ((force force)) (lambda (p) (if (not (promise? p)) (error "Not a promise: " p) (force p))))) (define-macro (cons-stream . args) `(cons ,(car args) (delay ,(cadr args)))) (define (stream-car stream) (car stream)) (define (stream-cdr st) (force (cdr st))) (define the-empty-stream '()) (define (stream-null? stream) (eq? stream the-empty-stream)) (define (stream? obj)
Background image of page 2
(or (stream-null? obj) (and (pair? obj) (promise? (cdr obj))))) (define (stream-accumulate combiner initial-value stream)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

Page1 / 27

berkeley - ; berkeley.scm 4.03.01 Tue Jul 22 17:22:59 2003...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online