Re: [racket-users] Matching groups of optional elements

2020-05-05 Thread Laurent
If you insist on using match, you can do it with a loop: #lang racket (define (parsel l) (match l [(list-rest req1 req2 r) (cons (list req1 req2) (let loop ([r r]) (match r ['() '()] [(list-rest opt1 opt2 opt3 opt4 r2)

Re: [racket-users] Matching groups of optional elements

2020-05-04 Thread David Storrs
Thanks, Phillip. On Mon, May 4, 2020 at 10:44 PM Philip McGrath wrote: > Depending on your requirements, I would consider using `syntax-parse` at > runtime: this is easily written with its `~seq` patterns, and you get nicer > error reporting. > > Here's an example—I use syntax classes for

Re: [racket-users] Matching groups of optional elements

2020-05-04 Thread David Storrs
Fantastic. Thanks, Michael. On Mon, May 4, 2020 at 10:39 PM Michael MacLeod wrote: > I'm not sure this is possible with only using `match` patterns. A > combination of the `list-rest` and `app` patterns as well as the `in-slice` > procedure from `racket/sequence` should do the trick, though: >

Re: [racket-users] Matching groups of optional elements

2020-05-04 Thread Philip McGrath
Depending on your requirements, I would consider using `syntax-parse` at runtime: this is easily written with its `~seq` patterns, and you get nicer error reporting. Here's an example—I use syntax classes for clarity, but they aren't necessary, if you prefer to be more concise: #lang racket

Re: [racket-users] Matching groups of optional elements

2020-05-04 Thread Michael MacLeod
I'm not sure this is possible with only using `match` patterns. A combination of the `list-rest` and `app` patterns as well as the `in-slice` procedure from `racket/sequence` should do the trick, though: #lang racket (require racket/match) (define (collect-optional-vals x) (for/list ([y

[racket-users] Matching groups of optional elements

2020-05-04 Thread David Storrs
I'm trying to write a parser for a CSV file with optional columns. Simplified version: There are 2 mandatory columns, after which there can be 0+ 4-column groups describing a person. Each group has the same column headers. ; legal column arrangements: RequiredA RequiredB RequiredA RequiredB