Adding a variety of things, mainly def*

This commit is contained in:
Jay McCarthy 2015-11-17 16:54:15 -05:00
parent 79627090d9
commit 4b1a4d96c8
5 changed files with 93 additions and 15 deletions

View File

@ -101,7 +101,9 @@ returns 1433
TODO Generics everywhere TODO Generics everywhere
https://github.com/stamourv/generic-collections https://github.com/stamourv/generic-collections
TODO Non-() syntax "mode" DONE Non-() syntax "mode"
TODO bindings to cooperate with {}
array.[{1 + 1}].(foo) array.[{1 + 1}].(foo)
-> ->
@ -119,7 +121,7 @@ DONE Implicit nesting in blocks
TODO Immutable strings only TODO Immutable strings only
TODO Remove letrec weirdness of define? DONE Remove letrec weirdness of define?
(def (f x) (def (f x)
(def [even (λ (x) (odd x))] (def [even (λ (x) (odd x))]
@ -169,4 +171,32 @@ TODO zos don't appear to users (switch to interp if no write access)
TODO only use syntax-parse and define-simple-macro TODO only use syntax-parse and define-simple-macro
TODO use \dots as ...
TODO add a threading macro TODO add a threading macro
TODO types and other information in syntax-local-value
TODO support :keyword (and keyword:?)
TODO @literate
TODO @docs
DONE [] for Rec def blocks or def* for let* behavior
and Search for def in block and trans to local-def which sees body
TODO [] for def & def* transformer
TODO Meta def & def* trans for more expansion (docs and test), static
info (types), and def transformers (types), maybe syntax ---
transformer (can change define to define-syntax/etc) vs expander
(expands to a different syntax) --- no ability to add args to
functions!
TODO operator overloading definitions of + and ones that check the
types for float/int/fixnum/etc
TODO greg's defs
https://github.com/greghendershott/defn
https://github.com/greghendershott/def-jambda

View File

@ -6,18 +6,39 @@
racket/syntax racket/syntax
syntax/parse)) syntax/parse))
;; xxx add extensibility
(define-syntax (def stx) (define-syntax (def stx)
(syntax-parse stx (syntax-parse stx
[(_ x:id . body:expr) [(_ x:id . body:expr)
(syntax/loc stx (syntax/loc stx
(define x (remix-block . body)))] (define x (remix-block . body)))]
[(_ (x:id . args:expr) . body:expr) [(_ (x . args:expr) . body:expr)
(syntax/loc stx (syntax/loc stx
(def x (remix-λ args . body)))])) (def x (remix-λ args . body)))]))
(define-syntax (remix-block stx) (define-syntax (def* stx)
;; xxx gather up defs and turn into bind (raise-syntax-error 'def* "illegal outside of block" stx))
;; xxx add extensibility
(define-syntax (def*-internal stx)
(syntax-parse stx (syntax-parse stx
[(_ (x:id . def-body:expr) bind-body:expr)
(syntax/loc stx
(let ([x (remix-block . def-body)])
(remix-block . bind-body)))]
[(_ ((x . args:expr) . def-body:expr) bind-body:expr)
(syntax/loc stx
(def*-internal (x (remix-λ args . def-body)) bind-body))]))
(define-syntax (remix-block stx)
(syntax-parse stx
#:literals (def*)
[(_ (~and (~not (def* . _)) before:expr) ...
(def* . def*-body:expr) . after:expr)
(syntax/loc stx
(let ()
before ...
(def*-internal def*-body after)))]
[(_ . body:expr) [(_ . body:expr)
(syntax/loc stx (syntax/loc stx
(let () . body))])) (let () . body))]))
@ -143,9 +164,13 @@
(syntax-parse stx (syntax-parse stx
[(_#%dot body:expr) [(_#%dot body:expr)
(syntax/loc stx (syntax/loc stx
(remix-cut body))]))]) (remix-cut body))]
;; xxx test this
[(_#%dot bodies:expr ...)
(syntax/loc stx
(remix-cut (#%dot bodies ...)))]))])
;; xxx actually implement cut ;; xxx actually implement cut with _ or $ as the var accessor
(define-syntax (remix-cut stx) (define-syntax (remix-cut stx)
(syntax-parse stx (syntax-parse stx
[(_ body:expr) [(_ body:expr)
@ -168,7 +193,10 @@
(remix-block . answer-body) (remix-block . answer-body)
(remix-cond . more))))])) (remix-cond . more))))]))
(provide def (provide def def*
;; xxx add these into the default precedence system
(rename-out [def ]
[def* ≙*])
(rename-out [remix-λ λ] (rename-out [remix-λ λ]
[remix-cond cond]) [remix-cond cond])
#%brackets #%brackets

View File

@ -45,6 +45,7 @@
["#i1.2 .a" (#%dot 1.2 a)] ["#i1.2 .a" (#%dot 1.2 a)]
["1 .2.a" (#%dot 1 (#%dot 2 a))] ["1 .2.a" (#%dot 1 (#%dot 2 a))]
["a.#i1.2" (#%dot a 1.2)] ["a.#i1.2" (#%dot a 1.2)]
;; ((sprite.bbox).ul).x
["a.b.c" (#%dot a (#%dot b c))] ["a.b.c" (#%dot a (#%dot b c))]
["a.(b c)" (#%dot a (b c))] ["a.(b c)" (#%dot a (b c))]
["(a b).c" (#%dot (a b) c)] ["(a b).c" (#%dot (a b) c)]

View File

@ -19,4 +19,4 @@
(def (draw) (def (draw)
(circle 'yellow 5))) (circle 'yellow 5)))
(big-bang (new rocket)) (big-bang (rocket.new))

View File

@ -22,7 +22,8 @@
x) x)
;; but of course def supports function definitions. [] is NOT the same ;; but of course def supports function definitions. [] is NOT the same
;; as () and defaults to expanding to a block definition ;; as (), it parses as #%brackets and defaults to expanding to a block
;; definition
(def (f x y) (def (f x y)
(+ [(def z (+ x x)) (+ [(def z (+ x x))
z] z]
@ -59,7 +60,8 @@
path(X, Y)? path(X, Y)?
} }
;; {} is also not (), but is an infix macro ;; {} is also not (), it is parsed as #%braces, and by default is an
;; infix macro
(def v7 (def v7
{3 + 4}) {3 + 4})
(module+ test (module+ test
@ -119,9 +121,26 @@
(module+ test (module+ test
v11) v11)
;; ... ;; ≙ is a synonym for def, and because of the {} rules, is a binary
;; ,,, ;; operator.
;; ooo {v33 33}
;; … (module+ test
v33)
(def v28
{(f x) x + x}
(f 14))
(module+ test
v28)
;; def* allows nested binding inside blocks
(def v64
(def* x 2)
(def* x {x + x})
(def* x {x + x})
(def* x {x + x})
(def* x {x + x})
(def* x {x + x})
x)
(module+ test
v64)