Groups | Search | Server Info | Login | Register
Groups > gnu.emacs.help > #61018
| From | Richard Smith <null@void.com> |
|---|---|
| Newsgroups | gnu.emacs.help |
| Subject | Re: TCO with named-let via macros |
| Date | 2025-04-08 10:26 +0100 |
| Organization | BWH Usenet Archive (https://usenet.blueworldhosting.com) |
| Message-ID | <m1r023ngv3.fsf@void.com> (permalink) |
| References | <m11q42e6zz.fsf@void.com> <8734oi5ksx.fsf@axel-reichert.de> <m1ttgxhkp3.fsf@void.com> <87ed6wjffl.fsf@gmail.com> <87y154m645.fsf@axel-reichert.de> |
Axel Reichert <mail@axel-reichert.de> writes: > steve g <sgonedes1977@gmail.com> 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
Back to gnu.emacs.help | Previous | Next — Previous in thread | Next in thread | Find similar
thanks - calculate pi fn. in elisp Richard Smith <null@void.com> - 2024-07-09 19:48 +0100
TCO with named-let via macros (was: thanks - calculate pi fn. in elisp) Axel Reichert <mail@axel-reichert.de> - 2024-07-09 23:15 +0200
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:28 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 15:56 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-08-10 22:28 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:36 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 16:22 -0400
Re: TCO with named-let via macros Axel Reichert <mail@axel-reichert.de> - 2024-08-10 23:15 +0200
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-11 14:56 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2025-04-08 10:26 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 06:59 +0100
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-07-10 09:18 +0100
Re: TCO with named-let via macros steve g <sgonedes1977@gmail.com> - 2024-08-10 16:26 -0400
Re: TCO with named-let via macros Richard Smith <null@void.com> - 2024-08-10 22:51 +0100
csiph-web