Does and
evaluate all its arguments? Or is the short circuting such that it not only saves unnecessary boolean checks after encountering a #f
, but also saves eval
ing arguments that occur after a #f
?
since Racket is strict, I’m expecting the former and am curious
and
is short-circuiting
try out (and #f (display 'hi))
strictness has to do with function application
In Racket, and
is not a function. It’s a syntax
Just like most other languages like C, Python, JS, etc.
oh that makes sense then, I was thinking it was a function
what is a good way to guess what is a function and what is part of syntax? (other than go read the grammar :sweat_smile:). I thought and
was a function since its usage was very similar to function application
you can look at the documentation: https://docs.racket-lang.org/reference/if.html?q=and#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._and%29%29 says “syntax”
Also, you can enter and
in the repl. If it is a function, you will get <procedure>, if it is a syntactic form (in most cases), you will get an error.
this is not foolproof though. Identifier macro exists, though rare.
@sorawee can you give an example?