On Thu, Aug 30, 2018 at 12:20 PM, Matthew Butterick <m...@mbtype.com> wrote:

>
> On Aug 30, 2018, at 8:36 AM, David Storrs <david.sto...@gmail.com> wrote:
>
> I'd like to be able to write something like this:
>
> (match (hash 'a 1 'b 2)
>   [(hash-table ('a a) ('b b) ('c c))  (list a b c)])
>
> ...except with something that says "if 'c isn't present, that's fine.  Use
> this value instead."
>
>
>
> Perhaps move 'c out of the match pattern?
>
> (let ([h (hash 'a 1 'b 2)])
>   (match h
>     [(hash-table ('a a) ('b b))
>      (list a b (hash-ref h 'c (λ () 'other-val)))]))
>

Yep.  Or, alternatively, I could do it up front:

(define h (hash 'a 1))
(match (hash-set h 'b ((lambda (h) (hash-ref h 'b #f)) h))
  [(hash-table ('a a) ('b b)) (list a b)])

=>  '(1 #f)

That works, but it's pretty ugly.

-- 
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