Post AWBsiwbcNNVP7pDbW4 by pfpoitras@fosstodon.org
 (DIR) More posts by pfpoitras@fosstodon.org
 (DIR) Post #AWBs9fquflGN1wYRE0 by louis@emacs.ch
       2023-05-30T19:38:34Z
       
       0 likes, 0 repeats
       
       TIL Tail call optimization is the default in most modern Common Lisp implementations. It is not a Scheme exclusive any more (I was under the impression...).But, how do I find out, in SBCL for example, that I do a proper TCO function call?#commonlisp #sbcl
       
 (DIR) Post #AWBsKG42tPYGEdkBlo by galdor@emacs.ch
       2023-05-30T19:40:31Z
       
       0 likes, 0 repeats
       
       @louis I use DISASSEMBLE when I need to check (or "C-c M-d" on a symbol with Slime).You'll see precisely what happens.
       
 (DIR) Post #AWBsiwbcNNVP7pDbW4 by pfpoitras@fosstodon.org
       2023-05-30T19:44:57Z
       
       0 likes, 0 repeats
       
       @louis Should be on by default on sbcl unless you have (optimize (debug 3)). If there's a function that you really need TCO on, you can always inspect the assembly via (disassemble 'my-func), where a recursive call should be obvious.
       
 (DIR) Post #AWBt1iaohSUdAPnOs4 by louis@emacs.ch
       2023-05-30T19:48:18Z
       
       0 likes, 0 repeats
       
       @galdor @pfpoitras  ​ Help me, please ... 🤔
       
 (DIR) Post #AWBtfCLtzN7al3e3UW by ramin_hal9001@emacs.ch
       2023-05-30T19:55:14Z
       
       0 likes, 0 repeats
       
       @louis @galdor @pfpoitras According to the Google Common Lisp coding guidelines, it is bad form to rely on tail call optimization, because not all CL implementations support it. You are supposed to use the loop macro instead.
       
 (DIR) Post #AWBuTcfqOqUIs917ZY by galdor@emacs.ch
       2023-05-30T20:04:34Z
       
       0 likes, 0 repeats
       
       @ramin_hal9001 @louis @pfpoitras The Google CL guidelines are just a list of opinions, you don't have to follow them. You're free to prefer LOOP, but it is a matter of taste. Personally I believe LOOP is a frankenstein construction that should never have been included in the standard. But again, preferences.Here you don't need the assembly code (am I tired or is this something else than amd64?): the call to LAUGH is not in tail position since its return value is used to be consed to the 'HA atom before being returned.So LAUGH is not tail recursive.In general to make this kind of code tail recursive, you pass the accumulator as an argument of the function and directly return it in tail position once you've finished recursing.Of course here you could just use DOTIMES :)
       
 (DIR) Post #AWBvU4EQ2bE0ILxtOS by pfpoitras@fosstodon.org
       2023-05-30T20:15:53Z
       
       0 likes, 0 repeats
       
       @galdor @ramin_hal9001 @louis I think you're right. This code gets correctly TCO'd```(defun laugh (blarg n)           (if (< n 1)               blarg               (progn (let ((new-blarg (cons n blarg)))                        (laugh new-blarg (1- n))))))```(laugh 10) returns (1 2 3 4 5 6 7 8 9 10)
       
 (DIR) Post #AWBvXO5gf4dqkvSpNo by amszmidt@mastodon.social
       2023-05-30T20:16:30Z
       
       0 likes, 0 repeats
       
       @galdor LOOP has existed as an integral part of Lisp since long before the CL standard. Earliest, quick reference, I could find is from 1982.  So to claim that it shouldn't have been part of what was already "common" .. is weird.  SERIES on the other hand .. now THAT is a weird thing to add.
       
 (DIR) Post #AWBzOEgudh4aoWleGu by louis@emacs.ch
       2023-05-30T20:59:39Z
       
       0 likes, 0 repeats
       
       @galdor You're right, of course! Thanks for the hint. The assembler is Apple Silicon ARM64. Unfortunately I don't know much about it.
       
 (DIR) Post #AWBzn3LVxPP4rpan5M by amszmidt@mastodon.social
       2023-05-30T21:04:07Z
       
       0 likes, 0 repeats
       
       @louis @galdor @pfpoitras Pushing the #LispMachine revolution.
       
 (DIR) Post #AWC1BX2RJU9TrPuGmm by louis@emacs.ch
       2023-05-30T21:19:46Z
       
       0 likes, 0 repeats
       
       @amszmidt That's so beautiful. I can actually read the assembler of this version :-)
       
 (DIR) Post #AWC1U23qi5o5HwO5j6 by amszmidt@mastodon.social
       2023-05-30T21:23:07Z
       
       0 likes, 0 repeats
       
       @louis "Fortunately, the translation between Lisp and this instruction set is very simple; after you get the hang of it, you can move back and forth between the two representations without much trouble." -- Lisp Machine Manual.