
@michael.hamel80 has joined the channel

can anyone recommend a Racket repl with syntax highlighting?

DrRacket? Or do you mean for use in a terminal?

yes, in a terminal

I don’t know of one, sorry

Maybe Rash does something similar, but I haven’t checked: https://docs.racket-lang.org/rash/index.html

(it’s not a racket repl, but my thinking was that maybe it does syntax color, which could then be extracted to make a repl)

@ury.marshak has joined the channel

re: Repl with syntax highlighting. Have you considered doing your repl in an emacs window? I use racket-mode and get syntax highlighting in the Racket repl as well as in racket files. @ego

How can I get all combinations of two lists?

Like a ‘power set’ in mathematics?

I’m not sure, I don’t know what a power set is. I thought it was called permutations in maths?

If I use for/list I think that it takes one member of each list in turn. I want each member of the first list to take each member of the second list in turn, if that makes sense.

I last studied maths 22 years ago though, so I could very easily be wrong!

Use for*/list
.

@sorawee Great, I’ll try that. Thanks.

@greg: this is not directly related to Racket Mode, but seems to be a problem from interaction between Evil and Racket Mode. Suppose I have:
[a]bc #'def
where [...]
indicates the current point. If I run evil-forward-word-begin
, it moves the point to:
abc #[']def
which is incorrect. Note that this problem only occurs in Racket Mode. If I switch to text-mode, it would move the point to:
abc [#]'def
correctly.
This is especially annoying when I “delete a word forward” using Evil, because it would result in 'def
rather than #'def
.
Do you have an idea what could cause this behavior?

Just for the sake of knowledge, this is called a Cartesian product and there’s even a racket function for it: https://docs.racket-lang.org/reference/pairs.html?q=Cartesian#%28def._%28%28lib._racket%2Flist..rkt%29._cartesian-product%29%29\|https://docs.racket-lang.org/reference/pairs.html?q=Cartesian#%28def._%28%28lib._racket%2Flist..rkt%29._cartesian-product%29%29 However, if you have just two lists, don’t even bother with it and just use for*/list.

Thanks, I actually have six lists. It’s all my possible project references of the form “AAA001” up to “ZZZ999”. Turns out there are quite a lot of them and this is a slow way of dealing with them :(

Try an experiment to see if it’s because the #
is not a legal character in a “word”. Is there anything else like that? \
maybe? _
? There’s some modify-syntax-entry
stuff in racket-common.el
so I would guess this isn’t an accident just not what you want. Googling the function that you mention shows a lot of people suffer. :slightly_smiling_face:

I’m sure emacs is probably the best option… but I’ve never touched emacs before and I’m new to Racket, so I didn’t really feel like tackling two new things at the same time

I wonder if it’s possible to get “just the repl” part of emacs+racket-mode working inside of VS Code or Sublime Text

Indeed that’s 17 million possibilities. Depending on what you do for each possibility, it can take a while to go through. (cartesian-product is a rather slow function, i still recommend for*/list). Is there any way you can avoid going through it all?

I think I’ve solved it. The function I need is simply to find the next consecutive reference, given an existing one. I tried for*/list but it wouldn’t finish. I switched it to for*/stream, and that still took about 10 seconds. I’ve now written a cond statement which destructures the reference into a list of chars and then manually increases it by checking each of the fields in turn from the last to the first to work out which characters to change. It’s quick now, but not as cool as using a stream!

would you be willing to share the code? this sounds like an interesting problem domain and I’d like to see if the for
forms could be improved to handle your use case.

Sure, though I’m surprised it is interesting. I’ll post it on a pastebin and send the link, if that works?

@notjack I’ve deleted the for*/list code though that didn’t work. Do you want me to dig it up for you? I’m happy to, if that is what you’re interested in.

I’m mostly interested in the working code that you ended up with. Pastebin would be great.

(I work on stream processing libraries for fun so I sometimes have an odd definition of “interesting”)


What I was doing before was creating a stream of matter references in order and then finding the reference after the current one. With 17 million references in total, it seemed to take quite awhile.

As a follow-up from my previous pull request, I converted most of the plot tests to use draw steps, rather than relying on manual testing. The new pull request is a bit large, but most of the files are data files in suport of the tests (some tests generated more than 200 test plots and there are about test 600 plots in total). I will leave this pull request open for about a week before merging it, to allow interested people to look at it and provide feedback.

Impressive

Here’s my take at this problem:
(define (next-reference r)
(define supported-chars
`((,char-upper-case? . #\A)
(,char-numeric? . #\0)))
(define (on-done done? acc)
(cond
[done? (list->string acc)]
[else (error "Maximum matter reference reached")]))
(unless (= 6 (string-length r))
(error "Ill-formed reference"))
(for/fold ([done? #f] [acc '()] #:result (on-done done? acc))
([char (reverse (string->list r))])
(cond
[done? (values #t (cons char acc))]
[else
(define next-char (integer->char (add1 (char->integer char))))
(apply
values
(or (for/or ([mode (in-list supported-chars)])
(and ((car mode) char)
(if ((car mode) next-char)
(list #t (cons next-char acc))
(list #f (cons (cdr mode) acc)))))
(error "Ill-formed reference")))])))
(next-reference "ABC999")

@cancandan has joined the channel

That’s very kind of you to code that. I have to admit, I don’t quite understand it, but it is definitely better than mine - shorter, less repetition of functions, and all contained in one function. Mine has its own module, the code is so long. I’ll scratch my head over the for/fold stuff and see if I can work it out.