Re: L-system rules with PicoLisp
Thanks Alex, I appreciate the suggestions. As ever, I learn something from them ;) /Lindsay On Fri, Mar 3, 2017 at 10:10 PM, Alexander Burgerwrote: > Hi Lindsay, > > > The code below is the recursive Gosper implementation I came up with that > > uses very little stack. This version just emits states. > > ... > > Picolisp continues to impress me with its expressiveness and power. > > As ever, I can't resist to suggest some optimizations :) > > > > (de Plot (L) > >(map '((X) (prin (car X))) L) ) > > (mapc prin L) would be enough. > > > > (de Fn (L) > >(let R > > (fish > > atom > > (mapcar > > '((X) > >(cond > > ((= X "A") A) > > ((= X "B") B) > > (T X) ) ) > > L ) ) > > R ) ) > > The 'let' is not necessary, as R is never used. And 'fish' is for nested > structures, a flat list can be handled directly e.g. with 'filter' or > 'extract' > >(extract '((X) (cond ((pair X)) ((=X "A") A) ..)) L) > > As 'A' and 'B' are free variables here, 'Fn' should be named differently, > starting with an underscrore (see doc/ref.html#conv)). You coud try 'lint' > or > 'lintAll' to see what it complains. > > The PicoLisp naming conventions also recommend upper case first letters for > locally bound variables. Functions defined globally like 'Plot' or 'Fn' > should > better start in lower case. > > > > (de L-Run (L D) > >(cond > > ((>= D MaxDepth) (Plot L)) > > (T > > Here an 'if' is shorter than a 'cond'. > > ♪♫ 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
Re: JavaCode with static class methods
Alexander Burgerwrites: Hi Joe, Hi Alex, >> I'm experimenting a bit with the 'java' function, and the StringBuilder >> ... >> (java "java.lang.Math" 'sqrt 4) > > It needs a different call: >: (java "java.lang.Math" 'sqrt (-6 . 64.0)) thanks for the hints, so actually I was pretty close, just ignorant about the peculiarities of those numeric arguments. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Subscribe
Hello Mateusz Poszwa:-) You are now subscribed Thanks. -- Mateusz Poszwa -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe