
Like adjacent-remove-duplicates
doesn’t exist either, despite being O(n) for sorted lists, vs O(n^2) for remove-duplicates

Does your function check the arity of the input function to know how to group? You seem to use it with a unary predicate and with a binary function

Predicate as in it it’s used to determine true/false? No.

It is the case for the first example, where there are “two groups” because char-whitespace?
returns either #t
ot #f

But for the second example, the output is any number

So what’s required in the first argument is any function of arity one.

Probably possible to extend that to more than one

I’m also not sure what you mean by binary function.

There probably should be an optional argument for the sameness function

Defaulting to equal?
which is what I use in the above two examples.

Ok, makes all sense now :slightly_smiling_face:

Sounds like you could have a similar interface as sort
, with an extract-key
and a comparator. There are quite a number of functions that have the same interface (such as my proposal for best
), we should try to use a unified interface.

If we align with sort, that would be: (define (adjacent-group-by lst comparator #:key [extract-key values])...)
but it doesn’t make too much sense here, so maybe we should have a more general interface like: (define (fun lst #:key [extract-key values] #:comparator [cmp equal?] #:cache-keys? [cache? #f]) ...)
where the default arguments could of course change depending on the function

A findf
function could also use this interface

a transducer-based version is possible if I ever get around to finishing https://github.com/jackfirth/rebellion/pull/331, which adds a grouping-consecutive
transducer

nice!

(transduce "abc def ghi"
(indexing char-whitespace?)
(grouping-consecutive into-list)
#:into into-list)


yes, this one too

We should use the comparators in data/order

Can there be a sequence-chaperone
function? Is that possible to add?

Keep in mind that the word comparator has several variants

I usually assume the Java one

What would that do?

let me add a guard around each element like with sequence-map
, but without changing the underlying type of the sequence so it returns a sequence that’s equal?
to the original

The one in sort
returns a boolean, not reflexive.
The one in C++ returns an integer.
The one in group-by
returns a boolean, reflexive and symmetric.

Re comparators, sometimes the use is for total order, sometimes is just for = or not =. I’m hoping we can use data/order for both

I usually use “comparator” to mean “thing that can tell you which of two values is bigger”, and “equivalence relation” to mean “thing that can tell you if two values are the same”

Is this for mutable sequences? Not sure what the guard would be for.

Like, (sequence/c number?)
should be a chaperone contract. It’s currently an impersonator contract, even though there’s no real reason it needs the ability to impersonate the original sequence.

hello, is there any gui app written in Racket like https://github.com/alex-hhh/ActivityLog2? i’m considering Racket for (multi-platform) desktop app and weighting it against some statically-compiled languages like Nim…

I was thinking you can overload equal?
and encapsulate in a struct maybe?

@spdegabrielle Did you keep track somewhere of the gui apps out there?

@sjaniska You can start searching for gui on the list of packages: https://pkgd.racket-lang.org/pkgn/search?q=gui

(not everything is relevant of course)

implementations of gen:equal+hash
aren’t consulted unless both values are of the same struct type, so although I could make a (struct chaperoned-sequence (original guard) …)
type, I wouldn’t be able to get it to compare equal?
to original
.

A few of mine: mred-designer, color-flood, towers-gui

Yeah, I thought that would be the case :confused:

regrettably, I think the only way to make this work would be to add some sort of optional method for chaperoning to the sequence interface and allow implementations to provide it

do you consider thar set of widgets is rich-enough for “general” gui apps?

@poga.po has joined the channel

Yes, but sometimes you have to derive the class to override some methods, for example to react to key presses

Mred-designer is a gui builder btw


@sjaniska a list would make a good wiki page - please post any here and I’ll do it this evening

Also, in case it isn’t clear, DrRacket is a cross platform GUI app written in Racket. There are also several as part of the games
package.

I think it’s possible. You’d have to extend the sequence interface, though, since individual sequence types would have to implement it themselves.

Otherwise you can attach the desired properties through a hashtable, so that eq? doesn’t change, but then it’s the burden of the callees to check the table for the guard

I know about DrRacket and I must say that having well-support built-in GUI DSL is tempting feature in comparison with some other language where GUI bindings are usually one-man show, not well supported etc. which makes those (statically-compiled) languages less attractive in comparison with Racket. Imho, Racket’s GUI is not popularized well-enough…

I wish I knew the distribution of software engineering; 1 software dev companies 2 companies that software is their business but don’t distribute/sell (FAANGs) 3 companies that do other things but code is written every day to keep the business going (i work for a hospital!)

@spdegabrielle you’re using Racket?

(for the hospital work)

No

I’m not using Racket at work

Racket CS has one cool capability. It allows us to convert non-negative integer to English text easily

(define (calc s)
(second
(regexp-match
#px"returned (.*?) values to single value return context"
s)))
(define (number->english-string n)
(define out
(with-handlers ([exn:fail? (lambda (e) (calc (exn-message e)))])
(values (apply values (range 0 n)))))
(if (eq? out 0)
"one"
out))
(number->english-string 0)
(number->english-string 1)
(number->english-string 2)
(number->english-string 100)