kellysmith12.21
2020-11-3 12:03:27

Is there any runtime overhead for using let* instead of let?


kellysmith12.21
2020-11-3 12:04:14

(I know about the differences in variable scope, I’m just curious about the performance.)


phanthero
2020-11-3 12:18:11

I’m a beginner too, but I think it was explained that let* are just nested lets, so it would have whatever performance inefficiency nested lets bring (shouldn’t be much though). I will let someone more experienced confirm for sure.


laurent.orseau
2020-11-3 12:28:07

You can check this with the Macro Stepper in DrRacket, and you will see that let* expands into nested lets. However, you may need to count on the compiler too. Unfortunately, since Racket CS produces machine code, raco decompile won’t tell you what this does.


phanthero
2020-11-3 12:47:16

Maybe doing a time on let and let* somehow would allow you to assess the efficiency? Or is this a bad method?


phanthero
2020-11-3 12:48:20

eg. computing factorial with both methods


soegaard2
2020-11-3 12:48:22

@kellysmith12.21 I would be surprised if you could measure a difference between let and let*.


sorawee
2020-11-3 12:59:27

Runtime overhead: no. Compile-time overhead: possible. There are several bug reports where several nested scopes at the order of thousands (so, not a program a human would write) makes the macroexpander run for a really long time. I believe the complexity is quadratic in these cases.


laurent.orseau
2020-11-3 13:15:02

Human: “Hey compiler, you see the bunch of apples under the tree over there? Pick one apple, bring it back to me, then go back to pick another apple and so on. Okay?” Compiler: “Hey human, how about you do it yourself? Okay?”


jgeddes
2020-11-3 16:39:30

An emacs/racket-mode/image question: My emacs used to show images in the Racket REPL (using racket-mode) but no longer does so. The images appear to be given to emacs as SVG (at least, emacs’ complaint is that it hasn’t been built with SVG support). Did Racket/racket-mode always show images as SVG? Is there some way of asking for, say, PNG instead (which my emacs can display)?


greg
2020-11-3 16:44:54

I remember using “pass” for a musical event filter feature, thinking of how e.g. low-pass filters accept things below a frequency, “let them pass”.

But someone said it was confusing because “pass” also means “take a pass” i.e. reject.

So yeah naming is hard.


greg
2020-11-3 16:58:15

Probably this: https://github.com/greghendershott/racket-mode/issues/475#issuecomment-702793756. TL;DR: Possibly you updated Racket Mode sometime between May and October 3; try updating it again?


greg
2020-11-3 16:59:46

If that doesn’t help, let me know. If you don’t mind using GitHub, easier for me to field that, there, on that comment thread. Otherwise here is OK (but I’ll likely copy/paste things to GitHub Issues to have a record for other people).


greg
2020-11-3 16:59:57

@jgeddes ^


joshibharathiramana
2020-11-3 18:48:38

Is there anyway I can improve on writing things like (second (third x)) ? I tried cadaddr but that doesn’t work


samth
2020-11-3 18:53:28

@joshibharathiramana I recommend using match


laurent.orseau
2020-11-3 19:00:36

that would be: (match '(a b (c d e) f) [(list-rest _ _ (list-rest _ x _) _) x])


joshibharathiramana
2020-11-3 19:02:27

Thank you


badkins
2020-11-3 19:07:45

(~> x third second) may also be useful if the nesting is deep. You’ll need to (require threading) first. Is the structure of x imposed upon you, or are you creating it? If the latter, the best approach may be to use a data structure that makes accessing it the way you want to easier.


laurent.orseau
2020-11-3 19:08:28

For the latter, look into struct


joshibharathiramana
2020-11-3 19:09:38

Indeed, I just realized structs are more suited for this


badkins
2020-11-3 19:10:07

In other cases, a hash table can be quite handy.


badkins
2020-11-3 19:16:40

If you need most of the parts of the object, you can use match-let* to destructure it in steps: (define x '(a b (c d e))) (match-let* ([ (list foo bar baz) x ] [ (list _ key _) baz ]) (printf "Key is ~a\n" key))


notjack
2020-11-3 19:41:56

also there’s match-define


rokitna
2020-11-3 23:06:12

Oh, wow, yeah.

This is a far less interesting thing to note, but pass is the name I give to a function that takes a given value and passes it as an argument to a given function. (It’s just #%app with the arguments reversed.) So I guess it’s a word with a lot of meanings, like “set” or “hash” or “map.”


bryanalves
2020-11-4 02:49:52

@bryanalves has joined the channel