
@tbrooke has joined the channel

@abmclin has joined the channel

@code has joined the channel

is there a way to get a list of all the generics defined in racket (bonus points if packages are included). When writing new structs I find it helpful to provide as much of a familiar interface as possible, when it makes sense. But I find it difficult to discover the existing gen:

This search is probably the best thing: https://docs.racket-lang.org/search/index.html?q=gen%3A

Another interesting api-design discussion: https://github.com/racket/racket/pull/2726

Maybe I should ask the question here? https://racket.slack.com/archives/C09L257PY/p1588937569265700

apply +
instead of sum
. Also ckeck out flsum
if you’re worried about precision on floats

(for lists)

You might want to check out transducers in rebellion.
(transduce (in-range 1 11)
(mapping sqr)
#:reduce into-sum))

Or closer to what you have written is the collections library which defines map to work over sequences. You would need to write sum to work over sequences in that case as well.

@laurent.orseau Thanks, but apply doesn’t work for stream. :’(

Then what do you have against for
?

@dan has joined the channel

I thought sum
from the math library also did everything flsum
did with precision on floats? Also about apply
with stream-map
it would be nice if apply
worked on streams. I believe Alexis King’s functional or collection library does that

(require data/collection)
(apply + (map sqr (in-range 1 11)))
In Alexis King’s library, map
and apply
both work on streams so this is fine

sequence transformations are so hard to read when they’re inside-out

You mean “when they’re inside-out so hard to read sequence transformation are”?

What about postfix notation (((1 11 in-range) sqr map) + apply)
:slightly_smiling_face:

is that just currying with extra steps?

I messed up a little though because the order of the arguments isn’t consistently reversed, showing that it’s not great either

(like 1 11 instead of 11 1 if I were to reverse everything)

Eh, if you want it in dataflow order I would rather use a threading macro than postfix notation (require data/collection threading)
(~>> (in-range 1 11) (map sqr) (apply +))

Nah, that’s cheating!

Although really (for/sum ([i (in-range 1 11)]) (sqr i))
isn’t bad at all

Real coders code in mirror notation (((11 1 egnar-ni) rqs pam) + ylppa)

of course with an editor that displays the original and the mirror string, we’re not savages.

Sometimes Alexis King’s libraries are just so good that using them feels like cheating

:slightly_smiling_face:

Using racket is cheating already ;)

@jaz has joined the channel

@greg has joined the channel

API design question: should there be for/{weak,mutable}-hash{,eq,eqv}
? When I want to create a mutable hash using for comprehension, I always ended up with a for
with hash-set!
inside the loop.
Alternatively, I can use for/hash
and then convert it to mutable hash…… wait a minute, there’s no direct function to convert immutable hash to mutable hash!! What choice do I have? hash -> list of pairs -> mutable hash? Hmmm….

I think a for/mutable-hash
form is reasonable

For conversion, I think every collection type should have a way to make one that’s a fresh copy of any other one

in Rebellion the way I do that is I add a sequence->foo
form for constructing a foo
collection

Yeah, n types of collections with O(n^2) conversion functions don’t sound nice.

sequence->set
, sequence->vector
, and sequence->mutable-vector
would all be good additions to Racket in my opinion

Just to clarify, you think for/mutable-hasheq
is not reasonable?

For hashes and other dictionary-like collections, the Racket idiom would probably be a sequence->hash
function that accepts a two-valued sequence

Oh no

but I don’t personally like that, because multivalued sequences are awkward

Currently Racket convention is representing a dict with a list of conses

oof that would be even worse

Well, I mean, it exists already

So I disagree with two-valued sequence. It just adds one more thing that we need to support

a sequence-of-conses-to-hash function exists already?

Not sequence of conses to hash

I’m less sold on the idea that eq-based and eqv-based hashes are worth the effort

list of conses to hash does exist, yeah. But something more generic is needed to avoid n^2 conversion functions

There’s a list of conses to hash

So sequence of conses to hash?

At least, it’s a generalization of list of cons

And not a totally new thing

Like two valued sequence

Yeah. On the one hand, it’s got precedent, it’s easily achievable, and it doesn’t force you to deal with multivalued sequences.

on the other…cons
, car
, and cdr
are awful names and dotted pair notation is confusing to read

In rebellion I just made a standard (entry key value)
struct and used that

I feel I’m going to repeat arguments in https://github.com/racket/racket/pull/3076. Yes, I agree with everything that you said, but I find fragmentation far worse than these problems. It would be a good idea to clean these things up for Rhombus, but for Racket, I would prefer to improve things while following the existing convention.

Yeah I don’t think adding an entry
struct to base racket is a viable solution

I’m more wondering if it’s worth adding something to the main distribution at all

I’m not sure it’s a good idea to try and fill the gap if there isn’t a good enough way to do it

For this example, out of those options, I think the data/collection
notation is easiest to read. I like the similarity between:
and the informal:
(edit: formatting code for Slack)

actually, what if (f x y zs …)
was a shorthand for (sequence-apply f x y zs)
?

(+ (map sqr (in-range 1 11)) ...)

Hm… I would feel a lot more comfortable about that if every variable had a notion of ellipsis-depth and it acted like syntax-templates, just without the syntax part

Or maybe not every variable, but like a pattern-matching form, that had ellipses, but for normal values and not just syntax objects

I was about to suggest a splat notation like that, but prefix instead so that it wouldn’t take as much paren-matching-by-eye effort:
(+ @(map sqr (in-range 1 11)))

minimizing the amount of new notation is important to me

it’s a new notation either way

I was thinking of something where rest args, match patterns, syntax patterns, syntax templates, and function calls would all use …
(and maybe …+
too)

mine is more along the lines of reusing ~@

(define (max xs ...+)
(for/fold ([greatest (first xs)]) ([x (rest xs)])
(if (> x greatest) x greatest)))

hmm, I see what you mean

and I probably would actually prefer that extra level of parens ~@
has, but I didn’t think that’d be flattering

I was also going to combine that with a suggestion for a quasiquotation-shaped map
operation:
This way it gets really close to that (+ (sqr 1) ...)
expansion

anyway, just meant it as a wild idea :)

I think we’re still firmly in the wild-ideas phase here so it’s welcomed :p

That quasiquote thing reminded me of a talk by Guy Steele on Computer-Science Metanotation, where he proposed thinking about repetitions in a quasiquote-unquote kind of way

oh? that sounds very relevant XD

2017 ACM PPoPP Keynote: It’s Time for a New Old Language: https://youtu.be/7HKbjYqqPPQ ClojureConj 2017 Invited Talk - Guy Steele: https://youtu.be/dCuZkaaou0Q

The analogy to quasiquoting comes at 58:39 in the PPoPP 2017 video: https://youtu.be/7HKbjYqqPPQ?t=3519 The analogy to quasiquoting comes at 52:52 in the ClojureConj 2017 video: https://youtu.be/dCuZkaaou0Q?t=3172

fascinating, thank you so much XD

Soon after that slide, he talks about a potential underline notation where everything that’s underlined is constant and everything that isn’t underlined shares an index that varies according to the overline.
The underlining approach reminds me of explicit rewriting macros, where every variable that isn’t local to the expansion needs to be annotated/unquoted, as opposed to the style of gensym
/generate-temporaries
where it’s the local variables that must be explicitly designated.

explicit renaming*