Re: Lifespan of memory of parameters

2017-02-25 Thread Alexander Burger
Hi Christopher,

> Hi list, could someone educate me a little regarding the following (or
> point me to the right documentation):
> 
> Say I have function
> 
> (foo (Lst)
>(bar (copy Lst)) )
> 
> My question is: At the point when bar is called, is Lst now gone (i.e.,
> marked for garbage collection) or does that wait until bar returns? If

Neither. It depends on who else "owns" this list. Consider

   (let L (range 1 99)
  (foo L)
  (print L) )

At first only 'L' points to the list (to the first cell, to be exact).

When (foo L) is called, now also 'Lst' points there. 'foo' has no influence on
that. It could be defined as

   (de foo (Lst)
  (let A (bar (copy Lst))
 (off Lst)
 (doSomethingWithTheCopy)
 ...

With (off Lst) *one* refernce to the list is cleared, but the list will be
garbage collected only when the *last* reference is gone, which is not under
control of 'foo'.

If the list could indeed be garbage collected inside 'foo', then the above
(print L) would crash terribly.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Lifespan of memory of parameters

2017-02-25 Thread Christopher Howard
Hi list, could someone educate me a little regarding the following (or
point me to the right documentation):

Say I have function

(foo (Lst)
   (bar (copy Lst)) )

My question is: At the point when bar is called, is Lst now gone (i.e.,
marked for garbage collection) or does that wait until bar returns? If
the latter, is there a way to tell the interpreter that you are done
with the first Lst (i.e., so you don't have two of them floating around)?

-- 
https://qlfiles.net
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: exercism.io

2017-02-25 Thread Mike Pechkin
https://github.com/exercism/x-common/tree/master/exercises

On Sun, Feb 26, 2017 at 1:20 AM, Joh-Tob Schäg  wrote:

> Thanks for sharing.
> Can you link the list of tasks or is it behind a login wall?
>
> 2017-02-25 9:42 GMT+01:00 Alexander Burger :
>
>> Hi Mike,
>>
>> > I've implemented tasks from A to F:
>> > https://bitbucket.org/mihailp/tankfeeder/src/9de46f9e807786f
>> dbf4a86604aca20dd25f0c19e/exercism-io/?at=default
>>
>> Great! Thanks for sharing!
>>
>> ♪♫ Alex
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>


Re: exercism.io

2017-02-25 Thread Lindsay John Lawrence
There is some very nice code in here.
For me, the 'allbase' function is a particularly nice gem.

/Lindsay


On Fri, Feb 24, 2017 at 8:44 PM, Mike Pechkin 
wrote:

> hi all,
>
> I've implemented tasks from A to F:
> https://bitbucket.org/mihailp/tankfeeder/src/
> 9de46f9e807786fdbf4a86604aca20dd25f0c19e/exercism-io/?at=default
>
> o) dumbest and duplicates from rosettacode ignored
> o) worth to check are Alphametrics and Change
>
> If you want:
> o) pick up one task
> o) set reservation
> o) implement and send your code
> o) repeat
>
> Mike
>
>


Re: exercism.io

2017-02-25 Thread Joh-Tob Schäg
Thanks for sharing.
Can you link the list of tasks or is it behind a login wall?

2017-02-25 9:42 GMT+01:00 Alexander Burger :

> Hi Mike,
>
> > I've implemented tasks from A to F:
> > https://bitbucket.org/mihailp/tankfeeder/src/
> 9de46f9e807786fdbf4a86604aca20dd25f0c19e/exercism-io/?at=default
>
> Great! Thanks for sharing!
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: later and output

2017-02-25 Thread Joh-Tob Schäg
I am glad i could be of some help.
To be honest Linsday you do a good job for the community and a better job
than i do to be honest.
Maybe somebody can spend some time and spin this in to a draft for the
future less terse picolisp documentation.
I am currently busy with learning for pre-exames.

2017-02-25 21:58 GMT+01:00 Lindsay John Lawrence <
lawrence.lindsayj...@gmail.com>:

>
> My earlier function 'primeFactorz' had a bug! returning the wrong results
> for actual prime numbers :(
>
> : (primeFactorz 17)
> -> (3 5)   # WRONG!
>
> I have to be more careful with integer arithmetic. The corrected function
> is:
>
> (de primeFactorz (N)
>(use Result
>   (recur (N)
>  (let (Root (inc (sqrt N))  X 2)
> (when (gt0 (% N X))
>(setq X 3)
>(while
>   (and
>  (gt0 (% N X))
>  (<= (inc 'X 2) Root) ) ) )
> (setq X (if (<= X Root) X N)
>   Result (cons X Result))
> (unless (= X N) (recurse (/ N X))) ) )
>   Result ) )
>
> : (primeFactorz 17)
> -> (17)
>
> /Lindsay
>
> Addum: I have to say I am  impressed with how straightforward it is to
> parallelize code in picolisp!
>
> I found my bug while playing with Joh-Tob's Check function and the
> discussion on this thread really helped me to understand how to use 'later'.
>
> : (bench (CheckPrimeFactors 1 CheckP1))
> 1.287 sec
> -> NIL
> : (bench (CheckPrimeFactors 1 CheckP2))
> 1.310 sec
> -> NIL
> : (bench (CheckPrimeFactors 1 CheckP1=P2))
> 1.340 sec
> -> NIL
> : (bench (CheckPrimeFactors 32 CheckOdd))
> (2 3 T 5 T 7 8 T)
> (T 11 12 13 T T T 17)
> (18 19 20 T T 23 T T)
> (T 27 28 29 30 31 32 T)
> 0.006 sec
> -> (T 27 28 29 30 31 32 T)
> : (bench (CheckPrimeFactors 32 CheckEven))
> (T T 4 T 6 T T 9)
> (10 T T T 14 15 16 T)
> (T T T 21 22 T 24 25)
> (26 T T T T T T 33)
> 0.006 sec
> -> (26 T T T T T T 33)
>
>
> Definitions: Assuming 'prime-factors' 'primeFactorz':
>
> : CheckP1
> -> ((N) (ifn (= N (apply '* (prime-factors N))) N T))
> : CheckP2
> -> ((N) (ifn (= N (apply '* (primeFactorz N))) N T))
> : CheckP1=P2
> -> ((N) (ifn (= (sort (prime-factors N)) (sort (primeFactorz N))) N T))
> : CheckOdd
> -> ((N) (if (bit? 1 (length (prime-factors N))) N T))
> : CheckEven
> -> ((N) (ifn (bit? 1 (length (prime-factors N))) N T))
>
>
> (de CheckPrimeFactors (Limit Checkit)
>(let Lst (need 8)
>   (for (N 2 (>= Limit N))
>  (map
> '((L)
>(set L NIL)
>(later L (Checkit N))
>(inc 'N) )
> Lst )
>  (wait NIL (full Lst))
>  (ifn (fully flg? Lst) (println Lst)) ) ) )
>
>
>
>


Re: later and output

2017-02-25 Thread Lindsay John Lawrence
My earlier function 'primeFactorz' had a bug! returning the wrong results
for actual prime numbers :(

: (primeFactorz 17)
-> (3 5)   # WRONG!

I have to be more careful with integer arithmetic. The corrected function
is:

(de primeFactorz (N)
   (use Result
  (recur (N)
 (let (Root (inc (sqrt N))  X 2)
(when (gt0 (% N X))
   (setq X 3)
   (while
  (and
 (gt0 (% N X))
 (<= (inc 'X 2) Root) ) ) )
(setq X (if (<= X Root) X N)
  Result (cons X Result))
(unless (= X N) (recurse (/ N X))) ) )
  Result ) )

: (primeFactorz 17)
-> (17)

/Lindsay

Addum: I have to say I am  impressed with how straightforward it is to
parallelize code in picolisp!

I found my bug while playing with Joh-Tob's Check function and the
discussion on this thread really helped me to understand how to use 'later'.

: (bench (CheckPrimeFactors 1 CheckP1))
1.287 sec
-> NIL
: (bench (CheckPrimeFactors 1 CheckP2))
1.310 sec
-> NIL
: (bench (CheckPrimeFactors 1 CheckP1=P2))
1.340 sec
-> NIL
: (bench (CheckPrimeFactors 32 CheckOdd))
(2 3 T 5 T 7 8 T)
(T 11 12 13 T T T 17)
(18 19 20 T T 23 T T)
(T 27 28 29 30 31 32 T)
0.006 sec
-> (T 27 28 29 30 31 32 T)
: (bench (CheckPrimeFactors 32 CheckEven))
(T T 4 T 6 T T 9)
(10 T T T 14 15 16 T)
(T T T 21 22 T 24 25)
(26 T T T T T T 33)
0.006 sec
-> (26 T T T T T T 33)


Definitions: Assuming 'prime-factors' 'primeFactorz':

: CheckP1
-> ((N) (ifn (= N (apply '* (prime-factors N))) N T))
: CheckP2
-> ((N) (ifn (= N (apply '* (primeFactorz N))) N T))
: CheckP1=P2
-> ((N) (ifn (= (sort (prime-factors N)) (sort (primeFactorz N))) N T))
: CheckOdd
-> ((N) (if (bit? 1 (length (prime-factors N))) N T))
: CheckEven
-> ((N) (ifn (bit? 1 (length (prime-factors N))) N T))


(de CheckPrimeFactors (Limit Checkit)
   (let Lst (need 8)
  (for (N 2 (>= Limit N))
 (map
'((L)
   (set L NIL)
   (later L (Checkit N))
   (inc 'N) )
Lst )
 (wait NIL (full Lst))
 (ifn (fully flg? Lst) (println Lst)) ) ) )


Re: BBWT

2017-02-25 Thread Lindsay John Lawrence
Thanks Alex,  The feedback is appreciated.

This is a good clarification of how namespaces work in the 64bit version.

 Also, somehow, it had not 'clicked' with me that transient symbols could
be used in this regard. Re-read that section of the documentation again...
=)
"With that mechanism, it is possible to create symbols with a local
access scope, not accessible from other parts of the program"

/Lindsay


On Sat, Feb 25, 2017 at 12:40 AM, Alexander Burger 
wrote:

> Hi Lindsay,
>
> > Bijective Burrows Wheeler Transform
> > https://github.com/thinknlive/picolisp-bbwt
>
> Cool! This code looks very good! :)
>
>
> > As I was working on this I realized I need to start thinking about how to
> > organize my code...
> >
> > The two main functions, encodeBBWT and decodeBBWT feel larger than they
> > should be because I have defined smaller functions within them that use
> > variables in the same scope.
> >
> > My question:  Is there an 'idiomatic' or recommended way to organize
> module
> > or project code in picolisp?
>
> Binding the functions 'Put' and 'Bwt' locally is perfectly legal, but not
> really
> necessary here, as they never change. So they just create (minimal) runtime
> overhead. I would define them the normal way, perhaps as transient symbols
> if I
> want to hide them from the outside world:
>
>(de "put" (B C)
>   (let (V ...
>
>(de "bwt" (W)
>   (let (C ...
>
>
> Using a namespace is also possible, but too much overhead in my feeling
> for such
> a small file. It would go like this:
>
>(symbols 'bbwt 'pico)
>(local put bwt)
>
>(de put (B C)  # Shadows the built-in 'put', use with care
>   (let (V ...
>
>(de bwt (W)
>   (let (C ...
>
>(de pico~encodeBBWT (L)
>   ...
>
>(de pico~decodeBBWT (L)
>   ...
>
> This creates the symbol 'encodeBBWT' in the 'pico' namespace. Another (I
> think
> better) way is:
>
>(de encode (L)
>   ...
>
>(de decode (L)
>   ...
>
> and later, when used from another namespace, call it as
>
>(bbwt~encode ...)
>(bbwt~decode ...)
>
>
> Concerning 'Debug', I would omit it here, and call (trace 'encodeBBWT) or
> (trace
> 'bbwt~encode) or (mapc trace '(bbwt~encode bbwt~decode bbwt~put bbwt~bwt)
> to
> debug it.
>
> Other minor improvements:
>
>   V2 (car (cdr V)) )
> ->
>   V2 (cadr V) )
>
>
>(while (car W)
>   (if (not (cdr W))
>  (Put C (car W))
>  (Put (car (cdr W)) (car W)) )
> ->
>(while (car W)
>   (Put
>  (ifn (cdr W) C (cadr W))
>  (car W) )
>
> and some similar cases :)
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Vip and different file types

2017-02-25 Thread Erik Gustafson
Hi Alex,

Thanks for the suggestions! I'll continue to play with it

- Erik


Re: P35 Prime Factors

2017-02-25 Thread Lindsay John Lawrence
Hi Alex,  Joh-Tob,

Thank you. With the Knuth reference the code makes a lot more sense!

I had implemented a more basic version.

For large ranges, the performance difference of the Alex's iterative
version that utilizes the sequence is much better! It is a very nice use of
circular lists.

: (bench (for X 300 (prime-factors X)))
16.547 sec
-> (2 2 2 2 2 2 3 5 5 5 5 5 5)
: (bench (for X 300 (primeFactorz X)))
24.632 sec
-> (5 5 5 5 5 5 3 2 2 2 2 2 2)


: (bench (prime-factors 1000))
0.000 sec
-> (2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5 5 5 5)
: (bench (primeFactorz 1000))
0.000 sec
-> (5 5 5 5 5 5 5 5 5 5 5 2 2 2 2 2 2 2 2 2 2 2)
:

(de primeFactorz (N)
   (use Result
  (recur (N)
 (let (Root (inc (sqrt N))  X 2)
(when (gt0 (% N X))
   (setq X 3)
   (while
  (and
 (gt0 (% N X))
 (< (inc 'X 2) Root) ) ) )
(setq
   X (if (<= X Root) X N)
   Result (cons X Result) )
(unless (= X N) (recurse (/ N X))) ) )
  Result ) )


/Lindsay


On Sat, Feb 25, 2017 at 1:25 AM, Joh-Tob Schäg  wrote:

> I verified that it works for all numbers lower than 1000.
>
>
> My code:
> (let N 2
>(while (> 1000 N )
>   (ifn (= N (apply '* (prime-factors N)))
>  (print N))
>   (inc 'N)))
>
> 2017-02-25 9:58 GMT+01:00 Alexander Burger :
>
>> Hi Lindsay, Joh-Tob,
>>
>> On Sat, Feb 25, 2017 at 09:36:04AM +0100, Joh-Tob Schäg wrote:
>> > The purpose of the list is to increase the speed of the algorithm by
>> > skipping some numbers. This is possible because of the math of
>> Differences
>>
>> Correct.
>>
>> > between consecutive primes but i am currently verifying the algorithm
>> if it
>> > works, since the list might be wrong.
>>
>> I took it from Donald E. Knuth's "Art of Computer Programming", Volume 2
>> (Seminumerical Algorithms). In "Factoring into Primes" on page 365 he
>> writes:
>>
>>The sequence ... of trial divisors .. can be taken to be simply 2, 3,
>> 5, 7,
>>11, 13, 17, 19, 23, 25, 29, 31, 35, .. where we alternately add 2 and
>> 4 after
>>the first three terms.
>>...
>>A further savings of 20 percent ... removing the numbers 30m +/- 5 ..
>>
>> I believe the term (let (D 2 L (1 2 2 . (4 2 4 2 4 6 2 6 .)) generates
>> that
>> sequence.
>>
>> ♪♫ Alex
>>
>>
>> >
>> > 2017-02-25 7:44 GMT+01:00 Lindsay John Lawrence <
>> > lawrence.lindsayj...@gmail.com>:
>> >
>> > > Does anyone know the algorithm that is being expressed here?
>> > >
>> > > I am trying to understand the code... http://picolisp.com/wiki/?99p35
>> > >
>> > > de prime-factors (N)
>> > >(make
>> > >   (let (D 2  L (1 2 2 . (4 2 4 2 4 6 2 6 .))  M (sqrt N))
>> > >  (while (>= M D)
>> > > (if (=0 (% N D))
>> > >(setq M (sqrt (setq N (/ N (link D)
>> > >(inc 'D (pop 'L)) ) )
>> > >  (link N) ) ) )
>> > >
>> > > and  having difficulties understanding the purpose of the circular
>> list.
>> > >
>> > > /Lindsay
>> > >
>> > >
>> > >
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>


Re: Workers for multicore processing (Question and RFC)

2017-02-25 Thread Mike Pechkin
>
>
>
>
> Is there some "worker" implementation which keeps a queue of task to do
> and creates N worker processes which take tasks from the queue when they
> are finished?
>
>
​you have to implement everything by yourself.
as start point:
https://bitbucket.org/mihailp/tankfeeder/src/9de46f9e807786fdbf4a86604aca20dd25f0c19e/map-reduce.l?at=default=file-view-default

https://bitbucket.org/mihailp/tankfeeder/src/9de46f9e807786fdbf4a86604aca20dd25f0c19e/pow.l?at=default=file-view-default
​


Re: later and output

2017-02-25 Thread Alexander Burger
On Sat, Feb 25, 2017 at 11:24:15AM +0100, Joh-Tob Schäg wrote:
> I tried to parallelize the following code:
> '(let N 2
>(while (> 1000 N )
>   (check N)
>   (inc 'N)))
> where (check N) is defined as '(ifn (= N (apply '* (prime-factors N)))
> (print N))

OK, good!


> 'later has the following form  '(later
> place_where_to_save_the_return_result . program to execute)

Correct.


> However i am not interested in storing the result and (later 'NIL prog)
> does not work for obvious reasons.

Right. It does not work well because too many processes are started too quickly.


> Furthermore (later (new) (print 8)) does not work either.
> Using files as in (out "+file" (later (new) (print 8))) does not work
> either.

This is a different problem. Because 'later' is a frontend to 'pipe' using PLIO,
you better not 'print' something to the current output channel.

This would work:

   : (later (new) (* 3 4))
   -> $377236506200
   : (val @)
   -> 12

or

   : (later (cons) (* 3 4))
   -> (NIL)
   : (car @)
   -> 12


> Is there a way to run '(check N) on multiple cores at the same time and get
> the results 'print-ed in to the standard output of the instance where the

As you cannot print to stdout (which is reserved for the pipe), you could print
to a file or simply to the console *inside* the child process:

   : (later (cons) (out "/dev/tty" (println 8)))
   -> (NIL)
   : 8
(car @)
   -> 8


Remains the problem of excessive process creation. I would handle this by
creating only eg. 8 processes at one time:

   (let Lst (need 8)
  (for (N 2  (>= 1000 N))
 (map
'((L)
   (set L NIL)
   (later L (out "/dev/tty" (println (check N
   (inc 'N) )
Lst )
 (wait NIL (full Lst)) ) )

Or, instead of printing in the child, you could also just print the *results* in
the main process:

   (let Lst (need 8)
  (for (N 2  (>= 1000 N))
 (map
'((L)
   (set L NIL)
   (later L (check N))
   (inc 'N) )
Lst )
 (wait NIL (full Lst))
 (println Lst) ) )

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Workers for multicore processing (Question and RFC)

2017-02-25 Thread Joh-Tob Schäg
There are limits on how many processes can exist at the same time and
having more 'later processes than cores is wasteful and Linux only allows
for 1024 file descriptors per process.
? (for N 1 (later (cons) (* N N)))
!? (pipe (pr (prog (* N N
Pipe error: Too many open files
? N
-> 339

Is there some "worker" implementation which keeps a queue of task to do and
creates N worker processes which take tasks from the queue when they are
finished?

Ideas:
Task would be copy of environment + function + values to apply the function
too. There would be some optimization potential in case the function and
environment is static, or reseted each time to a constant value but it
should be possible to fetch a copy of the current environment to.
Such a pool of workers is best represented with a symbol on which certain
functions are applied which are may stored inside the symbol. This could be
archived with some overhead with the picolisp object system when compared
to a manual implementation since the worker queue should be accessible fast
and putting it in val of the symbol would be the easiest way to achieve
that.

Further thoughts:
It might be wise to give the possibility to register a callback on the
return value.
This would allow to make things more efficient.
For example:

(prog1  # Parallel background calculation of square numbers
   (mapcan '((N) (later (cons) )) (range 1 100))
   (wait NIL (full @)) )

could be:

(pool "squares.db")
(with-workerpool W '((workers . 2) (callback . '((R) (put *DB (car R)
(cadr R ))
   (mapcar '((N) (add_task 'W '((N) (cons N (* N N))) N ) (range 1 100)) )]

#Normally the with-workerpool should not finish until the queue is empty

How ever it should also be possible to do something like that:


(with-workerpool W '((callback . NIL) (return . nil) (output .
"+file") (wait . NIL))
   (for X 1000
  (add_task  'W '((N) (ifn (= N (apply '* (prime-factors N)))
 (print N))) X ] # workers run in background main thread can continue

This usage may seem overly complex at first and the proposed interface
is horrible. However i think that such an library could be an valuable
addition to picolisp.

Lets discuss the idea itself, your proposals for the interface and the
implementation.


later and output

2017-02-25 Thread Joh-Tob Schäg
I tried to parallelize the following code:
'(let N 2
   (while (> 1000 N )
  (check N)
  (inc 'N)))
where (check N) is defined as '(ifn (= N (apply '* (prime-factors N)))
(print N))

'later has the following form  '(later
place_where_to_save_the_return_result . program to execute)
However i am not interested in storing the result and (later 'NIL prog)
does not work for obvious reasons.
Furthermore (later (new) (print 8)) does not work either.
Using files as in (out "+file" (later (new) (print 8))) does not work
either.

Is there a way to run '(check N) on multiple cores at the same time and get
the results 'print-ed in to the standard output of the instance where the
process was created or in a file which was opened by it (without reopening
the file before each in print in the child process)?


Re: P35 Prime Factors

2017-02-25 Thread Joh-Tob Schäg
I verified that it works for all numbers lower than 1000.


My code:
(let N 2
   (while (> 1000 N )
  (ifn (= N (apply '* (prime-factors N)))
 (print N))
  (inc 'N)))

2017-02-25 9:58 GMT+01:00 Alexander Burger :

> Hi Lindsay, Joh-Tob,
>
> On Sat, Feb 25, 2017 at 09:36:04AM +0100, Joh-Tob Schäg wrote:
> > The purpose of the list is to increase the speed of the algorithm by
> > skipping some numbers. This is possible because of the math of
> Differences
>
> Correct.
>
> > between consecutive primes but i am currently verifying the algorithm if
> it
> > works, since the list might be wrong.
>
> I took it from Donald E. Knuth's "Art of Computer Programming", Volume 2
> (Seminumerical Algorithms). In "Factoring into Primes" on page 365 he
> writes:
>
>The sequence ... of trial divisors .. can be taken to be simply 2, 3,
> 5, 7,
>11, 13, 17, 19, 23, 25, 29, 31, 35, .. where we alternately add 2 and 4
> after
>the first three terms.
>...
>A further savings of 20 percent ... removing the numbers 30m +/- 5 ..
>
> I believe the term (let (D 2 L (1 2 2 . (4 2 4 2 4 6 2 6 .)) generates that
> sequence.
>
> ♪♫ Alex
>
>
> >
> > 2017-02-25 7:44 GMT+01:00 Lindsay John Lawrence <
> > lawrence.lindsayj...@gmail.com>:
> >
> > > Does anyone know the algorithm that is being expressed here?
> > >
> > > I am trying to understand the code... http://picolisp.com/wiki/?99p35
> > >
> > > de prime-factors (N)
> > >(make
> > >   (let (D 2  L (1 2 2 . (4 2 4 2 4 6 2 6 .))  M (sqrt N))
> > >  (while (>= M D)
> > > (if (=0 (% N D))
> > >(setq M (sqrt (setq N (/ N (link D)
> > >(inc 'D (pop 'L)) ) )
> > >  (link N) ) ) )
> > >
> > > and  having difficulties understanding the purpose of the circular
> list.
> > >
> > > /Lindsay
> > >
> > >
> > >
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Destructive element modification?

2017-02-25 Thread Alexander Burger
On Sat, Feb 25, 2017 at 09:13:46AM +0200, Mike Pechkin wrote:
> ast start point:
> http://ideone.com/zPndpA
> 
> On Sat, Feb 25, 2017 at 9:01 AM, Christopher Howard <
> christopher.how...@qlfiles.net> wrote:
> 
> > Hi list. How do I *destructively* modify the value of one element in a
> > list? E.g.
> >
> > (setq Lst (1 2 3 4))
> >
> > How do I set the second element to be 10, without creating a new list,
> > and without using "con" to change a lot of the list?

In this concrete case:

   (set (cdr Lst) 10)

or, more generally:

   (set (nth Lst 2) 10)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: P35 Prime Factors

2017-02-25 Thread Alexander Burger
Hi Lindsay, Joh-Tob,

On Sat, Feb 25, 2017 at 09:36:04AM +0100, Joh-Tob Schäg wrote:
> The purpose of the list is to increase the speed of the algorithm by
> skipping some numbers. This is possible because of the math of Differences

Correct.

> between consecutive primes but i am currently verifying the algorithm if it
> works, since the list might be wrong.

I took it from Donald E. Knuth's "Art of Computer Programming", Volume 2
(Seminumerical Algorithms). In "Factoring into Primes" on page 365 he writes:

   The sequence ... of trial divisors .. can be taken to be simply 2, 3, 5, 7,
   11, 13, 17, 19, 23, 25, 29, 31, 35, .. where we alternately add 2 and 4 after
   the first three terms.
   ...
   A further savings of 20 percent ... removing the numbers 30m +/- 5 ..

I believe the term (let (D 2 L (1 2 2 . (4 2 4 2 4 6 2 6 .)) generates that
sequence.

♪♫ Alex


> 
> 2017-02-25 7:44 GMT+01:00 Lindsay John Lawrence <
> lawrence.lindsayj...@gmail.com>:
> 
> > Does anyone know the algorithm that is being expressed here?
> >
> > I am trying to understand the code... http://picolisp.com/wiki/?99p35
> >
> > de prime-factors (N)
> >(make
> >   (let (D 2  L (1 2 2 . (4 2 4 2 4 6 2 6 .))  M (sqrt N))
> >  (while (>= M D)
> > (if (=0 (% N D))
> >(setq M (sqrt (setq N (/ N (link D)
> >(inc 'D (pop 'L)) ) )
> >  (link N) ) ) )
> >
> > and  having difficulties understanding the purpose of the circular list.
> >
> > /Lindsay
> >
> >
> >
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: BBWT

2017-02-25 Thread Alexander Burger
Hi Lindsay,

> Bijective Burrows Wheeler Transform
> https://github.com/thinknlive/picolisp-bbwt

Cool! This code looks very good! :)


> As I was working on this I realized I need to start thinking about how to
> organize my code...
> 
> The two main functions, encodeBBWT and decodeBBWT feel larger than they
> should be because I have defined smaller functions within them that use
> variables in the same scope.
> 
> My question:  Is there an 'idiomatic' or recommended way to organize module
> or project code in picolisp?

Binding the functions 'Put' and 'Bwt' locally is perfectly legal, but not really
necessary here, as they never change. So they just create (minimal) runtime
overhead. I would define them the normal way, perhaps as transient symbols if I
want to hide them from the outside world:

   (de "put" (B C)
  (let (V ...

   (de "bwt" (W)
  (let (C ...


Using a namespace is also possible, but too much overhead in my feeling for such
a small file. It would go like this:

   (symbols 'bbwt 'pico)
   (local put bwt)

   (de put (B C)  # Shadows the built-in 'put', use with care
  (let (V ...

   (de bwt (W)
  (let (C ...

   (de pico~encodeBBWT (L)
  ...

   (de pico~decodeBBWT (L)
  ...

This creates the symbol 'encodeBBWT' in the 'pico' namespace. Another (I think
better) way is:

   (de encode (L)
  ...

   (de decode (L)
  ...

and later, when used from another namespace, call it as

   (bbwt~encode ...)
   (bbwt~decode ...)


Concerning 'Debug', I would omit it here, and call (trace 'encodeBBWT) or (trace
'bbwt~encode) or (mapc trace '(bbwt~encode bbwt~decode bbwt~put bbwt~bwt) to
debug it.

Other minor improvements:

  V2 (car (cdr V)) )
->
  V2 (cadr V) )


   (while (car W)
  (if (not (cdr W))
 (Put C (car W))
 (Put (car (cdr W)) (car W)) )
->
   (while (car W)
  (Put
 (ifn (cdr W) C (cadr W))
 (car W) )

and some similar cases :)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: exercism.io

2017-02-25 Thread Alexander Burger
Hi Mike,

> I've implemented tasks from A to F:
> https://bitbucket.org/mihailp/tankfeeder/src/9de46f9e807786fdbf4a86604aca20dd25f0c19e/exercism-io/?at=default

Great! Thanks for sharing!

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: P35 Prime Factors

2017-02-25 Thread Joh-Tob Schäg
The purpose of the list is to increase the speed of the algorithm by
skipping some numbers. This is possible because of the math of Differences
between consecutive primes but i am currently verifying the algorithm if it
works, since the list might be wrong.

2017-02-25 7:44 GMT+01:00 Lindsay John Lawrence <
lawrence.lindsayj...@gmail.com>:

> Does anyone know the algorithm that is being expressed here?
>
> I am trying to understand the code... http://picolisp.com/wiki/?99p35
>
> de prime-factors (N)
>(make
>   (let (D 2  L (1 2 2 . (4 2 4 2 4 6 2 6 .))  M (sqrt N))
>  (while (>= M D)
> (if (=0 (% N D))
>(setq M (sqrt (setq N (/ N (link D)
>(inc 'D (pop 'L)) ) )
>  (link N) ) ) )
>
> and  having difficulties understanding the purpose of the circular list.
>
> /Lindsay
>
>
>


Re: Future of PicoLisp?

2017-02-25 Thread Alexander Burger
Thanks Lindsay, Mansur, good hints. I take a look at alternate ways,
hopefully without Python, to Let's Encrypt.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe