Hallo!
kann mir bitte jemand sagen wo ich die sog. zusaetzlichen funktionen von scheme, sprich die datei tools.scm finden kann ?
vielen dank
find die auch grad nicht an der Uni-Seite,
bei mir lokal siehts sie so aus:
;;;; ============================================================================================
;;;; some basic functions that are missing in some scheme implementations,
;;;; uncomment, if necessary
;;;; ============================================================================================
;(define (list-ref xs n)
; ;;; element n of list xs, zero indexed
; (cond
; ((<= (length xs) n)
; (error "list-ref: Index" n "out of range for list" xs))
; ((zero? n) (car xs))
; (else (list-ref (cdr xs) (- n 1)))))
(define (add1 x) (+ x 1))
(define (sub1 x) (- x 1))
(define (id x) x)
(define writeln
(lambda args
(for-each display args)
(newline)))
(define (space n)
(iterate
(curry string-append " ")
(compose (curry = n)
string-length)
""))
;;;; =============================================================================================
;;;; random numbers
;;;; =============================================================================================
(define *last-ran* 1) ; the previous random number
(define (random-real)
;;; pick a random real number between 0 and 1.0
(let* ((a (add1 (expt 2 7)))
(b 1)
(T (sub1 (expt 2 35)))
(next-ran (remainder
(+ (* a *last-ran*)
b)
T)))
(set! *last-ran* next-ran)
(/ next-ran T)))
(define (random n)
;;; pick a random integer between 0 and n-1
(floor (* n (random-real))))
(define (random-elt choices)
;;; Choose an element from a list at random
(list-ref choices (random (length choices))))
;;;; =============================================================================================
;;;; Repetition
;;;; =============================================================================================
(define (iterate f end? seed)
; apply f to seed and repeat the process on the sequence of results (f (f (.. seed)))
; until (end? (f(f ..seed))) is satisfied. return the last value.
(if (end? seed) seed
(iterate f end? (f seed))))
(define (reduce f xs seed)
(cond ((null? xs) seed)
(else
(reduce f
(cdr xs)
(f seed (car xs))))))
;;;; =============================================================================================
;;;; The dylan function builders, see Graham
;;;; =============================================================================================
(define (curry1 f x)
;; curry left arg to the function f
(lambda (y) (f x y)))
(define curry
;;; curry an arbitrary number of args (from left to right)
;;; to a function of several args.
(lambda args ;function name and args to be curried
(let ((f (car args))
(curried-args (cdr args)))
(lambda not-curried-args
(apply f
(append
curried-args
not-curried-args))))))
(define rcurry
;;; curry an arbitrary number of args (as the last args)
;;; to a function of several args.
(lambda args ;function name and args to be curried
(let ((f (car args))
(curried-args (cdr args)))
(lambda not-curried-args
(apply f
(append
not-curried-args
curried-args))))))
(define (compose2 f g)
;; compose two functions in one argument: (f (g x))
(lambda (x) (f (g x))))
(define compose
;; compose an arbitrary number of functions
(lambda functions
(if (null? functions) id
(let* ((rfs (reverse functions))
(f0 (car rfs)))
; the last function has to be applied first
(lambda fargs
(reduce
(lambda (v fi) (fi v))
; apply function i to the previous result
(cdr rfs)
(apply f0 fargs))))))) ; the seed value
(define disjoin
;; return a composite predicate that is true
;; when any of the component predicates are true
(lambda functions
(if (null? functions) (always #f) ;no predicate is true
(let ((f0 (car functions))
(rest (cdr functions)))
(lambda args
(or (apply f0 args)
(apply (apply disjoin rest) args)))))))
(define conjoin
;; return a composite predicate that is true
;; when all of the component predicates are true
(lambda functions
(if (null? functions) (always #t) ;all predicates are true
(let ((f0 (car functions))
(rest (cdr functions)))
(lambda args
(and (apply f0 args)
(apply (apply disjoin rest) args)))))))
dank dir für die funktionen.
hab trotzdem gerade nochmal gesucht und bin fündig geworden.
seit heute liegt die datei 'tools.scm' im p1texte ordner (die war gestern noch nich da)
grüsse
schön und gut…aber wofür brauchen wir die tools.scm?
nö gehen alle gut ohne
oder für welche der aufgaben wolltest du was aus der tools.scm benutzen?
nö gehen alle gut ohne
oder für welche der aufgaben wolltest du was aus der tools.scm benutzen?
Dann benutzt du evtl. eine Scheme-Implementation die alle der Funktionen schon drinhat
Ich bin auch mit DrScheme ohne diese tools.scm ausgekommen. Kann natürlich sein, dass ich es mir komplizierter gemacht habe, als nötig…
Das Scheme auf der rzdspc3 und damit wahrschienlich alle Kommandozeilenschemes in der Uni (/opt/bin/scm) kennt zumindest weder id noch curry sowiet ich das beurteilen kann
… zumindest ich habe keines davon genutzt [img]
http://www.fb18.de/gfx/24.gif[/img]
curry kennt so gut wie kein scheme. Hattet ihr in der VL kein reduce oder curry? letztes jahr musste man auf einem zettel höhere funktionen benutzen um listen zu bearbeiten, und curry war da sehr nützlich.