Is there any runtime overhead for using let*
instead of let
?
(I know about the differences in variable scope, I’m just curious about the performance.)
I’m a beginner too, but I think it was explained that let*
are just nested let
s, so it would have whatever performance inefficiency nested let
s bring (shouldn’t be much though). I will let someone more experienced confirm for sure.
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.
Maybe doing a time
on let
and let*
somehow would allow you to assess the efficiency? Or is this a bad method?
eg. computing factorial with both methods
@kellysmith12.21 I would be surprised if you could measure a difference between let
and let*
.
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.
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?”
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)?
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.
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?
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).
@jgeddes ^
Is there anyway I can improve on writing things like (second (third x))
? I tried cadaddr
but that doesn’t work
@joshibharathiramana I recommend using match
that would be: (match '(a b (c d e) f)
[(list-rest _ _ (list-rest _ x _) _)
x])
Thank you
(~> 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.
For the latter, look into struct
Indeed, I just realized struct
s are more suited for this
In other cases, a hash table can be quite handy.
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))
also there’s match-define
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 has joined the channel