Re: [racket-users] How do I provide a name as both a match expander and contracted function?

2019-12-30 Thread Sorawee Porncharoenwase
IIUC, this is what Alex Knauth did in
https://github.com/mbutterick/txexpr/pull/8.

On Mon, Dec 30, 2019 at 7:07 PM Jack Firth  wrote:

> If I'm making my own data types, one common thing I want to do is make
> smart constructors that double as match expanders. I could use
> `define-match-expander` with two transformers, but then I can't add a
> contract to the smart constructor with `contract-out`. If I try to write
> this:
>
> (provide
>  (contract-out
>   [foo (->* (widget?) (#:name symbol?) foo?)]))
>
> (define (make-foo widget #:name [name #f])
>   ...)
>
> (define-match-expander foo
>   (syntax-parser [(_ widget) #'(? foo? (app foo-widget widget))])
>   (syntax-parser [(_ arg ...) #'(make-foo arg ...)]))
>
> ...then the use of `contract-out` hides the fact that `foo` is a match
> expander. What should I do?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/2dac85e9-8058-437c-b5bc-a92f659c02f6%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegvhNMz85CQOtXMHQjyQTym7xS9huNVikJVoXXVYhsS0AQ%40mail.gmail.com.


[racket-users] How do I provide a name as both a match expander and contracted function?

2019-12-30 Thread Jack Firth
If I'm making my own data types, one common thing I want to do is make 
smart constructors that double as match expanders. I could use 
`define-match-expander` with two transformers, but then I can't add a 
contract to the smart constructor with `contract-out`. If I try to write 
this:

(provide
 (contract-out
  [foo (->* (widget?) (#:name symbol?) foo?)]))

(define (make-foo widget #:name [name #f])
  ...)

(define-match-expander foo
  (syntax-parser [(_ widget) #'(? foo? (app foo-widget widget))])
  (syntax-parser [(_ arg ...) #'(make-foo arg ...)]))

...then the use of `contract-out` hides the fact that `foo` is a match 
expander. What should I do?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/2dac85e9-8058-437c-b5bc-a92f659c02f6%40googlegroups.com.