
@tli2 has joined the channel

Hi, folks
I’m reading this blog on Algorithm && Lisp, I’m trying to translate the Common Lisp version to Racket.
https://lisp-univ-etc.blogspot.com/2019/08/programming-algorithms-data-structures.html
Here’s my initial:
(struct point
([parent #:mutable]
[size #:mutable]
[name])
#:transparent)
(define (root p)
(if (not (point-parent p))
p
(let ([root_cur (root (point-parent p))])
(set-point-parent! p root_cur)
root_cur)))
(define (union p_left p_right)
(let* ([p1 (root p_left)]
[p2 (root p_right)]
[size1 (point-size p1)]
[size2 (point-size p2)])
(if (>= size1 size2)
(begin
(set-point-size! p1 (+ size1 size2))
(set-point-parent! p2 p1))
(begin
(set-point-size! p2 (+ size1 size2))
(set-point-parent! p1 p2)))))
I was wondering if anyone could help to take a look at it? I think the with
and values
in Common Lisp is much more clear than my version.

What is the syntax and semantics of the with
form of Common Lisp? I can’t find it in the hyperspec.

An alternative to with
and values
: (define-syntax (swap! stx)
(syntax-case stx ()
[(_ x y) #'(let ([t x]) (set! x y) (set! y x))]))
(define (union p_left p_right)
(define p1 (root p_left))
(define p2 (root p_right))
(define n1 (point-size p1))
(define n2 (point-size p2))
(when (< n1 n2) (swap! p1 p2))
(set-point-size! p1 (+ n1 n2))
(set-point-parent! p2 p1))

And here is one which avoids swap
: (define (union p1 p2 [root1 #f] [root2 #f])
(define r1 (or root1 (root p1)))
(define r2 (or root2 (root p2)))
(define n1 (point-size r1))
(define n2 (point-size r2))
(cond
[(< n1 n2) (union p2 p1 root2 root1)]
[else (set-point-size! r1 (+ n1 n2))
(set-point-parent! r2 r1)]))

thanks for the link, that’s some interesting code. This project is basically the entire grammar for ILASM, which will form only the base of the actual languages to be built. Should be interesting :smile:

@pezi_pink glad you found the talk helpful, thanks!

@popa.bogdanp syntax-parse is definitely intended to support uses like that, and it looks like you’ve already found the annotations (#:commit
, ~!
, etc) to avoid excessive backtracking

For the sake of completeness, swap!
can be also written (set!-values (a b) (values b a))

Nice trick!

@george.privon has joined the channel

@racket192 has joined the channel

I’m splitting up documentation for my package. It looks like scribblings
in info.rkt
will let me place links in inappropriately prominent places, so I want to sanity check something here: (define scribblings '(("scribblings/guide/index.scrbl" (multi-page) (tools))
("scribblings/reference/index.scrbl" (multi-page) (library))
("scribblings/how-tos/index.scrbl" (multi-page) (omit))
("scribblings/tutorials/index.scrbl" (multi-page) (omit))))
Given the apparent intention of each document shown in the paths, do the categories make sense?

~I’m actually having trouble getting the links to function on the doc index in the first place~ Realized I shouldn’t be using index.scrbl
everywhere.

Sometimes goto
is handy. https://www.reddit.com/r/Racket/comments/e4rh15/pollards_rho_algorithm/

Hello @greg ! I propose to add possibility to get back to the current-buffer
in fn racket--send-region-to-repl
(line 574 in racket-repl.el
). I’d like to enable such behavior because of my case: I run 2 emacsclients, the first one (with code) is placed at the primary monitor, the second one (with repl) is placed at the secondary monitor. As result after calling racket-send-last-sexp
I just get two windows with racket-repl. Thank you for the great emacs package and attention! :slightly_smiling_face:

Hi. Pehaps we can figure something out?
My .emacs is here:
https://gist.github.com/soegaard/942a3074513655292816e0b79c466620
I added an attempt to get cmd-d and cmd-e to racket-mode. Maybe you can modify these to your use-case?

Thanks a lot!:+1: Figuring out…

I just briefly skimmed that and thought, just do a big letrec

Yeah, that’s the sensible thing to do…

I was in a playful mood, so I attempted to write a macro that expanded labels B: that ends with a colon into (label B).
I couldn’t get the context of label
correct, so I removed it again.

hah I was going to say why don’t you make the labels less clunky :slightly_smiling_face:

@soegaard2 your idea works! I just a little bit rewrote racket-send-last-sexp
to this one: (defun my-racket-send-last-sexp ()
"Send the previous sexp to the Racket REPL.
When the previous sexp is a sexp comment the sexp itself is sent,
without the #; prefix."
(interactive)
(let ((source-buffer (current-buffer)))
(racket--send-region-to-repl (racket--repl-last-sexp-start)
(point))
(switch-to-buffer source-buffer)))

This works for my use case as expected :-)

Great!

@public has joined the channel

Some indentation would have helped too.

What if label
encapsulated the statements? Like this:
(label B1
(n ← N)
(x ← 5)
(x- ← 2)
(k ← 1)
(l ← 1))
(label B2
(when (prime? n)
(return n)))
(label B3 ...)

@marc162 has joined the channel

@levaremzyani has joined the channel

Polyglot 2.0 Update: https://sagegerard.com/polyglot-doc-update.html

+1 I forgot to mention: M-x customize-variable pop-up-windows then set it to nil