On Mon, May 18, 2020 at 04:51:26PM -0400, Sam Tobin-Hochstadt wrote:
> The systematic way to do it is to use `inst`.
>
> Here's the first example:
>
> (define hash-list : (Listof (Pair Symbol Natural)) (list))
> ((inst sort (Pair Symbol Natural) String) hash-list string<? #:key (λ
> ((p : (Pair Symbol Natural))) (symbol->string (car p))) #:cache-keys?
> #t)
>
> This program works already, but I wasn't sure what the `y` binding was
> doing in your second example:
>
> (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol
> Natural) (in-list hash-list))
> (k : Symbol (in-value (car p)))
> (v : Natural (in-value (cdr p)))
> #:when (not (= v 1))
> )
> (cons k v))
I got this second example to work, but it's still a black art to me.
(printf "~s~%"
`(define pname-map (hasheqv
,@(for*/list : (Listof (List Symbol Natural))
((p : (Pair Symbol Natural)(in-list (hash->sorted-list pname-map)))
(k : Symbol (in-value (car p)))
(v : Natural (in-value (cdr p)))
#:when (not (= v 1))
)
(list k v) ; TODO: I changed this; original used a temporary variable 'y'.
))))
I really had to get rid of the y variable. Even providing an explicit type for that
variable did not work.
It kept complaining about the overloaded function 'cons'.
Presumably I'd have to use inst on the 'cons' function to clear this up comprehensibly,
but 'cons' does not appear explicitly in the code at all.
It's probably embedded in the code generated by quasiquote. The 'inst' tril doesn't
work very well on code generated by a macro when the macro itself doesn't generate
'inst's.
I do not understand how eliminating the temporary variably 'y' made it all work.
-- hendrik