massung
2021-7-27 19:02:47

Can someone provide some details on how for for hash sequences provide both the key and value? I’d like to do something similar for a custom stream. I’m not sure if it’s just the stream returning multiple values or a list that’s destructured by for or perhaps something else? For example, would stream-map accept multiple values as well (assuming it’s just a stream)?


samth
2021-7-27 19:03:36

It’s a sequence that produces multiple values


samth
2021-7-27 19:04:34

streams (not sequences) are single-valued


notjack
2021-7-27 19:18:35

A for/sequence form would be handy for implementing custom sequences that produce multiple values



sorawee
2021-7-27 20:00:39

@samth stream in general can be multi valued


sorawee
2021-7-27 20:01:19

The ones in the standard library just decide to not support it


samth
2021-7-27 20:01:30

we should just fix that


notjack
2021-7-27 20:07:18

Also I’d still like a for/sequence form to construct sequences where I don’t want to pay the cost of memoizing the elements


sorawee
2021-7-27 20:13:11

https://github.com/racket/racket/pull/3333\|https://github.com/racket/racket/pull/3333 was an attempt to do that, but I don’t know if I should port stuff from the stream-values library to the standard library


samth
2021-7-27 20:14:04

yes, for/stream/values seems like a strict improvement on for/stream


sorawee
2021-7-27 20:28:11

Well, it’s slower :(


samth
2021-7-27 20:28:37

why is it slower?


sorawee
2021-7-27 20:29:05

Memoizing multiple values


sorawee
2021-7-27 20:30:19

@notjack I should create a variant that doesn’t have memoization. That’s very easy to do


notjack
2021-7-27 20:31:02

a variant of for/stream? I actually don’t think that’s a good idea. If memoization in streams is optional, what’s the point of having separate stream and sequence APIs?


sorawee
2021-7-27 20:32:54

Sequence supports non stream. That’s the only reason for the concept iiuc


sorawee
2021-7-27 20:34:25

So if you want to create a sequence, creating a non memoizing stream is one of the best way


notjack
2021-7-27 20:46:02

I would rather write (for/sequence ([x ...]) ...) than (for/stream #:no-memoize ([x ...]) ...) Keeps the conceptual split simpler IMO



sorawee
2021-7-28 03:53:04

Have a question about syntax-parse.

I have:

(define-syntax-parse-rule (test1 (main sub ...)) (list (list '(main sub) ...))) (test1 (1 2 3 4)) ;=> '(((1 2) (1 3) (1 4))) And this works as expected.

Now, let’s add one more ellipsis, and it no longer works:

(define-syntax-parse-rule (test2 (main sub ...) ...) (list (list '(main sub) ...) ...)) (test2 (1 2 3 4) (4 5 6 8)) ;=> syntax: incompatible ellipsis match counts for template in: ... I understand why it errors, but would it be possible for this to work?

Also, what are possible workarounds? One answer is doing code generation in a syntax class. Another is awkwardly creating main* whose attribute arity matches sub. Do I miss other options?


shu--hung
2021-7-28 04:52:33

I don’t know the answer to this but I’m curious about the expected output. If it were (test2 (1 2 3) (4 5 6)) then I can see that the expected output is '(((1 2) (4 3)) ((1 5) (4 6))) what about your example?


sorawee
2021-7-28 04:58:18

Hmm, that’s not the output that I expect, but I can see that it’s a sensible output.


sorawee
2021-7-28 04:59:55

Yeah, nvm then. The property x => y then x ... => y ... simply doesn’t hold for syntax-parse.


shu--hung
2021-7-28 05:02:06

ah so you want ellipsis saturation from the outside rather than from the inside


sorawee
2021-7-28 05:02:12

yep


sorawee
2021-7-28 05:03:32

So the workaround for this case would be:

(define-syntax-parse-rule (test2 clause:parse-this-thing ...) (list clause.code-gen ...))


sorawee
2021-7-28 05:03:52

where parse-thing-thing generates the code like test1


sorawee
2021-7-28 05:04:50

It’s annoying when parse-this-thing requires additional information from other syntax fragments. Cuz I need to reparse clause within the #:with clause.


sorawee
2021-7-28 05:05:54

E.g.,

(define-syntax-parse-rule (test2 sth raw-clause ...) #:with ({~var clause (parse-this-thing #'sth)} ...) (attribute raw-clause) (list clause.code-gen ...))