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 Lawrence
<lawrence.lindsayj...@gmail.com> wrote:
> 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 <abu@software-labde>
> 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

Reply via email to