matching M-N instances

23 views
Skip to first unread message

David Storrs

unread,
Sep 13, 2020, 8:18:41 PM9/13/20
to Racket Users
Using the 'match' form, is there a straightforward way to have optional items in a pattern?  For example:

(match records [(list (? string? name) 0..1  phone-numbers ..1) 'ok])

This would match a list of phone numbers that might or might not have the owner's name (either as a single string or as two strings) on the front.

I know that I could do it with an 'or' pattern, or by having multiple clauses in the match, but those get repetitive and verbose when part of the pattern is a struct* used for decomposing multiple fields of a (potentially nested) struct, which is a thing I do a lot.

Reply all
Reply to author
Forward
0 new messages