On 8/30/2018 11:36 AM, David Storrs 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."

I've gone through the page on pattern matching and been unable to find anything.  I've tried various things with #:when but that doesn't seem to do what I need -- it only controls whether the match succeeds or fails.

I could write multiple clauses or do the defaulting before the match, but that's a lot of bother and it feels like there should be a more elegant solution.  Have I missed anything?


Match doesn't allow dynamic patterns.  The only way I can think you might do it is to do a wildcard match, check the values manually, and then force match to backtrack if necessary.  You can use *failure-cont* if you want to continue trying other matches in the same context.

George




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