diff --git a/collects/frtime/demos/calculator.ss b/collects/frtime/demos/calculator.ss deleted file mode 100644 index 3ba00fa534..0000000000 --- a/collects/frtime/demos/calculator.ss +++ /dev/null @@ -1,21 +0,0 @@ -(require frtime/gui) - -(define op-names (list "+" "-" "*" "/")) -(define ops (list + - * /)) - -(define (str->num s) - (cond - [(string->number s)] - [#t 0])) - -(define x - (str->num (make-text "First number:"))) - -(define op - (make-choice "Op:" op-names)) - -(define y - (str->num (make-text "Second number:"))) - -(make-message - (format "Result = ~a" ((list-ref ops op) x y))) diff --git a/collects/frtime/demos/circles.ss b/collects/frtime/demos/circles.ss deleted file mode 100644 index a4a2a3f37c..0000000000 --- a/collects/frtime/demos/circles.ss +++ /dev/null @@ -1,23 +0,0 @@ -(require frtime/animation - frtime/etc - frtime/gui) - -(define radius (make-slider "Radius" 100 200 150)) -(define speed (* .02 (make-slider "Speed" 0 10 5))) -(define n (make-slider "Num circles" 1 10 6)) -(define ratio (add1 (* .2 (make-slider "Ratio" 1 5 2)))) - -(define phase (wave speed)) -(define center (make-posn 200 200)) - -(display-shapes - (build-list - n - (lambda (i) - (make-ring - (posn+ center - (posn* - (make-posn (cos phase) (sin phase)) - (* radius (- 1 (expt ratio (- i)))))) - (/ radius (expt ratio i)) - "gray")))) diff --git a/collects/frtime/demos/pizza.ss b/collects/frtime/demos/pizza.ss deleted file mode 100644 index 9a05a305cb..0000000000 --- a/collects/frtime/demos/pizza.ss +++ /dev/null @@ -1,24 +0,0 @@ -(require frtime/gui) - -(define kinds (list "New York" "Chicago" "California" "Hawaii")) -(define sizes (list "small" "medium" "large" "Texas")) - -(define customer - (make-text "Customer name:")) - -(define kind - (make-choice "Kind:" kinds)) - -(define size - (make-choice "Size:" sizes)) - -(define button-event - (make-button "Confirm")) - -(make-message - (hold (button-event - . -=> . - (snapshot (customer kind size) - (string-append customer " ordered a " - (list-ref sizes size) " " - (list-ref kinds kind) " pizza."))))) diff --git a/collects/frtime/demos/spreadsheet/data-synthesis.ss b/collects/frtime/demos/spreadsheet/data-synthesis.ss deleted file mode 100644 index 2643ef8e1e..0000000000 --- a/collects/frtime/demos/spreadsheet/data-synthesis.ss +++ /dev/null @@ -1,72 +0,0 @@ -(module data-synthesis frtime/frtime - -(require "distributions.ss" - mzlib/math - ) - -;; num list -> num -; INPUT: Many numbers DATA -; OUTPUT: That DATA's sample mean (a.k.a mean, average) -(define (sample-mean data) - (let ([n (length data)] - [sum-y (apply + data)]) - (/ sum-y n))) - -;;num list -> num -; INPUT: List of numbers DATA -; OUTPUT: The sample variance of DATA -(define (sample-variance data) - (let* ([n (length data)] - [sm (sample-mean data)] - [d2 (map (lambda (x) - (sqr (- x sm))) - data)]) - (/ (apply + d2) - (- n 1)))) - - -;; NOTE: -;; The sample-mean and sample-variance of set of data are unbiased -;; and efficient estimators of the mean and variance of the probability -;; distribution that produced that data. Therefore, our best fitting -;; normal distribution to that data is a normal distribution having -;; mean equal to the sample mean and variance equal to the sample-variance. - -(define (fit-normal-distribution data) - (make-normal-distribution (sample-mean data) - (sqrt (sample-variance data)))) - -(define (fit-uniform-distribution data) - (let ([mean (sample-mean data)] - [variance (sample-variance data)]) -; (print (format "theta1: ~a" (- mean -; (sqrt (* 3 variance))))) -; (print (format "theta2: ~a" (+ mean -; (sqrt (* 3 variance))))) - (make-uniform-distribution (- mean - (sqrt (* 3 variance))) - (+ mean - (sqrt (* 3 variance)))))) - -; My Gamma work is screwy. See distributions.ss -;(define (fit-gamma-distribution data) -; (let ([mean (sample-mean data)] -; [variance (sample-variance data)]) -; (make-gamma-distribution (/ (sqr mean) -; variance) -; (/ variance mean)))) - -(define (fit-exponential-distribution data) - (make-exponential-distribution (sample-mean data))) - -(define (synthesize-random-data dist size) - (if (zero? size) - '() - (cons ((distribution-rand dist)) - (synthesize-random-data dist (sub1 size))))) - - - -(provide (all-defined)) - - ) diff --git a/collects/frtime/demos/spreadsheet/demos.sheet b/collects/frtime/demos/spreadsheet/demos.sheet deleted file mode 100644 index e8a4c7f406..0000000000 --- a/collects/frtime/demos/spreadsheet/demos.sheet +++ /dev/null @@ -1 +0,0 @@ -((35 (apply format "~a:~a:~a" (map (@e (+ row -1) (+ col 0)) (list (date-hour (@e (+ row -2) (+ col 0))) (date-minute (@e (+ row -2) (+ col 0))) (date-second (@e (+ row -2) (+ col 0))))))) (32 seconds) (17 (- row 10)) (34 (lambda (x) (if (< x 10) (format "0~a" x) x))) (33 (seconds->date (@e (+ row -1) (+ col 0)))) (31 (quote behaviors:)) (16 (- row 10)) (18 (quote below:)) (15 (- row 10)) (13 (- row 10)) (14 (- row 10)) (12 (- row 10)) (11 (- row 10)) (0 1) (2 1) (8 "above:") (4 1) (9 (quote below:)) (10 (- row 10)) (7 1) (6 1) (5 1) (3 1) (1 1))((27 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (25 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (23 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (21 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (31 undefined) (29 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (22 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (20 1) (17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (30 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (19 1) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (26 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (24 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (18 (quote fibonacci)) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (28 (+ (@e (+ row -2) (+ col 0)) (@e (+ row -1) (+ col 0)))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 "pascal's") (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 (quote mult)) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((25 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (27 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (21 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (19 undefined) (29 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (23 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (20 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (30 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (22 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (26 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (24 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (18 "golden ratio") (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (28 ((@e 20 (+ col 2)) (/ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col -1))))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 (quote triangle)) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 (quote table)) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 undefined) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 undefined) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((27 (@c (+ row -3) (+ row 0) (+ col -3))) (25 (@c (+ row -3) (+ row 0) (+ col -3))) (29 (@c (+ row -3) (+ row 0) (+ col -3))) (22 "list of 4") (20 (lambda (x) (/ (round (* 100000 (exact->inexact x))) 100000))) (17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (30 (@c (+ row -3) (+ row 0) (+ col -3))) (23 (@c (+ row -3) (+ row 0) (+ col -3))) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (26 (@c (+ row -3) (+ row 0) (+ col -3))) (24 (@c (+ row -3) (+ row 0) (+ col -3))) (19 (quote cell)) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (28 (@c (+ row -3) (+ row 0) (+ col -3))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 undefined) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 undefined) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((25 (apply + (@e (+ row 0) (+ col -1)))) (29 (apply + (@e (+ row 0) (+ col -1)))) (23 (apply + (@e (+ row 0) (+ col -1)))) (27 (apply + (@e (+ row 0) (+ col -1)))) (17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (30 (apply + (@e (+ row 0) (+ col -1)))) (22 "sum of 4") (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (26 (apply + (@e (+ row 0) (+ col -1)))) (24 (apply + (@e (+ row 0) (+ col -1)))) (19 (quote containing)) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (28 (apply + (@e (+ row 0) (+ col -1)))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 undefined) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 undefined) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (19 (quote function)) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 undefined) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 undefined) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((17 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (16 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (15 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (13 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (14 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (12 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (11 (* (@e (+ row 0) 0) (@e 10 (+ col 0)))) (0 1) (2 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (8 undefined) (4 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (9 undefined) (10 col) (7 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (6 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (5 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (3 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))) (1 (+ (@e (+ row 0) (+ col -1)) (@e (+ row -1) (+ col 0)))))((13 undefined) (12 undefined) (11 undefined) (0 undefined) (2 undefined) (8 undefined) (4 undefined) (9 undefined) (10 undefined) (7 undefined) (6 undefined) (5 undefined) (3 undefined) (1 undefined))((13 undefined) (12 undefined) (11 undefined) (0 undefined) (2 undefined) (8 undefined) (4 undefined) (9 undefined) (10 undefined) (7 undefined) (6 undefined) (5 undefined) (3 undefined) (1 undefined))()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() \ No newline at end of file diff --git a/collects/frtime/demos/spreadsheet/distributions.ss b/collects/frtime/demos/spreadsheet/distributions.ss deleted file mode 100644 index 8e11948237..0000000000 --- a/collects/frtime/demos/spreadsheet/distributions.ss +++ /dev/null @@ -1,433 +0,0 @@ -(module distributions mzscheme - - (require mzlib/math - ) - - (define RANDOM-GRAIN (sub1 (expt 2 31))) - - ;; A distribution has a: - ;; bool continuous? : Is this distribution continuous? (#t if yes, #f if discrete) - ;; (num -> num) density-f : Probability density function f(y)= p(y) - ;; num mean : mean of distribution - ;; num variance : variance of distribution - ;; I need to think about this next one: - ;; (num -> num)? mgf : moment generating function. Forgive the acronym. - (define-struct distribution (continuous? - d-func - mean - variance - rand - )) - - (define (print-distribution dist) - (print (format "continuous?: ~a, mean: ~a, variance: ~a" - (distribution-continuous? dist) - (distribution-mean dist) - (distribution-variance dist)))) - - (define (ln n) - (/ (log n) - (log e))) - - - (define fac - (lambda (n) - (if (zero? n) - 1 - (* n (fac (- n 1)))))) - - (define choose - (lambda (a b) - (/ (fac a) - (* (fac b) - (fac (- a b)))))) - - (define myround - (lambda (n) - (- n - (- n (round n))))) - - - - ;; Ultimately, mgf might be a struct, with make-uniform-mgf, make-normal-mgf, etc. - ;; be special constructors for that particular struct. For now, I'll leave - ;; this as the actual formula - (define (make-uniform-mgf theta1 theta2) - (lambda (t) - (/ (- (exp (* t theta2)) - (exp (* t theta1))) - (* t - (- theta2 theta1))))) - (define (make-normal-mgf mu sigma) - (lambda (t) - (exp (+ (* mu t) - (/ (* (sqr t) (sqr sigma)) - 2))))) - - ;;Do I need these? Dammit! - (define (make-exponential-mgf bete) - 'dummy) - (define (make-binomial-mgf n p) - 'dummy) - - - - - - (define (make-uniform-distribution theta1 theta2) - (make-distribution #t - (lambda (y) - ;;is it appropriate to limit the domains of the - ;; probability functions with conditionals like - ;; this? - (if (or (< y theta1) - (< theta2 y)) - 0 - (/ (- theta2 theta1)))) - (/ (+ theta1 theta2) - 2) - (/ (sqr (- theta2 theta1)) - 12) - (lambda () - (uniform-random theta1 theta2)) - )) - - (define (make-normal-distribution mu sigma) - (make-distribution #t - (lambda (y) - (* (/ (* sigma (sqrt (* 2 pi)))) - (exp (- (* (/ (* 2 (sqr sigma))) - (sqr (- y mu))))))) - mu - (sqr sigma) - (lambda () - (normal-random mu sigma)) - )) - - (define (make-exponential-distribution beta) - ;;Can I asser here that beta > 0?? - (make-distribution #t - (lambda (y) - (if (< 0 y) - (* (/ beta) - (exp (/ (- y) - beta))) - 0)) - beta - (sqr beta) - (lambda () - (exponential-random beta)) - )) - - ;; FUCK! The Gamma function is a big integral, equal to factorial if the - ;; argument is an integer, but otherwise...crap on a stick! - - ; (define (make-gamma-distribution alpha beta) - ; (make-distribution #t - ; (lambda (y) - - - (define (make-binomial-distribution n p) - (make-distribution #f - (lambda (y) - ;;should assert whole-number-ness here or something - (* (choose n y) - (expt p y) - (expt (- 1 p) - (- n y)))) - (* n p) - (* n p (- 1 p)) - (lambda () - (binomial-random n p)) - )) -; -; (define (make-gamma-distribution alpha beta) -; (make-distribution #f -; (lambda (y) -; (if (<= y 0) -; 0 -; (* (expt y (sub1 alpha)) -; (exp (/ (- y) beta)) -; (/ (* (exp (gammln alpha)) -; (expt beta alpha)))))) -; (* alpha beta) -; (* alpha beta beta) -; (lambda () -; (gamma-random alpha beta)))) - - - - - - (define (uniform-random theta1 theta2) - (+ theta1 (* (/ (- theta2 theta1) (sub1 RANDOM-GRAIN)) (random RANDOM-GRAIN)))) - - (define (open-uniform-random theta1 theta2) - (+ theta1 (* (/ (- theta2 theta1) RANDOM-GRAIN) (add1 (random (sub1 RANDOM-GRAIN)))))) - - - - - ;; Although it might be the root of all evil, and make no sense in this context, - ;; I'm going to use the Marsaglia Polar Method here with the flip-flopping - ;; indicator switch because it's HOT. - (define r 0) - (define ind 1) - - (define (ranf) - (open-uniform-random 0 1)) - - (define (standard-normal-random-guts) - (let* ([x1 (- (* 2 (ranf)) 1)] - [x2 (- (* 2 (ranf)) 1)] - [w (+ (* x1 x1) (* x2 x2))]) - (if (> w 1) - (standard-normal-random-guts) - (let ([w2 (sqrt (/ (* (ln w) -2) w))]) - (set! r (* x2 w2)) - (* x1 w2))))) - - (define (standard-normal-random) - (set! ind (- ind)) - (if (> ind 0) - (standard-normal-random-guts) - r)) - - (define (normal-random mu sigma) - (+ (* sigma (standard-normal-random)) mu)) - - (define (exponential-random beta) - (let ([rand (/ (add1 (random (sub1 RANDOM-GRAIN))) RANDOM-GRAIN)]) - (* (- (ln rand)) beta))) - - - - ;(define (testrand args make-dist rand target n m) - ; (/ (let loopa ([t 0]) - ; (if (> t target) - ; 0 - ; (+ (let loop ([i m]) - ; (if (> 0 i) - ; 0 - ; (+ (if (= (apply rand - ; (cons n - ; args)) - ; t) - ; 1 - ; 0) - ; (loop (sub1 i))))) - ;(loopa (add1 t))))) - ;((distribution-density-f (apply make-dist args)) target) - ;)) - - - ;;;pronlems if alpha is a non-integer - ;(define (standard-gamma-random-guts alpha) - ; (let ([v1 (ranf RANDOM-GRAIN)] - ; [v2 (- (* 2 (ranf RANDOM-GRAIN)) 1)]) - ; (if (> (+ (* v1 v1) (* v2 v2)) 1) - ; (standard-gamma-random-guts alpha) - ; (let* - ; ([y (/ v2 v1)] - ; [am (- alpha 1)] - ; [s (sqrt (+ (* 2 am) 1))] - ; [x (+ (* s y) am)]) - ; (if (<= x 0) - ; (standard-gamma-random-guts alpha) - ; (if (> (ranf) - ; (* (+ 1 (* y y)) - ; (exp (- (* am - ; (ln (/ x am))) - ; (* s y))))) - ; (standard-gamma-random-guts alpha) - ; x)))))) - ; - ;;;problems if alpha is a non-integer, I think - ;(define (standard-gamma-random alpha) - ; (cond [(< alpha 1) (error "Bad alpha value for standard-gamma-random")] - ; [(< alpha 6) (let loop ([x 1] [i 0]) - ; (if (> i alpha) - ; (- (ln x)) - ; (loop (* x (ranf)) (add1 i))))] ; the random number here - ; ; might have to be over the - ; ; whole number line. - ; [else (standard-gamma-random-guts alpha)])) - ; - ; - ;;;problems if alpha is a non-integer - ;(define (gamma-random alpha beta) - ; (* beta (standard-gamma-random alpha))) - - ;; PROBLEMS with GAMMA RANDOM: - ;; (1) The random gamma number generator should only take positive integers as - ;; argument according to the spec in Numerical Recipes. However, according to - ;; Mathematical Statistics and Applications, the alpha parameter of a gamma function - ;; may not always be an integer. - ;; (2) Using the code for the random number generator above seems to produce data with mean of - ;; ((alpha + 1) * beta), and variance of ((alpha + 1) * beta ^ 2). I don't know what - ;; is wrong with the code, but I hesitated to just throwing in something subtracting 1 from - ;; alpha before running calculations because that seems unsound. - - - (define (gammln xx) - ;Returns the value ln[(xx)] for xx > 0. - (let* ([ser 1.000000000190015] - [cof1 76.18009172947146] - [cof2 -86.50532032941677] - [cof3 24.01409824083091] - [cof4 -1.231739572450155] - [cof5 0.001208650973866179] - [cof6 -0.000005395239384953] - [x xx] - [y xx] - [tmp (- (+ x 5.5) - (* (+ x 0.5) - (ln (+ x 5.5))))] - [ser2 (+ ser - (/ cof1 (+ y 1)) - (/ cof2 (+ y 2)) - (/ cof3 (+ y 3)) - (/ cof4 (+ y 4)) - (/ cof5 (+ y 5)) - (/ cof6 (+ y 6)))]) - (+ (- tmp) - (ln (* 2.5066282746310005 - (/ ser2 - x)))))) - - - - ;;more sketchy mutative stuff recommended by Numerical Recipes to optimize this craziness. - (define pg 0) - (define poldm -1.0) - (define psq -1) - (define palxm -1) - - - (define (poisson-random xm) - (if (> 12 xm) - (begin - (unless (= xm poldm) - (set! poldm xm) - (set! pg (exp (- xm)))) - (let loop ([em 0] [t (ranf)]) - (if (> t pg) - (loop (add1 em) (* t (ranf))) - em))) - (begin - (unless (= xm poldm) - (set! poldm xm) - (set! psq (sqrt (* 2.0 xm))) - (set! palxm (ln xm)) - (set! pg (- (* xm palxm) (gammln (+ xm 1))))) - (poisson-random-guts xm)))) - - (define (poisson-random-guts xm) - (let loop ([y (tan (* (ranf) pi))]) - (let ([em (+ (* psq y) - xm)]) - (if (< em 0) - (loop (tan (* (ranf) pi))) - (let* ([fem (floor em)] - [t (* 0.9 - (+ 1.0 (* y y)) - (exp (- (* fem palxm) - (gammln (+ fem 1)) - pg)))]) - (if (> (ranf) t) - (loop (tan (* pi (ranf)))) - fem)))))) - - - - - ;;These are mutating variables that are meant to store computed values to speed up sampling - (define bnold -1) - (define bpold -1) - (define boldg -1) - - (define (binomial-random n pp) - ;Returns as a floating-point number an integer value that is a random deviate drawn from - ;a binomial distribution of n trials each of probability pp, using ran1(idum) as a source of - ;uniform random deviates. - (let* ([p (if (<= pp 0.5) - pp - (- 1 pp))] - [am (* n p)]) - (if (< n 25) - (let loop ([bnl 0] [j 1]) - (if (<= n j) - (if (= p pp) - bnl - (- n bnl)) - (if (< (ranf) p) - (loop (add1 bnl) (add1 j)) - (loop bnl (add1 j))))) - (if (< am 1) - (let ([g (exp (- am))]) - (let loop ([t 1] [j 0]) - (if (not (<= j n)) - (if (= p pp) - n - 0) - (let ([t2 (* t (ranf))]) - (if (< t g) - (if (< t g) - (if (= p pp) - j - (- n j)) - (loop t2 (add1 j)))))))) - - (begin - (unless (= n bnold) - (set! boldg (gammln (+ n 1))) - (set! bnold n)) - (let* ([en n] - [pc (- 1 p)] - [plog (ln p)] ; If sampling is too slow - [pclog (ln pc)] ; I can gain speed by storing some of these - [sq (sqrt (* 2 am pc))] ; in mutating, out of function variables - ) - (let loop ([angle (* pi (ranf))]) - (let* ([y (tan angle)] - [em (+ (* sq y) am)]) - (if (or (< em 0) (>= em (+ en 1))) - (loop (* pi (ranf))) - (let ([fem (floor em)] - [t (* 1.2 - sq - (+ (* y y) 1) - (exp (+ boldg - (- (gammln (+ em 1))) - (- (gammln (+ en (- em) 1))) - (* em plog) - (* (- en em) pclog))))]) - (if (> (ranf) t) - (loop (* pi (ranf))) - (if (= p pp) - em - (- n em))))))))))))) - - - - (provide (all-defined)) - ) - -;(let loop ([x (round (binomial-random 100000 10 .4))]) -; (loop (round (binomial-random 100000 10 .4)))) - - - - -;(define (accumulate-mean sampler-event) -; (collect-e sampler-event -; (cons 777777 0) ;;;The number 7777777 never gets used -; (lambda (datum mean-count) -; (let ([new-count (add1 (cdr mean-count))]) -; (cons (+ (/ datum new-count) -; (* (/ (cdr mean-count) -; new-count) -; (car mean-count))) -; new-count))))) - -;(accumulate-mean ((changes milliseconds) . ==> . (lambda (_) (normal-random 1000000 5 30)))) diff --git a/collects/frtime/demos/spreadsheet/doc.txt b/collects/frtime/demos/spreadsheet/doc.txt deleted file mode 100644 index 70f042c4af..0000000000 --- a/collects/frtime/demos/spreadsheet/doc.txt +++ /dev/null @@ -1,32 +0,0 @@ - -This is an experimental spreadsheet to test FrTime and its GUI -development capabilities. It is interesting because FrTime is used to -implement the spreadsheet and as the language for cell formulas. - -Usage: - -To run the spreadsheet, open spread.ss in DrScheme, set the language level -to (module ...), and execute. - -Select a cell by clicking the mouse or moving with the arrow -keys. Press enter to focus the text entry field, where you can enter -a FrTime expression. This includes purely functional Scheme and many -common primitives. In a cell, you can refer to another cell by name. -Entering the formula (+ a5 c7), including the parentheses, makes the -value of the selected cell the sum of cells a5 and c7. - -It is also possible to refer to sequences of adjacent cells, which -results in a list. For example, a1:5 returns a list containing the -values of the cells a1 through a5. - -The spreadsheet can load and save files. For several of examples of -spreadsheet formulas, including the use of behaviors, cell sequences, -and absolute cell references, open demos.sheet. - -Known Bugs: - -- Initial evaluation of a cell formula is super slow. -- Whole-screen redraw, as when scrolling or resizing, is super slow. -- Errors arising during re-evaluation (not during initial evaluation) go - to the DrScheme interactions window instead of propagating to the cell. -- Does not work on MacOS diff --git a/collects/frtime/demos/spreadsheet/preprocessor2.ss b/collects/frtime/demos/spreadsheet/preprocessor2.ss deleted file mode 100644 index d869c1ac0a..0000000000 --- a/collects/frtime/demos/spreadsheet/preprocessor2.ss +++ /dev/null @@ -1,553 +0,0 @@ -(module preprocessor2 mzscheme - - (require mzlib/string - mzlib/etc - ) - - (define (drop l n) - (if (zero? n) - l - (drop (cdr l) (sub1 n)))) - - (define (caddddr lst) - (car (cdr (cdr (cdr (cdr lst)))))) - - (define (first lst) - (car lst)) - - (define (take l n) - (if (zero? n) - '() - (cons (car l) - (take (cdr l) - (sub1 n))))) - - ;; ('a -> bool) * 'a list -> (#f or num) - (define position-of-first-satisfied-in-list - (lambda (pred l) - (let loop ((i 0) (l l)) - (if (null? l) #f - (if (pred (car l)) i - (loop (+ i 1) (cdr l))))))) - - (define position-of-object-in-list - (lambda (o l) - (position-of-first-satisfied-in-list (lambda (x) - (eqv? o x)) - l))) - - (define capitals - '(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z)) - - (define lower-case - (let loop ([i 97]) - (if (<= i 122) - (cons (integer->char i) - (loop (add1 i))) - '()))) - - (define digits - '(#\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\0)) - - (define (contains? i lst) - (and (not (null? lst)) - (or (equal? i (car lst)) - (contains? i (cdr lst))))) - - (define (capital? char) - (contains? char capitals)) - (define (lower-case? char) - (contains? char lower-case)) - (define (digit? char) - (contains? char digits)) - (define (letter? char) - (or (capital? char) - (lower-case? char))) - - (define-struct cell-reference (row1 ; num - row2 ; num - row-absolute? ; bool - col1 ; num - col2 ; num - col-absolute? ; bool - )) - - (define (capital->col-num char) - (- (char->integer char) - 65)) - - (define (lower-case->col-num char) - (- (char->integer char) - 97)) - - #;(define (letter->col-num char) - (if (capital? char) - (capital->row-num char) - (lower-case->row-num char))) - - (define (digit->row-num char) - (- (char->integer char) - 48)) - - #;(define (letter-list->col-num llst) - (let loop ([num -1] - [lst llst]) - (cond [(null? lst) - num] - [(capital? (car lst)) - (loop (+ (* (add1 num) 26) - (capital->row-num (car lst))) - (cdr lst))] - [(lower-case? (car lst)) - (loop (+ (* (add1 num) 26) - (lower-case->col-num (car lst))) - (cdr lst))]))) - - (define (digit-list->row-num nlist) - (let loop ([num 0] - [lst nlist]) - (cond [(null? lst) - num] - [(digit? (car lst)) - (loop (+ (* num 10) - (digit->row-num (car lst))) - (cdr lst))]))) - - (define NOT-A-CELL-REFERENCE #f) - - ;; char list -> cell-reference - (define (parse-ref char-list) - (let loop ([lst char-list] - [reading-col-section #t] - [row1 #f] - [row2 #f] - [row-absolute? #f] - [col1 #f] - [col2 #f] - [col-absolute? #f]) - (cond [(null? lst) - (if (and row1 row2 col1 col2 (not reading-col-section)) - (make-cell-reference row1 row2 row-absolute? col1 col2 col-absolute?) - NOT-A-CELL-REFERENCE)] - [reading-col-section - (cond [(equal? (car lst) - #\$) - (if (or col1 col-absolute?) ;; then already hit first $, so this must refer to numbers - (loop lst #f row1 row2 row-absolute? col1 col2 col-absolute?) - (loop (cdr lst) - #t - row1 row2 row-absolute? - col1 col2 - #t))] - [(letter? (car lst)) - (let ([next (position-of-first-satisfied-in-list - (lambda (o) - (or (equal? o #\$) - (equal? o #\:) - (digit? o))) - lst)]) - (if col1 - (if next - (if (equal? 'invalid - (letter-list->col-num (take lst - next))) - NOT-A-CELL-REFERENCE - (loop (drop lst next) - #t ; should get switched in next iteration - row1 row2 row-absolute? - col1 - (letter-list->col-num (take lst - next)) - col-absolute?)) - NOT-A-CELL-REFERENCE - ) - (if next - (if (equal? 'invalid - (letter-list->col-num (take lst - next))) - NOT-A-CELL-REFERENCE - (loop (drop lst - next) - #t - row1 row2 row-absolute? - (letter-list->col-num (take lst - next)) - (letter-list->col-num (take lst next)) - col-absolute?)) - NOT-A-CELL-REFERENCE - )))] - [(equal? (car lst) #\:) - (if col1 - (loop (cdr lst) #t row1 row2 row-absolute? col1 col2 col-absolute?) - NOT-A-CELL-REFERENCE)] - [(digit? (car lst)) - (loop lst #f row1 row2 row-absolute? col1 col2 col-absolute?)] - [else NOT-A-CELL-REFERENCE])] - [else ; reading NUMBER/ROW section section - (cond [(equal? (car lst) - #\$) - (loop (cdr lst) #f row1 row2 #t col1 col2 col-absolute? ;!! - )] - [(digit? (car lst)) - (let ([next (position-of-first-satisfied-in-list - (lambda (o) - (not (digit? o))) - lst)]) - (if row1 - (if next - NOT-A-CELL-REFERENCE - (loop '() - #f - row1 - (digit-list->row-num lst) - row-absolute? - col1 col2 col-absolute?)) - (if next - (loop (drop lst next) - #f - (digit-list->row-num (take lst next)) - (digit-list->row-num (take lst next)) - row-absolute? - col1 col2 col-absolute?) - (loop '() - #f - (digit-list->row-num lst) - (digit-list->row-num lst) - row-absolute? - col1 col2 col-absolute?))))] - [(equal? (car lst) - #\:) - (loop (cdr lst) #t - row1 row2 row-absolute? - col1 col2 col-absolute?)] - [else - NOT-A-CELL-REFERENCE])]))) - - ; - ;(define pt1 '(#\a #\b #\1 #\2)) - ;(define pt1- (make-cell-reference 12 12 #f 27 27 #f)) - ;(define pt2 '(#\$ #\a #\b #\4)) - ;(define pt2- (make-cell-reference 4 4 #f 27 27 #t)) - ;(define pt3 '(#\a #\$ #\4)) - ;(define pt3- (make-cell-reference 4 4 #t 0 0 #f)) - ;(define pt4 '(#\a #\: #\e #\5)) - ;(define pt4- (make-cell-reference 5 5 #f 0 4 #f)) - ;(define pt5 '(#\z #\1 #\: #\8)) - ;(define pt5- (make-cell-reference 1 8 #f 25 25 #f)) - ;(define pt6 '(#\$ #\a #\: #\d #\1)) - ;(define pt6- (make-cell-reference 1 1 #f 0 3 #t)) - ;(define pt7 '(#\$ #\a #\$ #\0)) - ;(define pt7- (make-cell-reference 0 0 #t 0 0 #t)) - ; - ;(define (equal-cell-refs? c1 c2) - ; (and (equal? (cell-reference-row1 c1) - ; (cell-reference-row1 c2)) - ; (equal? (cell-reference-row2 c1) - ; (cell-reference-row2 c2)) - ; (equal? (cell-reference-row-absolute? c1) - ; (cell-reference-row-absolute? c2)) - ; (equal? (cell-reference-col1 c1) - ; (cell-reference-col1 c2)) - ; (equal? (cell-reference-col2 c1) - ; (cell-reference-col2 c2)) - ; (equal? (cell-reference-col-absolute? c1) - ; (cell-reference-col-absolute? c2)))) - ; - ;(equal-cell-refs? (parse-ref pt1) pt1-) - ;(equal-cell-refs? (parse-ref pt2) pt2-) - ;(equal-cell-refs? (parse-ref pt3) pt3-) - ;(equal-cell-refs? (parse-ref pt4) pt4-) - ;(equal-cell-refs? (parse-ref pt5) pt5-) - ;(equal-cell-refs? (parse-ref pt6) pt6-) - ;(equal-cell-refs? (parse-ref pt7) pt7-) - - - (define mapped-symbols - '(+ - length - = - if - quote - * - seconds - add1 - map)) - - - ;process: sexp symbol symbol symbol symbol num num -> sexp - ;INPUT: An expression EXPR, the name of lookup procedures LOOKUP, LOOKUP-ROW, LOOKUP-COL, LOOKUP-MATRIX and the current row and column - ; for the cell being processed, ROW and COL. - ;OUTPUT: blah blah blah - (define (process expr lookup lookup-row lookup-col lookup-matrix row col) - (define (cell-ref->sexp cref c-row c-col) - ;; cell-reference * num * num -> sexp - (let ([ref-row1 (cell-reference-row1 cref)] - [ref-col1 (cell-reference-col1 cref)] - [ref-row2 (cell-reference-row2 cref)] - [ref-col2 (cell-reference-col2 cref)] - [row-ref-expr (lambda (n) - (if (cell-reference-row-absolute? cref) - n - (list '+ 'row (- n c-row))))] - [col-ref-expr (lambda (n) - (if (cell-reference-col-absolute? cref) - n - (list '+ 'col (- n c-col))))]) - (if (not (= ref-row1 ref-row2)) - (if (not (= ref-col1 ref-col2)) - (list lookup-matrix - (row-ref-expr ref-row1) - (row-ref-expr ref-row2) - (col-ref-expr ref-col1) - (col-ref-expr ref-col2)) - (list lookup-col - (row-ref-expr ref-row1) - (row-ref-expr ref-row2) - (col-ref-expr ref-col1))) - (if (not (= ref-col1 ref-col2)) - (list lookup-row - (row-ref-expr ref-row1) - (col-ref-expr ref-col1) - (col-ref-expr ref-col2)) - (list lookup - (row-ref-expr ref-row1) - (col-ref-expr ref-col1)))))) - ;; end of cell reference handling - (cond [(symbol? expr) - (let ([parsed (parse-ref (string->list (symbol->string expr)))]) - (cond [parsed (cell-ref->sexp parsed row col)] - [else ;; currently allowing all symbols. - expr]))] - [(list? expr) - (if (and (not (null? expr)) - (equal? 'quote (car expr))) - expr - (map (lambda (sexp) - (process sexp lookup lookup-row lookup-col lookup-matrix row col)) - expr))] - [else expr])) - - - - - ;(define t1 "a:zz$1") - ;(define t2 "length") - ;(define t3 "(+ 3 4)") - ;(define t4 "(+ 2 a3)") - ;(define t5 "(if (= 3 (length A1)) (a2 $A3) 'dont-see)") - ;(define t6 "(ZD941 A:d3:40)") - ; - ;(define p (lambda (e) - ; (process (read (open-input-string e)) 'lookup 'lookup-row 'lookup-col 'lookup-matrix 1 1))) - ;t1 (p t1) - ;t2 (p t2) - ;t3 (p t3) - ;t4 (p t4) - ;t5 (p t5) - ;t6 (p t6) - - - ;; ISSUES: - ;; - When going from cell-references to symbols, be careful about LETTERS referring to COLUMNS - ;; and NUMBERS referring to ROWS. Some procedures are still BROKEN because of this. - ;; - ;; - Now a lookup expression has more information about what sort of region it is looking up - ;; (singleton, row, column, matrix). Use this when converting from lookup expressions to - ;; cell references. - ;; - ;; - Now that lookup expressions contain all the information contained within cell references, - ;; the intermediate step between expressions and cell references is UNNECESSARY. I should - ;; have procedure's LOOKUP-EXPR->SYMBOL that take care of everything for the UNPROCESSOR. - ;; - (define (letter-list->col-num llst) - (let ([col-num (let loop ([num -1] - [lst llst]) - (cond [(null? lst) - num] - [(capital? (car lst)) - (loop (+ (* (add1 num) 26) - (capital->col-num (car lst))) - (cdr lst))] - [(lower-case? (car lst)) - (loop (+ (* (add1 num) 26) - (lower-case->col-num (car lst))) - (cdr lst))]))]) - (if (>= col-num 702) - 'invalid - col-num))) - - ; num -> char list - (define (col-num->letter-list n) - (let loop ([num n] - [lst '()]) - (cond [(= -1 num) - lst] - [else (loop (sub1 (quotient num 26)) - (cons (integer->char (+ 97 (remainder num 26))) - lst))]))) - - ; num -> char list - (define (row-num->digit-list n) - (define help - (lambda (n) - (let ([r (remainder n 10)] - [q (quotient n 10)]) - (if (zero? q) - (list (integer->char (+ 48 n))) - (cons (integer->char (+ 48 r)) - (help q)))))) - (reverse (help n))) - - - - (define (lookup-expr->symbol expr local-row local-col) - (let* ([row-expr (cadr expr)] - [col-expr (caddr expr)] - [row-chars (cond [(number? row-expr) - (cons #\$ - (row-num->digit-list row-expr))] - [(list? row-expr) - (row-num->digit-list (+ local-row - (caddr row-expr)))])] - [col-chars (cond [(number? col-expr) - (cons #\$ - (col-num->letter-list col-expr))] - [(list? col-expr) - (col-num->letter-list (+ local-col - (caddr col-expr)))])]) - - (string->symbol (list->string (append col-chars - row-chars))))) - - (define (lookup-row-expr->symbol expr local-row local-col) - (let* ([row-expr (cadr expr)] - [col1-expr (caddr expr)] - [col2-expr (cadddr expr)] - [row-chars (cond [(number? row-expr) - (cons #\$ - (row-num->digit-list row-expr))] - [(list? row-expr) - (row-num->digit-list (+ local-row - (caddr row-expr)))])] - [col1-chars (cond [(number? col1-expr) - (cons #\$ - (col-num->letter-list col1-expr))] - [(list? col1-expr) - (col-num->letter-list (+ local-col - (caddr col1-expr)))])] - [col2-chars (cons #\: - (cond [(number? col2-expr) - (col-num->letter-list col2-expr)] - [(list? col2-expr) - (col-num->letter-list (+ local-col - (caddr col2-expr)))]))]) - (string->symbol (list->string (append col1-chars - col2-chars - row-chars))))) - - (define (lookup-col-expr->symbol expr local-row local-col) - (let* ([row1-expr (cadr expr)] - [row2-expr (caddr expr)] - [col-expr (cadddr expr)] - [row1-chars (cond [(number? row1-expr) - (cons #\$ - (row-num->digit-list row1-expr))] - [(list? row1-expr) - (row-num->digit-list (+ local-row - (caddr row1-expr)))])] - [row2-chars (cons #\: - (cond [(number? row2-expr) - (row-num->digit-list row2-expr)] - [(list? row2-expr) - (row-num->digit-list (+ local-row - (caddr row2-expr)))]))] - [col-chars (cond [(number? col-expr) - (cons #\$ - (col-num->letter-list col-expr))] - [(list? col-expr) - (col-num->letter-list (+ local-col - (caddr col-expr)))])]) - - (string->symbol (list->string (append col-chars - row1-chars - row2-chars))))) - - (define (lookup-matrix-expr->symbol expr local-row local-col) - (let* ([row1-expr (cadr expr)] - [row2-expr (caddr expr)] - [col1-expr (cadddr expr)] - [col2-expr (caddddr expr)] - [row1-chars (cond [(number? row1-expr) - (cons #\$ - (row-num->digit-list row1-expr))] - [(list? row1-expr) - (row-num->digit-list (+ local-row - (caddr row1-expr)))])] - [row2-chars (cons #\: - (cond [(number? row2-expr) - (row-num->digit-list row2-expr)] - [(list? row2-expr) - (row-num->digit-list (+ local-row - (caddr row2-expr)))]))] - [col1-chars (cond [(number? col1-expr) - (cons #\$ - (col-num->letter-list col1-expr))] - [(list? col1-expr) - (col-num->letter-list (+ local-col - (caddr col1-expr)))])] - [col2-chars (cons #\: - (cond [(number? col2-expr) - (col-num->letter-list col2-expr)] - [(list? col2-expr) - (col-num->letter-list (+ local-col - (caddr col2-expr)))]))]) - (string->symbol (list->string (append col1-chars - col2-chars - row1-chars - row2-chars))))) - - - - ; sexp * symbol * symbol *symbol *symbol num * num -> sexp - (define (unprocess expr lookup lookup-row lookup-col lookup-matrix local-row local-col) - (cond [(list? expr) - (cond [(null? expr) - '()] - [(equal? (first expr) lookup) - (lookup-expr->symbol expr local-row local-col)] - [(equal? (first expr) lookup-row) - (lookup-row-expr->symbol expr local-row local-col)] - [(equal? (first expr) lookup-col) - (lookup-col-expr->symbol expr local-row local-col)] - [(equal? (first expr) lookup-matrix) - (lookup-matrix-expr->symbol expr local-row local-col)] - [(equal? (first expr) 'quote) - expr] - [else - (map (lambda (e) - (unprocess e lookup lookup-row lookup-col - lookup-matrix local-row local-col)) - expr)])] - [else - expr])) - ; - ;(define te1 - ; '((lookup 3 4) - ; '(lookup 3 4) - ; (1 2 (lookup 0 0)) - ; (lookup-matrix (+ row 0) (+ row 5) (+ col 2) (+ col 5)) - ; (lookup-row 5 (+ col 1) (+ col 20)) - ; (lookup-col 3 39 (+ col 0)))) - ; - ;(unprocess te1 - ; 'lookup - ; 'lookup-row - ; 'lookup-col - ; 'lookup-matrix - ; 1 - ; 1) - - - (provide process unprocess) - - ) diff --git a/collects/frtime/demos/spreadsheet/quotes.ss b/collects/frtime/demos/spreadsheet/quotes.ss deleted file mode 100644 index 670bd079e8..0000000000 --- a/collects/frtime/demos/spreadsheet/quotes.ss +++ /dev/null @@ -1,75 +0,0 @@ -(module quotes mzscheme - (require net/url) - (require mzlib/list) - - (provide no-quote? stock-quote no-quote-reason) - - (define-struct no-quote (company reason)) - - #| ---------------------------------------------------------------------------- - Stock and Fund Quotes - --------------------- - - procedures: - stock-quote : String -> Number - - exceptions: - no-quote : (structure:no-quote String Symbol) - - The goal is to send a request to some quote server, - read the page line by line, and identify the quote. - - ----------------------------------------------------- - - First: where the information comes from and - how to indentify it within the page: - - the current source is Yahoo's page - - we look for a table cell that looks like - this: