> On Dec 12, 2016, at 10:40 AM, Winston Weinert <winston+...@ml1.net> wrote:
> 
> Thanks. I wrote a rudimentary syntax transformer, but really I don't know the 
> best way to work around this -- and I'm not very proficient with syntax 
> transformers. I could put all of my code which I would prefer to be top level 
> in a procedure/let context, but I don't really think this is the solution I'm 
> looking for.
> 
> For example, I want to put some example data read by my port->list helper 
> procedure in the top level for experimenting, but I'm sure there are more 
> serious use cases for my issue.
> 
> Here's a very basic solution I just came up with. Any ideas would be 
> appreciated:
> 
> #lang typed/racket
> 
> (define-syntax guard
>  (syntax-rules ()
>    [(_ a b)
>     (let ()
>       (unless (a b)
>         (error "guard failed"))
>       b)]))
> 
> (define ls (port->list read (open-input-string "1 2 3 4")))
> (for ([n (guard (λ (ls) (andmap number? ls)) ls)])
>  (displayln (* n n)))

Your `guard` form is just like an `assert`:

http://docs.racket-lang.org/ts-reference/Utilities.html#%28def._%28%28lib._typed-racket%2Fbase-env%2Fextra-procs..rkt%29._assert%29%29
 
<http://docs.racket-lang.org/ts-reference/Utilities.html#(def._((lib._typed-racket/base-env/extra-procs..rkt)._assert))>

So you should be able to use assert instead (with the arguments flipped).

#lang typed/racket

(define ls (port->list read (open-input-string "1 2 3 4")))
(for ([n (assert ls (λ (ls) (andmap number? ls)))])
 (displayln (* n n)))

However typed racket's inference isn't good enough to deal with this, and it 
needs an annotation on the lambda:

#lang typed/racket

(define ls (port->list read (open-input-string "1 2 3 4")))
(for ([n (assert ls (λ ([ls : (Listof Any)]) (andmap number? ls)))])
 (displayln (* n n)))

Alex Knauth

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to