Adding a variety of things, mainly def*
This commit is contained in:
parent
79627090d9
commit
4b1a4d96c8
34
remix/README
34
remix/README
|
@ -101,7 +101,9 @@ returns 1433
|
|||
TODO Generics everywhere
|
||||
https://github.com/stamourv/generic-collections
|
||||
|
||||
TODO Non-() syntax "mode"
|
||||
DONE Non-() syntax "mode"
|
||||
|
||||
TODO bindings to cooperate with {}
|
||||
|
||||
array.[{1 + 1}].(foo)
|
||||
->
|
||||
|
@ -119,7 +121,7 @@ DONE Implicit nesting in blocks
|
|||
|
||||
TODO Immutable strings only
|
||||
|
||||
TODO Remove letrec weirdness of define?
|
||||
DONE Remove letrec weirdness of define?
|
||||
|
||||
(def (f 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 use \dots as ...
|
||||
|
||||
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
|
||||
|
|
|
@ -6,18 +6,39 @@
|
|||
racket/syntax
|
||||
syntax/parse))
|
||||
|
||||
;; xxx add extensibility
|
||||
(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)
|
||||
[(_ (x . 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
|
||||
(define-syntax (def* stx)
|
||||
(raise-syntax-error 'def* "illegal outside of block" stx))
|
||||
|
||||
;; xxx add extensibility
|
||||
(define-syntax (def*-internal 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)
|
||||
(syntax/loc stx
|
||||
(let () . body))]))
|
||||
|
@ -143,9 +164,13 @@
|
|||
(syntax-parse stx
|
||||
[(_#%dot _λ body:expr)
|
||||
(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)
|
||||
(syntax-parse stx
|
||||
[(_ body:expr)
|
||||
|
@ -168,7 +193,10 @@
|
|||
(remix-block . answer-body)
|
||||
(remix-cond . more))))]))
|
||||
|
||||
(provide def
|
||||
(provide def def*
|
||||
;; xxx add these into the default precedence system
|
||||
(rename-out [def ≙]
|
||||
[def* ≙*])
|
||||
(rename-out [remix-λ λ]
|
||||
[remix-cond cond])
|
||||
#%brackets
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
["#i1.2 .a" (#%dot 1.2 a)]
|
||||
["1 .2.a" (#%dot 1 (#%dot 2 a))]
|
||||
["a.#i1.2" (#%dot a 1.2)]
|
||||
;; ((sprite.bbox).ul).x
|
||||
["a.b.c" (#%dot a (#%dot b c))]
|
||||
["a.(b c)" (#%dot a (b c))]
|
||||
["(a b).c" (#%dot (a b) c)]
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
(def (draw)
|
||||
(circle 'yellow 5)))
|
||||
|
||||
(big-bang (new rocket))
|
||||
(big-bang (rocket.new))
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
x)
|
||||
|
||||
;; 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 z (+ x x))
|
||||
z]
|
||||
|
@ -59,7 +60,8 @@
|
|||
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
|
||||
{3 + 4})
|
||||
(module+ test
|
||||
|
@ -119,9 +121,26 @@
|
|||
(module+ test
|
||||
v11)
|
||||
|
||||
;; ...
|
||||
;; ,,,
|
||||
;; ooo
|
||||
;; …
|
||||
;; ≙ is a synonym for def, and because of the {} rules, is a binary
|
||||
;; operator.
|
||||
{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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user