Re: Copy/Clone a 'job
Thanks for the suggestion Joe. Other than copy-paste examples, I haven't played much with either #oop and #dbase in picolisp. It is definitely on my list ;) I've been trying to get a good understanding of variable scope, state and lifetime. Especially with functions that have the side-effect of manipulating globals, or lists, 'destructively'. Once I have that, I think the symbol management in picolisp's oop and db facets should be easy enough to grasp. My hex digit example was a bit contrived... I was actually working through this https://rosettacode.org/wiki/Pi#PicoLisp, and after reading the referenced source at http://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf, tweaked it to return the digits in hexadecimal (see code below). To get off-topic a bit, philosophically I am a proponent of minimalism in coding and algorithms/tools that make it easy to generate, manipulate or filter 'streams. Hence.. picolisp! https://en.wikipedia.org/wiki/Unix_philosophy: "Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface." --- Doug Mcllroy I think what Mcllroy could have said there, instead of text streams, was 'symbol lists' ;) /Lindsay # From https://rosettacode.org/wiki/Pi#PicoLisp # But, return the digits in hexadecimal and provide a way to 'reset' the spigot. (de makeHexaPi () (curry ((Q . 1) (R . 0) (S . 1) (K . 1) (N . 3) (L . 3)) () (while (>= (- (+ R (* 4 Q)) S) (* N S)) (mapc set '(Q R S K N L) (list (* Q K) (* L (+ R (* 2 Q))) (* S L) (inc K) (/ (+ (* Q (+ 2 (* 7 K))) (* R L)) (* S L)) (+ 2 L) ) ) ) (prog1 N (let M (- (/ (* 16 (+ R (* 3 Q))) S) (* 16 N)) (setq Q (* 16 Q) R (* 16 (- R (* N S))) N M) ) ) ) ) : (def 'pi16Digit (makeHexaPi)) -> pi16Digit : (pack (make (do 8 (link (hex (pi16Digit)) -> "3243F6A8" : (pack (make (do 8 (link (hex (pi16Digit)) -> "885A308D" : (off pi16Digit) -> NIL : (def 'pi16Digit (makeHexaPi)) -> pi16Digit : (pack (make (do 16 (link (hex (pi16Digit)) -> "3243F6A8885A308D" On Sun, Feb 26, 2017 at 4:30 AM, Joe Bognerwrote: > Hi Lindsay, > > It looks like you are using job primarily to retain the value of N > between invocations. Is that true? Just curious, why not move the loop > inside of hexSpigot instead of looping outside of it? Another option > to consider if you want the behavior of being able to increment the > hexSpigot at any point - use a pil class > (http://software-lab.de/doc/ref.html#oop) > > > > Thanks, > Joe >
Re: Copy/Clone a 'job
Hi Lindsay, It looks like you are using job primarily to retain the value of N between invocations. Is that true? Just curious, why not move the loop inside of hexSpigot instead of looping outside of it? Another option to consider if you want the behavior of being able to increment the hexSpigot at any point - use a pil class (http://software-lab.de/doc/ref.html#oop) Thanks, Joe On Sun, Feb 26, 2017 at 5:03 AM, Lindsay John Lawrencewrote: > Thanks Alex, > > I'll have to play with your solution a bit. I don't quite follow how the > global is working there in conjunction with 'job and 'off. > > However, after banging around on this for a couple of hours, trying 'copy', > various auxillary functions to return the quoted 'job, etc I was at my wits > end...when just a few minutes ago, I remembered where the mail list had > discussed 'job most recently... over 'curry! > > This seems to do what I want as well... > > : (pp 'getHexSpigot) > (de getHexSpigot NIL >(curry > ((N)) > NIL > (default N '(0)) > (prog1 > (hex (% (car N) 16)) > (setq N (cons (+ 1 (car N)) N)) ) ) ) > -> getHexSpigot > > Now I can do this... > > : (def 'hexSpigot1 (getHexSpigot)) > -> hexSpigot1 > : (def 'hexSpigot2 (getHexSpigot)) > -> hexSpigot2 > > : (do 8 (prin (hexSpigot1))) > 01234567-> "7" > : (do 16 (prin (hexSpigot2))) > 0123456789ABCDEF-> "F" > > : hexSpigot1 > -> (NIL (job '((N 8 7 6 5 4 3 2 1 0)) (default N '(0)) (prog1 (hex (% (car > N) 16)) (setq N (cons (+ 1 (car N)) N) > : hexSpigot2 > -> (NIL (job '((N 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)) (default N > '(0)) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N) > > : (off hexSpigot1) > : (off hexSpigot2) > > > /Lindsay > > > > > On Sun, Feb 26, 2017 at 1:19 AM, Alexander Burger > wrote: >> >> Hi Lindsay, >> >> > (de hexSpigot NIL >> >(job '((N)) >> > ... >> > : (do 32 (prin (hexSpigot))) >> > ... >> > 0123456789ABCDEF0123456789ABCDEF-> "F" >> > ... >> > : (pp 'hexSpigot) >> > (de hexSpigot NIL >> >(job >> > '((N 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 >> > 12 >> > 11 10 9 8 7 6 5 4 3 2 1 0 ) ) >> > ... >> > The job vars are being modified and the list N is growing.. using ever >> > greater amounts of memory. If I want to reset the spigot, or even clone >> > it >> > to have more than one, how would I do that? >> >> The simplest is to use a global: >> >>(setq *HexSpigot '((N))) >> >>(de hexSpigot NIL >> (job *HexSpigot >> ... >> >> and later just do the 'setq' again. >> >> >> BTW, for an expression like >> >>(ifn N (setq N (0))) >> >> there is 'default' >> >>(default N (0)) >> >> So the above could be made a bit easier: >> >>(off *HexSpigot) >> >>(de hexSpigot NIL >> (job (default *HexSpigot '((N . (0 >> (prog1 >> (hex (% (car N) 16)) >> (setq N (cons (+ 1 (car N)) N)) ) ) ) >> >>(do 32 (prin (hexSpigot))) >>(off *HexSpigot) >>(do 32 (prin (hexSpigot))) >> >> i.e. just call 'off' to reset it :) >> >> ♪♫ Alex >> -- >> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe > > -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Copy/Clone a 'job
Hi Lindsay, > I'll have to play with your solution a bit. I don't quite follow how the > global is working there in conjunction with 'job and 'off. There is nothing mysterious about it. 'job' evaluates its first argument. So there is absolutely no difference whether you quote that argument (job '((N)) ... or pass it in a variable (setq Var '((N))) (job Var ... ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Copy/Clone a 'job
Thanks Alex, I'll have to play with your solution a bit. I don't quite follow how the global is working there in conjunction with 'job and 'off. However, after banging around on this for a couple of hours, trying 'copy', various auxillary functions to return the quoted 'job, etc I was at my wits end...when just a few minutes ago, I remembered where the mail list had discussed 'job most recently... over 'curry! This seems to do what I want as well... : (pp 'getHexSpigot) (de getHexSpigot NIL (curry ((N)) NIL (default N '(0)) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N)) ) ) ) -> getHexSpigot Now I can do this... : (def 'hexSpigot1 (getHexSpigot)) -> hexSpigot1 : (def 'hexSpigot2 (getHexSpigot)) -> hexSpigot2 : (do 8 (prin (hexSpigot1))) 01234567-> "7" : (do 16 (prin (hexSpigot2))) 0123456789ABCDEF-> "F" : hexSpigot1 -> (NIL (job '((N 8 7 6 5 4 3 2 1 0)) (default N '(0)) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N) : hexSpigot2 -> (NIL (job '((N 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)) (default N '(0)) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N) : (off hexSpigot1) : (off hexSpigot2) /Lindsay On Sun, Feb 26, 2017 at 1:19 AM, Alexander Burgerwrote: > Hi Lindsay, > > > (de hexSpigot NIL > >(job '((N)) > > ... > > : (do 32 (prin (hexSpigot))) > > ... > > 0123456789ABCDEF0123456789ABCDEF-> "F" > > ... > > : (pp 'hexSpigot) > > (de hexSpigot NIL > >(job > > '((N 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 > > 11 10 9 8 7 6 5 4 3 2 1 0 ) ) > > ... > > The job vars are being modified and the list N is growing.. using ever > > greater amounts of memory. If I want to reset the spigot, or even clone > it > > to have more than one, how would I do that? > > The simplest is to use a global: > >(setq *HexSpigot '((N))) > >(de hexSpigot NIL > (job *HexSpigot > ... > > and later just do the 'setq' again. > > > BTW, for an expression like > >(ifn N (setq N (0))) > > there is 'default' > >(default N (0)) > > So the above could be made a bit easier: > >(off *HexSpigot) > >(de hexSpigot NIL > (job (default *HexSpigot '((N . (0 > (prog1 > (hex (% (car N) 16)) > (setq N (cons (+ 1 (car N)) N)) ) ) ) > >(do 32 (prin (hexSpigot))) >(off *HexSpigot) >(do 32 (prin (hexSpigot))) > > i.e. just call 'off' to reset it :) > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: Copy/Clone a 'job
Hi Lindsay, > (de hexSpigot NIL >(job '((N)) > ... > : (do 32 (prin (hexSpigot))) > ... > 0123456789ABCDEF0123456789ABCDEF-> "F" > ... > : (pp 'hexSpigot) > (de hexSpigot NIL >(job > '((N 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 > 11 10 9 8 7 6 5 4 3 2 1 0 ) ) > ... > The job vars are being modified and the list N is growing.. using ever > greater amounts of memory. If I want to reset the spigot, or even clone it > to have more than one, how would I do that? The simplest is to use a global: (setq *HexSpigot '((N))) (de hexSpigot NIL (job *HexSpigot ... and later just do the 'setq' again. BTW, for an expression like (ifn N (setq N (0))) there is 'default' (default N (0)) So the above could be made a bit easier: (off *HexSpigot) (de hexSpigot NIL (job (default *HexSpigot '((N . (0 (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N)) ) ) ) (do 32 (prin (hexSpigot))) (off *HexSpigot) (do 32 (prin (hexSpigot))) i.e. just call 'off' to reset it :) ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Copy/Clone a 'job
Hi, How would I copy|clone, reinitialize or dispose of a 'job' function? For example, given (de hexSpigot NIL (job '((N)) (ifn N (setq N '(0))) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N)) ) ) ) I can then do.. : (do 32 (prin (hexSpigot))) 0123456789ABCDEF0123456789ABCDEF-> "F" Now, hexSpigot something like this... : (pp 'hexSpigot) (de hexSpigot NIL (job '((N 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ) ) (ifn N (setq N '(0))) (prog1 (hex (% (car N) 16)) (setq N (cons (+ 1 (car N)) N)) ) ) ) The job vars are being modified and the list N is growing.. using ever greater amounts of memory. If I want to reset the spigot, or even clone it to have more than one, how would I do that? /Lindsay