> What have you used them for?
https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
It's a macro that allows me to bundle expected inputs with expected
outputs for those inputs together with a contract definition, meaning
I have a tighter coupling of test-cases together with definitions of
functions without a bunch of `(module+ test ...)`.
Further challenges:(define/cti (square2&add x y)contract:(integer? integer? . -> . integer?)tests:[2 3 -> 13][1 2 -> 5][-4 4 -> 31]implementation:(+ (expt x 2) (expt y 2)))
Care to post one of your examples, with a bit of commentary?
Dan
(struct foo ([x : Integer]))
along with a constructor, predicate, and accessors.(define-type foo (Pairof 'foo (List Integer)))
#lang typed/racket
(require (for-syntax racket/base syntax/parse racket/syntax))(define-syntax (struct2 stx)
(syntax-parse stx #:datum-literals (:)
[(_ name:id ([f*:id : t*] ...))
#:with ((name-f* i*) ...)
(for/list ([f (in-list (syntax-e #'(f* ...)))]
[i (in-naturals 1)])
(list (format-id stx "~a-~a" (syntax-e #'name) (syntax-e f)) i))
#:with Name (format-id stx "~a" (string-titlecase (symbol->string (syntax-e #'name))))
#:with name? (format-id stx "~a?" (syntax-e #'name))
(syntax/loc stx (begin
(define-type Name (Pairof 'name (Listof Any)))
(provide Name)
(define (name (f* : t*) ...) : Name
(list 'name f* ...))
(provide name)
(define (name-f* (p : Name)) : t*
(cast (list-ref p 'i*) t*))
...
(provide name-f* ...)
(define (name? (v : Any)) : Boolean
(and (list? v) (not (null? v)) (eq? 'name (car v)))) ))]))(struct2 posn ([x : Real]
[y : Real]))
(struct2 block ([x : Real]
[y : Real]
[color : Symbol]))
(struct2 tetra ([center : Posn]
[blocks : (Listof Block)]))
(struct2 world ([tetra : Tetra]
[blocks : (Listof Block)]))(: posn=? (-> Posn Posn Boolean))
(define (posn=? p1 p2)
(and (= (posn-x p1) (posn-x p2))
(= (posn-y p1) (posn-y p2))))(provide posn=?)
On Apr 12, 2016 7:53 AM, "George Neuner" <gneu...@comcast.net> wrote:
>
> My most common uses are to handle database connections and
> to embed free form SQL into Racket code.
Care to post one of your examples, with a bit of commentary?
`((h1 "SVG test")(div(input (@ (type "range") (value ,($ radius))(min "10") (max "95") (step "5")))(br) (br)(button (@ (on-click "swap")) "Change color"))(svg (@ (width "200") (height "200"))(circle (@ (cx "100") (cy "100") (r ,($ radius))(stroke "green") (stroke-width "4")(fill ,($ fill)))))))
<h1>SVG test</h1><div><input type="range" value="{{radius}}" min="10" max="95" step="5"><br> <br><button on-click="swap">Change color</button></div><svg width="200" height="200"><circle cx="100" cy="100" r="{{radius}}"stroke="green" stroke-width="4" fill="{{fill}}"></circle></svg>
(define-syntax ($ stx)(syntax-parse stx[(_ var:id)(with-syntax ([v (datum->syntax stx(format "{{~a}}" (syntax->datum #'var)))])#'v)][(_ (fn:id args:id ...))(with-syntax ([js (datum->syntax stx(format "{{~a(~a)}}"(syntax->datum #'fn)(string-join(map (compose(λ (x) (format "~a" x))syntax->datum)(syntax->list #'(args ...)))", ")))])#'js)]))
Compared to George's macro, it uses syntax-parse for pattern-matching rather than match, and still uses datum->syntax / syntax->datum, but more locally within with-syntax.
On Apr 12, 2016, at 4:54 PM, Anthony Carrico <acar...@memebeam.org> wrote:Please view Asumu's google hangout on typed racket