From d19e5f6b89039875d2a28d0b1a7e3fd06ab978d2 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 3 Mar 2016 12:34:33 -0800 Subject: [PATCH] remove examples --- br/ex/nothing/nothing-invoked-as-reader.rkt | 1 - .../nothing/nothing-invoked-as-semantics.rkt | 1 - br/ex/nothing/nothing.rkt | 39 ------------ .../expander-only/expander-invoked.rkt | 10 --- br/ex/simples/expander-only/expander.rkt | 11 ---- br/ex/simples/rapl/rapl.rkt | 61 ------------------ br/ex/simples/rapl/rapltest.rkt | 7 --- br/ex/simples/reader-only/reader-invoked.rkt | 3 - br/ex/simples/reader-only/reader.rkt | 9 --- .../stack compiler/stack-compiler-invoked.rkt | 3 - .../simples/stack compiler/stack-compiler.rkt | 33 ---------- br/ex/simples/stack/stack-invoked.rkt | 21 ------- br/ex/simples/stack/stack.rkt | 62 ------------------- br/ex/simples/stacker/stacker-lang.rkt | 37 ----------- br/ex/simples/stacker/stacker-test.rkt | 6 -- 15 files changed, 304 deletions(-) delete mode 100644 br/ex/nothing/nothing-invoked-as-reader.rkt delete mode 100644 br/ex/nothing/nothing-invoked-as-semantics.rkt delete mode 100644 br/ex/nothing/nothing.rkt delete mode 100644 br/ex/simples/expander-only/expander-invoked.rkt delete mode 100644 br/ex/simples/expander-only/expander.rkt delete mode 100644 br/ex/simples/rapl/rapl.rkt delete mode 100644 br/ex/simples/rapl/rapltest.rkt delete mode 100644 br/ex/simples/reader-only/reader-invoked.rkt delete mode 100644 br/ex/simples/reader-only/reader.rkt delete mode 100644 br/ex/simples/stack compiler/stack-compiler-invoked.rkt delete mode 100644 br/ex/simples/stack compiler/stack-compiler.rkt delete mode 100644 br/ex/simples/stack/stack-invoked.rkt delete mode 100644 br/ex/simples/stack/stack.rkt delete mode 100644 br/ex/simples/stacker/stacker-lang.rkt delete mode 100644 br/ex/simples/stacker/stacker-test.rkt diff --git a/br/ex/nothing/nothing-invoked-as-reader.rkt b/br/ex/nothing/nothing-invoked-as-reader.rkt deleted file mode 100644 index e90c683..0000000 --- a/br/ex/nothing/nothing-invoked-as-reader.rkt +++ /dev/null @@ -1 +0,0 @@ -#lang reader (submod "nothing.rkt" reader) \ No newline at end of file diff --git a/br/ex/nothing/nothing-invoked-as-semantics.rkt b/br/ex/nothing/nothing-invoked-as-semantics.rkt deleted file mode 100644 index 62219b8..0000000 --- a/br/ex/nothing/nothing-invoked-as-semantics.rkt +++ /dev/null @@ -1 +0,0 @@ -#lang s-exp "nothing.rkt" \ No newline at end of file diff --git a/br/ex/nothing/nothing.rkt b/br/ex/nothing/nothing.rkt deleted file mode 100644 index 7f518f2..0000000 --- a/br/ex/nothing/nothing.rkt +++ /dev/null @@ -1,39 +0,0 @@ -#lang racket -(provide (all-from-out racket)) - -(module reader syntax/module-reader - br/ex/nothing/nothing) - -#| - -#lang racket -(provide (all-from-out racket)) - -(module reader racket/base - (provide read read-syntax)) - -|# - -#| - -(module nothing racket - (provide (all-from-out racket)) - - (module reader syntax/module-reader - br/ex/nothing)) - -|# - -#| - -#lang racket - -(module reader syntax/module-reader - #:language '(submod br/ex/nothing semantics)) - -(module semantics racket - (provide (all-from-out racket))) - -(sleep 100000) - -|# diff --git a/br/ex/simples/expander-only/expander-invoked.rkt b/br/ex/simples/expander-only/expander-invoked.rkt deleted file mode 100644 index b6dfe6d..0000000 --- a/br/ex/simples/expander-only/expander-invoked.rkt +++ /dev/null @@ -1,10 +0,0 @@ -#lang s-exp "expander.rkt" - -"asdf" - - -41 - -1+2i - -;; but not foo \ No newline at end of file diff --git a/br/ex/simples/expander-only/expander.rkt b/br/ex/simples/expander-only/expander.rkt deleted file mode 100644 index 9d9310a..0000000 --- a/br/ex/simples/expander-only/expander.rkt +++ /dev/null @@ -1,11 +0,0 @@ -#lang br -(provide (rename-out [simple-module-begin #%module-begin]) - #%datum #%top-interaction) -(define #'(simple-module-begin expr ...) - #'(#%module-begin - (define lines (list expr ...)) - (display (format "Expressions = ~a" (length lines))) - (define numbers (filter number? lines)) - (unless (zero? (length numbers)) - (displayln (format ", numbers = ~a" (length numbers))) - (apply + numbers)))) \ No newline at end of file diff --git a/br/ex/simples/rapl/rapl.rkt b/br/ex/simples/rapl/rapl.rkt deleted file mode 100644 index 4655247..0000000 --- a/br/ex/simples/rapl/rapl.rkt +++ /dev/null @@ -1,61 +0,0 @@ -#lang br -(require racket/function) -(provide (except-out (all-from-out br) + *) - (rename-out [my+ +] [my* *]) ⌊) - -(define (⌊ largs rargs) - (let ([lenlargs (length largs)] - [lenrargs (length rargs)]) - (cond - [(zero? lenlargs) - (map (compose1 inexact->exact floor) rargs)] - [(= lenlargs lenrargs) - (map min - largs rargs)]))) - -(define (my* largs rargs) - (let ([lenlargs (length largs)] - [lenrargs (length rargs)]) - (cond - [(= lenlargs lenrargs) - (map * largs rargs)] - [(= 1 lenlargs) - (map (curry * (car largs)) rargs)] - [(= 1 lenrargs) - (my* rargs largs)] - [else - (error 'length-error)]))) - -(define (my+ largs rargs) - (let ([lenlargs (length largs)] - [lenrargs (length rargs)]) - (cond - [(= lenlargs lenrargs) - (map + largs rargs)] - [(= 1 lenlargs) - (map (curry + (car largs)) rargs)] - [(= 1 lenrargs) - (my+ rargs largs)] - [else - (error 'length-error)]))) - -(module reader br - (provide read-syntax) - (define (read-syntax src-path src-port) - (define operators '(+ ⌊ *)) - (define src-exprs (for/list ([ln (in-lines src-port)] - #:when (regexp-match #px"\\w" ln)) - (format-datum '(begin ~a) ln))) - (with-syntax ([(src-expr ...) src-exprs]) - (syntax->datum #'(module rapl "rapl.rkt" - (displayln 'src-expr) ...))))) - - - -#;(module+ test - (require rackunit) - (check-equal? (+ '(4) '(7)) '(11)) - (check-equal? (+ '(3) '(2 4 11 7 5)) '(5 7 14 10 8)) - (check-equal? (+ '(6 3 8 1) '(3)) '(9 6 11 4)) - (check-equal? (+ '(6 3 8 1) '(3 6 1 8)) '(9 9 9 9)) - (check-exn exn:fail? (λ _ (+ '(6 8 1) '(3 6 1 8))))) \ No newline at end of file diff --git a/br/ex/simples/rapl/rapltest.rkt b/br/ex/simples/rapl/rapltest.rkt deleted file mode 100644 index a8f8bc5..0000000 --- a/br/ex/simples/rapl/rapltest.rkt +++ /dev/null @@ -1,7 +0,0 @@ -#lang reader (submod "rapl.rkt" reader) - -1 3 3 7 * 8.41 - -⌊ 8.41 - -5 ⌊ 8.41 \ No newline at end of file diff --git a/br/ex/simples/reader-only/reader-invoked.rkt b/br/ex/simples/reader-only/reader-invoked.rkt deleted file mode 100644 index 124caef..0000000 --- a/br/ex/simples/reader-only/reader-invoked.rkt +++ /dev/null @@ -1,3 +0,0 @@ -#lang reader "reader.rkt" - -This is a terrible idea, and I should know because I invented it. \ No newline at end of file diff --git a/br/ex/simples/reader-only/reader.rkt b/br/ex/simples/reader-only/reader.rkt deleted file mode 100644 index c730417..0000000 --- a/br/ex/simples/reader-only/reader.rkt +++ /dev/null @@ -1,9 +0,0 @@ -#lang br -(provide read-syntax) - -(define (read-syntax src in) - (syntax-let ([#'src-str (port->string in)]) - #'(module no-name racket - (define (scramble str) - (list->string (shuffle (string->list str)))) - (regexp-replace* #px"\\w+" src-str scramble)))) diff --git a/br/ex/simples/stack compiler/stack-compiler-invoked.rkt b/br/ex/simples/stack compiler/stack-compiler-invoked.rkt deleted file mode 100644 index f68b972..0000000 --- a/br/ex/simples/stack compiler/stack-compiler-invoked.rkt +++ /dev/null @@ -1,3 +0,0 @@ -#lang reader "stack-compiler.rkt" - -(* (/ 25 14 (expt 5 2)) (/ 2 3 1) (* 10 12 15)) diff --git a/br/ex/simples/stack compiler/stack-compiler.rkt b/br/ex/simples/stack compiler/stack-compiler.rkt deleted file mode 100644 index cd31835..0000000 --- a/br/ex/simples/stack compiler/stack-compiler.rkt +++ /dev/null @@ -1,33 +0,0 @@ -#lang br - -(provide #%top-interaction) ; activates the REPL - -;; reader goes first and -;; 1) converts surface syntax into Rackety expressions (wrapping in `(inst ...)`) -;; 2) creates a module specifying semantics source (in this case, same module) -(provide read-syntax) -(define (read-syntax src-path src-input-port) - (define expr-datums (for/list ([src-line (in-lines src-input-port)] - #:when (regexp-match #px"\\w" src-line)) - (format-datum '~a src-line))) - (syntax-let ([#'(expr-stx ...) expr-datums]) ; ok to bind with non-syntax - #'(module stack-compiler-module "stack-compiler.rkt" - expr-stx ...))) - - -;; semantics always start with #%module-begin, which unwraps the content of the module and rewraps it -(provide (rename-out [stack-module-begin #%module-begin])) -(define #'(stack-module-begin expr ...) - #'(#%module-begin - (stackify (quote expr)) ...)) - - -(define (stackify quoted-expr) - (define pushes - (let loop ([x quoted-expr]) - (cond - [(list? x) - (match-define (list op args ...) x) - (append (make-list (sub1 (length args)) op) (flatten (map loop args)))] - [else x]))) - (for-each displayln (map (λ(p) (format "push ~a" p)) (reverse pushes)))) \ No newline at end of file diff --git a/br/ex/simples/stack/stack-invoked.rkt b/br/ex/simples/stack/stack-invoked.rkt deleted file mode 100644 index 430242b..0000000 --- a/br/ex/simples/stack/stack-invoked.rkt +++ /dev/null @@ -1,21 +0,0 @@ -#lang reader "stack.rkt" - -push 15 -push 12 -push 10 -push * -push * -push 1 -push 3 -push 2 -push / -push / -push 2 -push 5 -push expt -push 14 -push 25 -push / -push / -push * -push * \ No newline at end of file diff --git a/br/ex/simples/stack/stack.rkt b/br/ex/simples/stack/stack.rkt deleted file mode 100644 index 0a4296b..0000000 --- a/br/ex/simples/stack/stack.rkt +++ /dev/null @@ -1,62 +0,0 @@ -#lang br - -(provide #%top-interaction) ; activates the REPL - -;; reader goes first and -;; 1) converts surface syntax into Rackety expressions (wrapping in `(inst ...)`) -;; 2) creates a module specifying semantics source (in this case, same module) -(provide read-syntax) -(define (read-syntax src-path src-input-port) - (define inst-datums (for/list ([src-line (in-lines src-input-port)] - #:when (regexp-match #px"\\w" src-line)) - (format-datum '(inst ~a) src-line))) - (syntax-let ([#'(inst-stx ...) inst-datums]) ; ok to bind with non-syntax - #'(module stack-lang-module "stack.rkt" - inst-stx ...))) - -(define stack empty) - -;; semantics always start with #%module-begin, which unwraps the content of the module and rewraps it -(provide (rename-out [stack-module-begin #%module-begin])) -(define #'(stack-module-begin instructions ...) - #'(#%module-begin - instructions ... - (first stack))) - - -;; then file is processed like a normal Racket file. - -(provide inst) -(define (inst . args) - (if (<= 1 (length args) 2) - (let ([proc (first args)]) - (apply proc (cdr args))) - (void))) - - -(provide push) -(define (push arg) - (display "push: ") - (cond - [(procedure? arg) - (displayln (format "got ~a, replacing ~a and ~a with result" arg (first stack) (second stack) )) - (set! stack (cons (arg (first stack) (second stack)) (cddr stack)))] - [else (displayln (format "storing value ~a" arg)) - (set! stack (cons arg stack))]) - (displayln stack)) - -;; exercises - -(provide pop) -(define (pop) - (display "pop: ") - (displayln (format "got ~a" (car stack))) - (set! stack (cdr stack)) - (displayln stack)) - -(provide swap) -(define (swap) - (display "swap: ") - (displayln (format "~a and ~a" (first stack) (second stack))) - (set! stack (list* (second stack) (first stack) (cddr stack))) - (displayln stack)) \ No newline at end of file diff --git a/br/ex/simples/stacker/stacker-lang.rkt b/br/ex/simples/stacker/stacker-lang.rkt deleted file mode 100644 index 7f382b8..0000000 --- a/br/ex/simples/stacker/stacker-lang.rkt +++ /dev/null @@ -1,37 +0,0 @@ -#lang br - -(module reader br - (define (read-syntax src-path src-port) - (define src-strs (port->lines src-port)) - (define (make-datum str) (format-datum '(dispatch ~a) str)) - (define src-exprs (map make-datum src-strs)) - (inject-syntax ([#'(list src-expr ...) src-exprs]) - #'(module stacker-mod "stacker-lang.rkt" - src-expr ...))) - (provide read-syntax)) - -(define #'(stacker-module-begin reader-line ...) - #'(#%module-begin - reader-line ... - (display (first stack)))) -(provide (rename-out [stacker-module-begin #%module-begin])) - -(define stack (list 0 0)) -(define (push num) (set! stack (cons num stack))) - -(define (dispatch arg-1 [arg-2 #f]) - (cond - [(number? arg-2) (push arg-2)] - [else - (define op arg-1) - (define op-result (op (first stack) (second stack))) - (set! stack (cons op-result (drop stack 2)))])) - -#;(define dispatch - (case-lambda - [(push num) (push num)] - [(stack-op) - (define op-result (stack-op (first stack) (second stack))) - (set! stack (cons op-result (drop stack 2)))])) - -(provide #%top-interaction) \ No newline at end of file diff --git a/br/ex/simples/stacker/stacker-test.rkt b/br/ex/simples/stacker/stacker-test.rkt deleted file mode 100644 index 30c533c..0000000 --- a/br/ex/simples/stacker/stacker-test.rkt +++ /dev/null @@ -1,6 +0,0 @@ -#lang reader (submod "stacker-lang.rkt" reader) -push 4 -push 8 -+ -push 3 -* \ No newline at end of file