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 Bogner <joebog...@gmail.com> wrote:

> 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
>

Reply via email to