tbrooke
2020-5-8 13:08:01

@tbrooke has joined the channel


abmclin
2020-5-8 13:20:04

@abmclin has joined the channel


code
2020-5-8 14:26:56

@code has joined the channel


code
2020-5-8 14:55:08

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:


samth
2020-5-8 14:56:18

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


samth
2020-5-8 14:57:02

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


wanpeebaw
2020-5-8 15:33:21

laurent.orseau
2020-5-8 15:47:40

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


laurent.orseau
2020-5-8 15:48:19

(for lists)


samdphillips
2020-5-8 15:58:57

You might want to check out transducers in rebellion.

(transduce (in-range 1 11) (mapping sqr) #:reduce into-sum))


samdphillips
2020-5-8 16:00:42

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.


wanpeebaw
2020-5-8 16:08:33

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


laurent.orseau
2020-5-8 16:09:23

Then what do you have against for?


dan
2020-5-8 16:17:21

@dan has joined the channel


alexknauth
2020-5-8 17:54:45

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


alexknauth
2020-5-8 17:56:58

(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


notjack
2020-5-8 18:04:05

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


laurent.orseau
2020-5-8 18:05:17

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


laurent.orseau
2020-5-8 18:06:17

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


notjack
2020-5-8 18:06:55

is that just currying with extra steps?


laurent.orseau
2020-5-8 18:07:48

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


laurent.orseau
2020-5-8 18:08:09

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


alexknauth
2020-5-8 18:14:24

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 +))


laurent.orseau
2020-5-8 18:14:41

Nah, that’s cheating!


alexknauth
2020-5-8 18:16:13

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


laurent.orseau
2020-5-8 18:18:36

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


laurent.orseau
2020-5-8 18:19:13

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


alexknauth
2020-5-8 18:21:45

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


laurent.orseau
2020-5-8 18:27:41

:slightly_smiling_face:


laurent.orseau
2020-5-8 18:28:07

Using racket is cheating already ;)


jaz
2020-5-8 18:32:00

@jaz has joined the channel


greg
2020-5-8 20:15:27

@greg has joined the channel


sorawee
2020-5-9 00:07:06

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….


notjack
2020-5-9 00:11:38

I think a for/mutable-hash form is reasonable


notjack
2020-5-9 00:12:13

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


notjack
2020-5-9 00:13:27

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


sorawee
2020-5-9 00:13:27

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


notjack
2020-5-9 00:14:35

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


sorawee
2020-5-9 00:15:09

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


notjack
2020-5-9 00:15:41

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


sorawee
2020-5-9 00:15:55

Oh no


notjack
2020-5-9 00:16:06

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


sorawee
2020-5-9 00:16:40

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


notjack
2020-5-9 00:17:06

oof that would be even worse


sorawee
2020-5-9 00:17:15

Well, I mean, it exists already


sorawee
2020-5-9 00:17:37

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


notjack
2020-5-9 00:18:01

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


sorawee
2020-5-9 00:18:30

Not sequence of conses to hash


notjack
2020-5-9 00:18:47

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


notjack
2020-5-9 00:19:31

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


sorawee
2020-5-9 00:19:32

There’s a list of conses to hash


sorawee
2020-5-9 00:19:49

So sequence of conses to hash?


sorawee
2020-5-9 00:19:56

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


sorawee
2020-5-9 00:20:04

And not a totally new thing


sorawee
2020-5-9 00:20:11

Like two valued sequence


notjack
2020-5-9 00:20:29

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


notjack
2020-5-9 00:21:08

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


notjack
2020-5-9 00:21:49

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


sorawee
2020-5-9 00:24:48

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.


notjack
2020-5-9 00:25:21

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


notjack
2020-5-9 00:25:38

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


notjack
2020-5-9 00:27:01

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


rokitna
2020-5-9 00:58:23

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)


notjack
2020-5-9 01:04:00

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


notjack
2020-5-9 01:04:55

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


alexknauth
2020-5-9 01:05:51

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


alexknauth
2020-5-9 01:06:47

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


rokitna
2020-5-9 01:07:28

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)))


notjack
2020-5-9 01:08:54

minimizing the amount of new notation is important to me


rokitna
2020-5-9 01:09:28

it’s a new notation either way


notjack
2020-5-9 01:10:08

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


rokitna
2020-5-9 01:12:01

mine is more along the lines of reusing ~@


notjack
2020-5-9 01:12:05

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


notjack
2020-5-9 01:12:25

hmm, I see what you mean


rokitna
2020-5-9 01:13:38

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


rokitna
2020-5-9 01:16:37

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


rokitna
2020-5-9 01:18:43

anyway, just meant it as a wild idea :)


notjack
2020-5-9 01:22:56

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


alexknauth
2020-5-9 01:25:01

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


rokitna
2020-5-9 01:25:19

oh? that sounds very relevant XD


alexknauth
2020-5-9 01:27:18

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


alexknauth
2020-5-9 01:33:26

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


rokitna
2020-5-9 01:44:35

fascinating, thank you so much XD


rokitna
2020-5-9 01:50:28

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.


rokitna
2020-5-9 01:52:53

explicit renaming*