|
|
|
|
|
by S1ngleM4lt
1434 days ago
|
|
Thanks, learned something new today with return-from! I’d be curious how different cl implementations implement it. The first few examples are what I was more familiar with, and it is precisely your note “and this /progn/ form would possibly be extracted to a new function if it was too long” which makes me want to just return early in some cases. Sometimes a case is common enough that it warrants a separate function, but having to define functions for incredibly specific cases just to avoid excessive indentation is not ideal for me. |
|
At least in SBCL, with it compiling the function, it turns into exactly the kind of assembly code you'd expect. Using disassemble:
This sets up the call for the comparison, conditionally jumps based on the result (JL), and then returns one of the two results. Note that the "40" in 5C and 6E are really "20", this is a consequence of how many CL implementations handle integers, the low-order bit is used as a tag so not really part of the value. If you wrote it in C it would be very similar.https://godbolt.org/z/cYPhdW3qd
The biggest difference is that the C version doesn't need a call for the comparison.