Path: csiph.com!weretis.net!feeder9.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail From: Richard Smith Newsgroups: gnu.emacs.help Subject: Re: TCO with named-let via macros Date: Tue, 08 Apr 2025 10:26:56 +0100 Organization: BWH Usenet Archive (https://usenet.blueworldhosting.com) Message-ID: References: <8734oi5ksx.fsf@axel-reichert.de> <87ed6wjffl.fsf@gmail.com> <87y154m645.fsf@axel-reichert.de> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: nnrp.usenet.blueworldhosting.com; logging-data="18187"; mail-complaints-to="usenet@blueworldhosting.com" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:QJKl6LEDJZTfX2mndFJbUQFpJaI= sha1:1eJ7raQaWueNpryKC3vVireSSwA= sha256:ic5vFJVfgVNJozlJebFh+j6JH/WrBd4lS+fNY6dZI3s= sha1:UUCJZe5gV+lTQZwpxS2ydoJVWeU= sha256:1SnVfFcguQTWOmIH7xJjwDrPVoM/9XvHDDqD5SsMsqo= Xref: csiph.com gnu.emacs.help:61018 Axel Reichert writes: > steve g writes: > >> check the elisp manual. it shows how to implement true tail recursion >> in emacs. >> >> (defun elisp-sum (args) >> (elisp-sum-aux args 0)) >> >> (defun elisp-sum-aux (args res) >> (if (null args) >> res >> (elisp-sum-aux (cdr args) (+ (car args) res)))) >> >> you can byte compile it. very simple. > > ... and then easily find out that it will enter the debugger for large > ARGS, say > > (defun elisp-sum (number-sequence 1 10000000)) > > But with > > (defmacro defun-tco (name args body) > "Wraps a 'named-let' around BODY to have a TCO of function NAME with ARGS." > (declare (indent defun)) > (let ((bindings (gensym))) > (setq bindings (mapcar #'(lambda (arg) (list arg arg)) args)) > `(defun ,name ,args > (named-let ,name ,bindings > ,body)))) > > and > > (defun-tco elisp-sum-aux (args res) > (if (null args) > res > (elisp-sum-aux (cdr args) (+ (car args) res)))) > > a > > (defun elisp-sum (number-sequence 1 10000000)) > > will do. > > Best regards > > Axel Hi there - several months later... Axel, Steve in particular with your responses. I got a job as a welder - my first local job on moving here - and had a "winter campaign". Was exhausting getting back into it. Strengthening-up my torso to do weld-runs quickly And accurately And able to overcome perturbations like the "hose" from machine to MIG gun/torch snagging and dragging while continuing welding at constant rate. Then mental tiredness of getting to grips with the various products and what they needed. Just had a chance to look through those posts again. Thanks so much. Best wishes, Rich S