tli2
2019-12-3 10:09:51

@tli2 has joined the channel


tli2
2019-12-3 10:14:25

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.


soegaard2
2019-12-3 10:27:26

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


soegaard2
2019-12-3 10:35:06

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


soegaard2
2019-12-3 10:40:57

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


pezi_pink
2019-12-3 11:04:18

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:


ryanc
2019-12-3 11:20:28

@pezi_pink glad you found the talk helpful, thanks!


ryanc
2019-12-3 11:22:11

@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


laurent.orseau
2019-12-3 11:59:50

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


soegaard2
2019-12-3 12:00:20

Nice trick!


george.privon
2019-12-3 15:23:46

@george.privon has joined the channel


racket192
2019-12-3 16:02:23

@racket192 has joined the channel


deactivateduser60718
2019-12-3 16:31:35

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?


deactivateduser60718
2019-12-3 16:40:34

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


soegaard2
2019-12-3 18:54:17

dmitryhertz
2019-12-3 19:16:46

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:


soegaard2
2019-12-3 19:21:08

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?


dmitryhertz
2019-12-3 19:22:58

Thanks a lot!:+1: Figuring out…


samdphillips
2019-12-3 19:40:23

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


soegaard2
2019-12-3 19:40:49

Yeah, that’s the sensible thing to do…


soegaard2
2019-12-3 19:42:21

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.


samdphillips
2019-12-3 19:42:56

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


dmitryhertz
2019-12-3 20:03:49

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


dmitryhertz
2019-12-3 20:04:13

This works for my use case as expected :-)


soegaard2
2019-12-3 20:04:36

Great!


public
2019-12-3 22:51:12

@public has joined the channel


soegaard2
2019-12-3 22:57:48

Some indentation would have helped too.


notjack
2019-12-3 23:03:27

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
2019-12-4 02:20:45

@marc162 has joined the channel


levaremzyani
2019-12-4 03:13:03

@levaremzyani has joined the channel


deactivateduser60718
2019-12-4 06:17:59

dmitryhertz
2019-12-4 06:59:55

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