From 72d1c9d58b747363ddcdc151d631870004b30879 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Sat, 3 Oct 2015 19:58:20 -0400 Subject: [PATCH] first version now that reader is in place --- remix/README | 109 +++++++++++++++++---------- remix/core.rkt | 4 +- remix/{seq => exp}/list.rkt | 0 remix/exp/reader.rkt | 4 +- remix/lang/reader.rkt | 16 +++- remix/num/gen0.rkt | 3 + remix/stx/read.rkt | 10 --- remix/stx0.rkt | 67 ++++++++++++++++ remix/{examples => tests}/rocket.rkt | 0 remix/tests/simple.rkt | 25 ++++++ 10 files changed, 182 insertions(+), 56 deletions(-) rename remix/{seq => exp}/list.rkt (100%) create mode 100644 remix/num/gen0.rkt delete mode 100644 remix/stx/read.rkt create mode 100644 remix/stx0.rkt rename remix/{examples => tests}/rocket.rkt (100%) create mode 100644 remix/tests/simple.rkt diff --git a/remix/README b/remix/README index edc1d7d..f804d8b 100644 --- a/remix/README +++ b/remix/README @@ -1,10 +1,16 @@ -- @ everywhere +TODO @ everywhere -- {} infix +DONE {} particular => (#%braces) -- [] particular => (#%brackets ) +TODO {} infix -- . in ids => x.y => (%#dot x y) +DONE [] particular => (#%brackets) + +DONE default #%brackets is (let () ....) + +DONE . in ids => x.y => (%#dot x y) + +TODO #%dot is extensible transformer (struct posn ((complex x) y)) @@ -37,23 +43,28 @@ obj.(move 5 6) (define (f (box x)) stuff) -- robby's request +TODO robby's request + (haskell-style (f '()) = 0 (f (cons x l)) = {1+ (f l)}) +TODO (define+ (f case) body) - -- No set! (use data-structure mutation and :=) +TODO No set! (use data-structure mutation and :=) (def (var x) 5) {x := 6} -- No effects or expressions at top-level (controversial, mf says wrong) [set-once!] -- "Versioned" libraries -- Make macros less weird and more like programs, by... -- Unified matching (syntax-parse/match/etc) -- Unified templates (syntax, quasiquote, etc) +TODO No effects or expressions at top-level (controversial, mf says wrong) [set-once!] + +TODO "Versioned" libraries + +TODO Make macros less weird and more like programs, by... + +TODO Unified matching (syntax-parse/match/etc) + +TODO Unified templates (syntax, quasiquote, etc) If x is a list, then... @@ -69,10 +80,13 @@ obj.(move 5 6) => (apply + (map f x)) -- Pattern matching everywhere -- New structs (more reflective information, representation control, sealing) -- Implicit units and interfaces (with properties) -- Bare-bones /base +TODO Pattern matching everywhere + +TODO New structs (more reflective information, representation control, sealing) + +TODO Implicit units and interfaces (with properties) + +DONE Bare-bones /base #lang racket/base (define BASE-NAMES (namespace-mapped-symbols (make-base-namespace))) @@ -82,9 +96,10 @@ obj.(move 5 6) returns 1433 -- Generics everywhere +TODO Generics everywhere https://github.com/stamourv/generic-collections -- Non-() syntax "mode" + +TODO Non-() syntax "mode" array.[{1 + 1}].(foo) -> @@ -94,44 +109,56 @@ array.[{1 + 1}].(foo) {x := z + 13} {p.x + p.y}) -- Implicit nesting in blocks +DONE Implicit nesting in blocks (def (f x) (def y 17) (+ x y)) -- Immutable strings only -- Remove letrec weirdness of define? +TODO Immutable strings only + +TODO Remove letrec weirdness of define? (def (f x) (def [even (λ (x) (odd x))] [odd (λ (x) (even x))]) (even x)) -- "define"-transformers for attaching meta-information to definitions, like documentation, tests, contracts, types, etc -- Bindings & keywords everywhere -- Less representation contraints -- Meaningless eq? semantics -- Literate programming and inline docs easily -- No case-lambda -- Optional traditional numbers (num/generic => +) -- Optional non-coercing number tower (num/{fl,fx,i32,i64,f32,f64,nat,int,rational,real}) --- with maybe impl (num/*/maybe) --- with overflow errors impl (num/*/exn) --- with modulo-X impl (num/*/modulo) --- with modulo-X & carry impl (num/*/carry) -- More unicode! -- Unboxed, raw data -- Remove multiple values? -- Rocket-strength super cut: +TODO "define"-transformers for attaching meta-information to definitions, like documentation, tests, contracts, types, etc + +TODO Bindings & keywords everywhere +---- DONE cond + +TODO Less representation contraints + +TODO Meaningless eq? semantics + +TODO Literate programming and inline docs easily + +DONE No case-lambda + +TODO Optional traditional numbers (num/generic => +) + +TODO Optional non-coercing number tower (num/{fl,fx,i32,i64,f32,f64,nat,int,rational,real}) +---- TODO with maybe impl (num/*/maybe) +---- TODO with overflow errors impl (num/*/exn) +---- TODO with modulo-X impl (num/*/modulo) +---- TODO with modulo-X & carry impl (num/*/carry) + +TODO More unicode! + +TODO Unboxed, raw data + +TODO Remove multiple values? + +TODO Rocket-strength super cut: λ.(+ $0 $1) -- Don't use English in exceptions and have more structured exns [demo on raco/pkg] +TODO Don't use English in exceptions and have more structured exns [demo on raco/pkg] -- (Define-default-type Number x y z) +TODO (Define-default-type Number x y z) [for define things too] -- zos don't appear to users (switch to interp if no write access) +TODO zos don't appear to users (switch to interp if no write access) -- (define+ (f case) body) diff --git a/remix/core.rkt b/remix/core.rkt index 777481f..0456e0d 100644 --- a/remix/core.rkt +++ b/remix/core.rkt @@ -1,2 +1,4 @@ #lang racket/base -(provide #%module-begin) +(provide #%module-begin + require + provide) diff --git a/remix/seq/list.rkt b/remix/exp/list.rkt similarity index 100% rename from remix/seq/list.rkt rename to remix/exp/list.rkt diff --git a/remix/exp/reader.rkt b/remix/exp/reader.rkt index 9f02b34..2404d80 100644 --- a/remix/exp/reader.rkt +++ b/remix/exp/reader.rkt @@ -50,4 +50,6 @@ ["(a b).c" (#%dot (a b) c)] ["(a b).(c d)" (#%dot (a b) (c d))] ["(a b).[3]" (#%dot (a b) (#%brackets 3))] - ["({1})" ((#%braces 1))])) + ["({1})" ((#%braces 1))] + ["remix/stx.0" (#%dot remix/stx 0)] + ["(require remix/stx.0)" (require (#%dot remix/stx 0))])) diff --git a/remix/lang/reader.rkt b/remix/lang/reader.rkt index 0d8b65d..c7a2ba0 100644 --- a/remix/lang/reader.rkt +++ b/remix/lang/reader.rkt @@ -1,5 +1,15 @@ (module reader syntax/module-reader remix/core - #:read remix:read - #:read-syntax remix:read-syntax - (require (prefix-in remix: remix/stx/read))) + #:read at:read + #:read-syntax at:read-syntax + #:wrapper1 + (λ (t) + (parameterize ([read-square-bracket-as-paren #f] + [read-curly-brace-as-paren #f] + [read-square-bracket-with-tag #t] + [read-curly-brace-with-tag #t] + [read-accept-dot #f] + [read-accept-infix-dot #f] + [read-cdot #t]) + (t))) + (require (prefix-in at: scribble/reader))) diff --git a/remix/num/gen0.rkt b/remix/num/gen0.rkt new file mode 100644 index 0000000..1083d82 --- /dev/null +++ b/remix/num/gen0.rkt @@ -0,0 +1,3 @@ +#lang racket/base +;; xxx fill out +(provide + < /) diff --git a/remix/stx/read.rkt b/remix/stx/read.rkt deleted file mode 100644 index 97d2f8b..0000000 --- a/remix/stx/read.rkt +++ /dev/null @@ -1,10 +0,0 @@ -#lang racket/base - -(define (:read ip) (:read-syntax #f ip)) - -(define (:read-syntax name ip) - eof) - -(provide - (rename-out [:read read] - [:read-syntax read-syntax])) diff --git a/remix/stx0.rkt b/remix/stx0.rkt new file mode 100644 index 0000000..352fd2a --- /dev/null +++ b/remix/stx0.rkt @@ -0,0 +1,67 @@ +#lang racket/base +(require (for-syntax racket/base + syntax/parse)) + +(define-syntax (def stx) + (syntax-parse stx + [(_ x:id . body:expr) + (syntax/loc stx + (define x (remix-block . body)))] + [(_ (x:id . args:expr) . body:expr) + (syntax/loc stx + (def x (remix-λ args . body)))])) + +(define-syntax (remix-block stx) + ;; xxx gather up defs and turn into bind + (syntax-parse stx + [(_ . body:expr) + (syntax/loc stx + (let () . body))])) + +;; xxx also make it a #%dot transformer that is cut. +(define-syntax (remix-λ stx) + (syntax-parse stx + ;; xxx transform args into bind plus what racket λ needs + [(_ (arg:id ...) . body:expr) + (syntax/loc stx + (λ (arg ...) (remix-block . body)))])) + +(define-syntax (#%brackets stx) + (syntax-parse stx + [(_ . body:expr) + (syntax/loc stx + (remix-block . body))])) + +(define-syntax (#%braces stx) + (syntax-parse stx)) + +(define-syntax (#%dot stx) + (syntax-parse stx)) + +(define-syntax (remix-cond stx) + (syntax-parse stx + #:literals (#%brackets) + [(_ (~and before:expr (~not (#%brackets . any:expr))) ... + (#%brackets #:else . answer-body:expr)) + (syntax/loc stx + (remix-block before ... . answer-body))] + [(_ (~and before:expr (~not (#%brackets . any:expr))) ... + (#%brackets question:expr . answer-body:expr) + . more:expr) + (syntax/loc stx + (remix-block before ... + (if question + (remix-block . answer-body) + (remix-cond . more))))])) + +(provide def + (rename-out [remix-λ λ] + [remix-cond cond]) + #%brackets + #%braces + #%dot + #%app + #%datum + module + module* + module+) diff --git a/remix/examples/rocket.rkt b/remix/tests/rocket.rkt similarity index 100% rename from remix/examples/rocket.rkt rename to remix/tests/rocket.rkt diff --git a/remix/tests/simple.rkt b/remix/tests/simple.rkt new file mode 100644 index 0000000..c87d9f2 --- /dev/null +++ b/remix/tests/simple.rkt @@ -0,0 +1,25 @@ +#lang remix +(require remix/stx0 + remix/num/gen0) + +(def x + (def a 40) + (def b 2) + (+ a b)) + +(def (f x y) + (+ [(def z (+ x x)) z] y)) + +(def (g x) + (cond + [(< x 100) "100"] + (def z (/ x 2)) + [(< z 100) "div 100"] + [#:else "other"])) + +(module+ test + x + (f x x) + (g 50) + (g 199) + (g 200))