Re: TC -> Loop Transformation?
Hi Christopher, Congratulations on the new baby. You'll have lots of late nights to code now...or maybe not. This may give some added insight into what you are trying to accomplish... https://rosettacode.org/wiki/Jump_anywhere#PicoLisp The code example there was worth some time to study for me, especially in consideration of scoping. It may even have been my lisp enlightenment moment (= code data). /Lindsay >
Re: TC -> Loop Transformation?
Hi, sorry about the delayed response — just had a new baby and have been in the hospital for a few days. What I am trying to accomplish is be able to represent algorithms in a recursive format (which is often what comes naturally to me and seems cleaner and easier to understand) without the stack penalty. This is why TCO is baked into Scheme and CL, as the lisp people usually have this mindset. If you don't, that is fine and probably not worth an extended discussion. In my Haskell days, I represented most algs in some recursive format, though I found out there was usually some higher level abstraction available encapsulating the recursion. The "macro" I wrote seems to accomplish what I want, though I'm thinking maybe there are a few things in the macro code itself that could be improved. E.g., it seems a little weird throwing an exception, but I wasn't sure how else to do a non-local jump. And there is potential also for variable name collisions between the macro variables and the function that is passed in. On 03/04/2017 11:46 PM, Alexander Burger wrote: > Hi Christopher, > > thanks for sharing these ideas! > > However I'm a bit clueless about what you want to achieve. > >> Hi, I while ago I asked how I might somehow represent a loop as a a tail >> call recursion, so as to give me the pattern I like without the call >> penalties. > > Isn't it a lot easier to write a 'while', 'for' or 'do' loop then? > > ♪♫ Alex > -- https://qlfiles.net -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: TC -> Loop Transformation?
Hi Christopher, thanks for sharing these ideas! However I'm a bit clueless about what you want to achieve. > Hi, I while ago I asked how I might somehow represent a loop as a a tail > call recursion, so as to give me the pattern I like without the call > penalties. Isn't it a lot easier to write a 'while', 'for' or 'do' loop then? ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
TC -> Loop Transformation?
Hi, I while ago I asked how I might somehow represent a loop as a a tail call recursion, so as to give me the pattern I like without the call penalties. Since nothing was forthcoming, I took a stab at it myself. Probably my noobish attempt will be ugly to you veterans, but I was hoping if I posted it I might get suggested improvements or alternative approaches: (de zip-set (L1 L2) (while (and L1 L2) (set (car L1) (car L2)) (setq L1 (cdr L1)) (setq L2 (cdr L2)) ) ) (de tc-recursion X (let (tc (list '@ (list 'prog (list 'zip-set (list 'car (list 'quote (car X))) '(rest)) '(setq Cont T) '(throw 'TC) ) ) ) (prog (setq Cont T) (while Cont (setq Cont NIL) (catch 'TC (run (cdr X)) ) ) ) ) ) (de tc-test () (setq A 1) (tc-recursion (A) (prinl A) (if (>= A 10) A (tc (+ A 1)) ) ) ) Please include constructive suggestions along with the criticism. -- https://qlfiles.net -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe