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)
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
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:
>
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
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
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
6 matches
Mail list logo