Depends on what `x` is, both symbolically and in terms of binding:
(for/first ([(list _) #hash([(a) . 1])])
list)
(define-match-expander x
(syntax-rules ()
[(_ pat) (list pat)]))
(match '(ok)
[(x v)
v])
-Philip
On Fri, Nov 23, 2018 at 11:41 PM Greg Hendershott
wrote:
> > The tr
> The trouble, sadly, is that this grammar is ambiguous. In
>
> (for ([(x y) s])
> )
>
> should (x y) be parsed as a single match pattern or as two binders for a
> two-valued sequence (such as one produced by in-hash, for example)?
Unless I'm being dense, (x y) isn't a valid single matc
I actually have an experimental `in-match` macro, analogous to `in-value`:
https://docs.racket-lang.org/adjutor/Experimental.html#(form._((lib._adjutor%2Fmain..rkt)._in-match))
One open question with my version (and one of the reasons I consider this
experimental) is what should be done if one of
Maybe you could have something like (in-match ...) ?
On Fri, Nov 23, 2018 at 4:54 PM Alexis King wrote:
> The trouble, sadly, is that this grammar is ambiguous. In
>
> (for ([(x y) s])
> )
>
> should (x y) be parsed as a single match pattern or as two binders for a
> two-valued sequenc
The trouble, sadly, is that this grammar is ambiguous. In
(for ([(x y) s])
)
should (x y) be parsed as a single match pattern or as two binders for a
two-valued sequence (such as one produced by in-hash, for example)? You could
make it unambiguous in various ways, such as by requiring
> (define-syntax (match-for stx)
That's nice.
Sometimes I wish I could do the general thing -- use `match` patterns
in the binding clauses for any `for`-family form.
I often do something like this:
(define xs (list (cons 1 2) (cons 3 4)))
(for ([x (in-list xs)])
(match-define (co
I like that. I really need to level up on Racket macros!
On Wednesday, November 21, 2018 at 3:19:55 PM UTC-5, Matthew Butterick
wrote:
>
>
> On Nov 21, 2018, at 9:30 AM, Brian Adkins > wrote:
>
> Thanks guys. I think I can live with:
>
> (for ([(i j) (in-dict '(("a" . 1) ("b" . 20)))])
> (d
> On Nov 21, 2018, at 9:30 AM, Brian Adkins wrote:
>
> Thanks guys. I think I can live with:
>
> (for ([(i j) (in-dict '(("a" . 1) ("b" . 20)))])
> (display (list i j)))
>
> I suppose I could also write something analogous to in-dict that would do
> what I want. Maybe in-tuple ?
Or per
Thanks guys. I think I can live with:
(for ([(i j) (in-dict '(("a" . 1) ("b" . 20)))])
(display (list i j)))
I suppose I could also write something analogous to in-dict that would do
what I want. Maybe in-tuple ?
On Wednesday, November 21, 2018 at 11:58:49 AM UTC-5, Vincent St-Amour
wrote
`in-dict` can get you mostly there.
(for ([(i j) (in-dict '(("a" 1) ("b" 20)))])
(display (list i j)))
> (a (1))(b (20))
If you have lists of pairs instead of lists of lists, you'll get the
same result as the hash case.
Vincent
On Wed, 21 Nov 2018 10:55:23 -0600,
Brian Adkins wrote:
>
> I
You can use `in-dict` on an alist, and it will behave like the default
sequence behavior for hashes. Note that it assumes the elements are
cons pairs, not lists, so the values in your example will be '(1) and
'(20).
Sam
On Wed, Nov 21, 2018 at 11:55 AM Brian Adkins wrote:
>
> I thought it was pos
I thought it was possible to destructure a list in for, but I've been
searching/experimenting for a while without success. I noticed this example
in the docs:
(for ([(i j) #hash(("a" . 1) ("b" . 20))])
(display (list i j)))
So, I assumed I could do this:
(for ([(i j) '(("a" 1) ("b" 20))])
12 matches
Mail list logo