tosxychor
2020-11-21 12:48:11

@tosxychor has joined the channel


kokou.afidegnon
2020-11-21 17:20:30

anyone using racket-mode on emacs?


soegaard2
2020-11-21 17:20:40

yes?


kokou.afidegnon
2020-11-21 17:21:10

racket-mode is not active by default when i open a .rkt file


kokou.afidegnon
2020-11-21 17:21:20

here is my current config (require 'lang-racket) (use-package racket-mode :ensure t :mode "\\.rkt[dl]?\\'")


soegaard2
2020-11-21 17:22:03

kokou.afidegnon
2020-11-21 17:22:14

thanks


soegaard2
2020-11-21 17:23:51

;; Laptop: up-arrow key is broken, so we need an alternative. (global-set-key (kbd "M-p") #'beginning-of-buffer) I had forgotten that M-p wasn’t standard…

And now I have a laptop with a working up-arrow.


kokou.afidegnon
2020-11-21 17:24:44

:slightly_smiling_face:


kokou.afidegnon
2020-11-21 17:25:33

which one is this? (add-to-list 'auto-mode-alist '("\\.scrbl\\'" . racket-mode))


soegaard2
2020-11-21 17:26:41

What do you mean, by “which one” ?


kokou.afidegnon
2020-11-21 17:28:07

i mean what extension is .scrbl ?


soegaard2
2020-11-21 17:28:37

That’s scribble files. There aren’t a dedicated scribble-mode, so I just use racket-mode.


kokou.afidegnon
2020-11-21 17:29:57

ok, all right


phanthero
2020-11-21 18:36:02

Is there a cleaner way to do this? (match-define (vector _ ..3 child1 _ child2 _ ..2 childs my-other-children _ another-child _ ..2) children) I want children at some very specific indices


phanthero
2020-11-21 18:37:15

like specifying 3, 5, 8, 9, 11 indices, and matching those in one single statement?


samdphillips
2020-11-21 20:05:47

Personally I think it would be cleaner to just use vector-ref


phanthero
2020-11-21 20:18:29

Hmmm, I wanted to save space and do it in one line instead of doing say 5 vector-ref definition lines however… Is there any way to do that in one like instead of: (define child1 (vector-ref children 4) (define child2 ... ?


soegaard2
2020-11-21 20:20:48

(match-define (list c1 c2 c3 c4 c5) (map (lambda (n) (vector-ref children n)) (list 3 5 8 9 11))


soegaard2
2020-11-21 20:21:04

Not much cleaner though.


phanthero
2020-11-22 00:04:02

Amazing! Thanks!


phanthero
2020-11-22 01:25:01

In what contexts can you use define/match-define? I recently learned you can use them in the then-body/body of cond/match . Can you use them before the body of a lambda? Any general rules to follow here?


phanthero
2020-11-22 01:25:36

I thought you had to use let, etc in these contexts but apparently I was wrong lol…


sorawee
2020-11-22 01:44:20

You can use define and friends in any “internal definition context” and also at the module body level.

Several forms introduce internal definition context. E.g., let, match, cond, when, lambda.

In the doc, if you see body ..., that position should be in the internal definition context.



sorawee
2020-11-22 01:50:59

One exception is begin and splicing-* forms. These forms splice their body, so they essentially inherit the context from their parent context. What this means is that:

(define (foo) (begin (define x 1) x)) is OK, but:

(if #t (begin (define x 1) x) #f) is not.


phanthero
2020-11-22 02:35:29

Hmm, so I guess I can’t do it in an if statement either: (define (do-things) (if (> 5 0) (begin (match-define (vector racket-child) (vector 'racket)) (println racket-child)) (list))) The above raises an error


phanthero
2020-11-22 02:35:42

the function signature seems to be (if test-expr then-expr else-expr), so I guess that makes sense. Must be body, not expr


phanthero
2020-11-22 02:40:07

Would https://docs.racket-lang.org/reference/contracts.html be a good place to read to get a good grasp on this?


rokitna
2020-11-22 04:09:14

sorawee just described why you get an error for that case, but it’s because you’re using begin


rokitna
2020-11-22 04:09:49

you can introduce a local definition context anywhere you want by using let


rokitna
2020-11-22 04:10:43

the let doesn’t even have to have any bindings, so you can replace that (begin ...) with (let () ...)


rokitna
2020-11-22 04:14:52

Some people find (block ...) more readable than (let () ...) because the intent of introducing a local definition context is a little clearer. The block syntax is available in the racket/block module: https://docs.racket-lang.org/reference/block.html?q=block#%28form._%28%28lib._racket%2Fblock..rkt%29._block%29%29\|https://docs.racket-lang.org/reference/block.html?q=block#%28form._%28%28lib._racket%2Fblock..rkt%29._block%29%29


sorawee
2020-11-22 04:41:05

FWIW, let, if, lambda, etc. are syntaxes, so I wouldn’t use the word “function signature” with them. I would instead call it “grammar”.