Re: altering LOCAL list elements

2017-02-10 Thread Joe Bogner
dean, is this what you are describing?

(let L (list 1 2 3)
(setq L (append L (4)))
(printsp L) )


(1 2 3 4)


The key to this is understanding how let works. It restores the prior value
after execution. See http://software-lab.de/doc/refL.html#let

Defines local variables. The value of the symbol sym - or the values of the
symbols sym in the list of the second form - ***are saved** and the symbols
are bound to the evaluated any arguments. The 64-bit version also accepts
lst arguments in the second form; they may consist only of symbols and
sublists, and match the any argument (destructuring bind). prg is executed,
then the symbols ***are restored to their original values***.



On Fri, Feb 10, 2017 at 3:22 PM, dean  wrote:

> Hi
> I've seen that I can alter local/let'd atoms? via inc/dec i.e. (inc
> 'Some_atom)
> which gets me a long way...
> ...but what about list elements?
>
>
> (setq L (0 0 0))
> (de doit ()
>#(let L (0 0 0)
>   (setq L (insert '1 (remove '1 L) 2))
>   (prinl "L is " L)
>#)
> )
>
> When I "setq" L this works but can I do it (somehow) when L is created
> with "let"?
>


Re: altering LOCAL list elements

2017-02-10 Thread Joh-Tob Schäg
Not related to your problem.
You might wanna take a look at the 'need function.

Furthermore i fail to understand your problem.

If picolisp behaves unexpected could you please describe what behavior you
expect wjat you get and provide a test case which runs the functions it
defines?

Alternativly you could define the behavior of the function you want.
Am 10.02.2017 21:28 schrieb "dean" :

> Hi
> I've seen that I can alter local/let'd atoms? via inc/dec i.e. (inc
> 'Some_atom)
> which gets me a long way...
> ...but what about list elements?
>
>
> (setq L (0 0 0))
> (de doit ()
>#(let L (0 0 0)
>   (setq L (insert '1 (remove '1 L) 2))
>   (prinl "L is " L)
>#)
> )
>
> When I "setq" L this works but can I do it (somehow) when L is created
> with "let"?
>


Re: box? on address

2017-02-10 Thread Joh-Tob Schäg
Hi Regenaxer,

I realize that there is no probkem with the evaluation of 'circ?.
Could 'later be (miss)used to cause some havick when it writes back data?
What about timer triggered code?
Am 10.02.2017 22:40 schrieb "Alexander Burger" :

> Hi Joh-Tob,
>
> > Doesn't 'circ? also set the gc bit?
>
> Well observed!! That't true, but it is the "other" mark bit. While gc uses
> the
> bit in the CDR
>
>or (X CDR) 1  # Set mark bit
>
> uses 'circ' the one in the CAR of the cell
>
>or (A) 1  # Mark
>
>
> > Could it be possible that 'circ? evaluates a term which accesses
> something
> > with a changed pointer?
>
> The bits are only set after all evaluation is done, and the raw circ
> detection
> processing runs. Then the bits are cleared (as after garbage collection
> too).
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: box? on address

2017-02-10 Thread Alexander Burger
Hi Joh-Tob,

> Doesn't 'circ? also set the gc bit?

Well observed!! That't true, but it is the "other" mark bit. While gc uses the
bit in the CDR

   or (X CDR) 1  # Set mark bit

uses 'circ' the one in the CAR of the cell

   or (A) 1  # Mark


> Could it be possible that 'circ? evaluates a term which accesses something
> with a changed pointer?

The bits are only set after all evaluation is done, and the raw circ detection
processing runs. Then the bits are cleared (as after garbage collection too).

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


Re: conc: unexpected results

2017-02-10 Thread Alexander Burger
On Fri, Feb 10, 2017 at 08:32:06PM +0100, Pierpaolo Bernardi wrote:
> On Fri, Feb 10, 2017 at 6:24 PM, Alexander Burger  
> wrote:
> 
> > Right Lindsay, this is called "nconc" in other versions of Lisp. There was 
> > the
> > convention - for some obscure reason - to put an "n" in front of the names 
> > of
> > destructive list operations: nconc, nreverse, ndelete ...
> 
> In case someone wonders, the n prefix stood for 'non-consing'

Cool! Thanks!!

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


altering LOCAL list elements

2017-02-10 Thread dean
Hi
I've seen that I can alter local/let'd atoms? via inc/dec i.e. (inc
'Some_atom)
which gets me a long way...
..but what about list elements?


(setq L (0 0 0))
(de doit ()
   #(let L (0 0 0)
  (setq L (insert '1 (remove '1 L) 2))
  (prinl "L is " L)
   #)
)

When I "setq" L this works but can I do it (somehow) when L is created with
"let"?


Re: unit testing?

2017-02-10 Thread dean
Hi andreas
That looks very good to me...thank you very much indeed!
Best Regards
Dean


On 10 February 2017 at 17:12,  wrote:

> Hi Dean
>
> PicoLisp is an interpreted language, so very dynamic.
> Therefore, why not just do it with a global flag variable?
>
> (off *Scaffolding) # do not load scaffolding
>
> 
>
> (de myCode ...)
>
> (when *Scaffolding
> (de myScaffoldingFunc1 ...)
> (de myScaffoldingFunc2 ...)
> (de myScaffoldingFunc3 ...) )
>
>
> So all the (de) is only executed if *Scaffolding is not NIL.
> (off *Scaffolding) sets global variable *Scaffolding to NIL.
> (on *Scaffolding) sets global variable to T (used as true in picolisp).
>
> This can be made even shorter:
>
> (off *Scaffolding) # or (on *Scaffolding), depending on context
>
> 
>
> (de myCode ...)
>
> `*Scaffolding # evaluate *Scaffolding during reading of the source file,
> when its NIL, (load)ing stops
>
> (de myScaffoldingFunc1 ...)
> (de myScaffoldingFunc2 ...)
> (de myScaffoldingFunc3 ...)
>
> Regards,
> beneroth
>
>
> - Original Message -
> From: dean [mailto:deangwillia...@gmail.com]
> To: picolisp@software-lab.de
> Sent: Wed, 8 Feb 2017 16:31:30 +
> Subject: Re: unit testing?
>
> Hi Alex and Christophe
> In Python that __name__ variable stops things like a local main proc from
> executing altogether...when Python detects that the module in which it
> exists no longer needs it because it is being loaded by a bigger program,
> which accesses the module's code like the local main does i.e. The local
> main is hidden from Python under such circumstances.
>
> I was wondering about the "once" situation toobecause I have
> experienced "function redeclared" or some such popping up. If you're
> telling me that such messages are inconsequential compared to the benefits
> of developing in a way which causes that.that's fine by me because it's
> easier to ignore the redeclaration messages than not :)
>
> Because PL seems to allow forward referencing...I was
> 1 Putting all the scaffolding down the bottom with my local main so it's
> all in the same place.
> 2 Commenting it all out...
> 3 Loading the module into the wider program and then
> 4 Comment the helper functions back in as PL reported their absence.
> Obviously the local main stays commented out.
> This seems fairly convenient but my interpretation of the above is I only
> need to comment out the local main and if that's right that's great.
>
> Thank you Chrostophe for the further explanation re Python.
>
> Best Regards
> Dean
>
>
>
>
>
>
> On 8 February 2017 at 14:47, Christophe Gragnic <
> christophegrag...@gmail.com
> > wrote:
>
> > On Wed, Feb 8, 2017 at 12:13 PM, Alexander Burger 
> > wrote:
> > >> I'm thinking of Python's `if __name__ == '__main__' and Perl's unless
> > >> (caller) {...}
> > >
> > > I don't know Python and Perl well enough. But perhaps 'once' is what
> you
> > think
> > > of?
> > >
> > > (once (load "xxx.l"))
> >
> > No, it's different.
> >
> > In Python there's a «magic» variable named __name__.
> > As files can be:
> > - imported from another script/module
> > - interpreted directly from top leve
> > it provides a trick to distinguish between those two ways to use a
> > script/module.
> > See here:
> > https://docs.python.org/3/library/__main__.html
> >
> >
> > chri
> > --
> > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subjectUnsubscribe
> >
>
>
>


Re: Segfault with huge list...?

2017-02-10 Thread Lindsay John Lawrence
I think I'll start keeping a list =) of picolisp's pleasant surprises.
/Lindsay

On Fri, Feb 10, 2017 at 11:06 AM, Joh-Tob Schäg  wrote:

> Linsday when you want to prevent values from neing printed take a look at
> the 'nil function.
>
>


Re: Segfault with huge list...?

2017-02-10 Thread Joh-Tob Schäg
Linsday when you want to prevent values from neing printed take a look at
the 'nil function.
Am 10.02.2017 19:44 schrieb "Lindsay John Lawrence" <
lawrence.lindsayj...@gmail.com>:

> If it even matters, the overhead of recurse is slowest here.
> So impressive that picolisp can iterate/recurse over a 10M element list in
> these times.
> (VirtualBox VM, 4GB, 1Core, with 64bit Debian).
>
> ... and 'make' is a lot more useful that I first realized.
>
> /Lindsay
>
> # Iterative
> (de sumi (L)
>(let (Sum (car L))
>   (while (setq L (cdr L))
>  (setq Sum (+ Sum (car L))) ) ) )
>
> # Recurse
> (de sumr (N)
>(cond
>   ((not N) 0)
>   (T (+ (car N) (sumr (cdr N ) )
>
> # This may take a moment...
> : (setq bigly (range 1 1000) D NIL) -> NIL
> : (bench (apply '+ bigly))  0.097 sec  -> 500500
> : (bench (sum '+ bigly))0.139 sec  -> 500500
> : (bench (sumi bigly))  0.275 sec  -> 500500
> : (bench (sumr bigly))  0.639 sec  -> 500500
>
> : (setq bigly (need 1000 1) D NIL) -> NIL
> : (bench (apply '+ bigly))  0.099 sec  -> 1000
> : (bench (sum '+ bigly))0.139 sec  -> 1000
> : (bench (sumi bigly))  0.272 sec  -> 1000
> : (bench (sumr bigly))  0.643 sec  -> 1000
>
> : (bench (setq bigly (make (for X 1000 (link (+ (- 1000 X) 1)
> (length bigly))0.437 sec -> 1000
> : (bench (sumr bigly))  0.630 sec  -> 500500
> : (bench (sumi bigly))  0.279 sec  -> 500500
>
>
> Am 10.02.2017 15:28 schrieb "Mike Pechkin" :
>>>
 hi,

 On Fri, Feb 10, 2017 at 3:07 PM, Christopher Howard <
 christopher.how...@qlfiles.net> wrote:

 > Hi list. When I try to do
 >
 > (apply '+ (range 1 100)
 >


 ​List of ​millions of items is not a problem.
 Problem how you use it.
 (apply) is not for free, ​It *creates*​ a function call with a million
 of
 arguments.
 Stack size make sense.


 > I get segfault. I thought maybe this was some kind of internal
 > limitation of the apply function, so I defined a foldl:
 >
 > (de foldl (Fn Acc Lst)
 > (if (== () Lst) Acc
 > (let Acc2 (Fn Acc (car Lst))
 >  (foldl Fn Acc2 (cdr Lst)) ) ) )
 >
 > : (foldl '+ 0 (range 1 1000))
 > (foldl '+ 0 (range 1 1000))
 > -> 500500
 > : (foldl '+ 0 (range 1 100))
 > (foldl '+ 0 (range 1 100))
 >
 >
 ​
 Stack size makes sense too.
 I like recursions this way:

 (de rec1 (F A L)
(if L
   (rec1 F (inc 'A (++ L)) L)
   A ) )

 recursion with hidden accumulator from outer call and car-cdr:
 (de rec2 (F L A)
(default A 0)
(if L
   (rec2 F (cdr L) (inc 'A (car L)))
   A ) )
 The call will be:  (rec2 '+ (range 1 100)))


 As recursion just loop you can implement it without big stack too:
 (de sum1 (L)
(let N 0
   (for I L
  (inc 'N I) ) ) )

 even without list creation:
 (de sum2 (X)
(let N 0
   (for I X
  (inc 'N I) ) ) )


 And finally, that's why (sum) was implemented:
 (sum prog (range 1 100)))


 Bonus: for practice write recursion function to sum numbers without
 (range)
>>>
>>>
>>
>


Re: box? on address

2017-02-10 Thread Joh-Tob Schäg
Doesn't 'circ? also set the gc bit?
Could it be possible that 'circ? evaluates a term which accesses something
with a changed pointer?
Am 10.02.2017 18:12 schrieb "Alexander Burger" :

> H Danilo,
>
> > Please take a quick look at [path "@doc64/structures"] and
> > source code of `car' and `val'.
> >
> > I am not sure what will happen if GC bit is 1.
>
> This is a good question. The interpreter would crash with a bus error.
> Fortunately this won't happen because this bit is guaranteed to be set only
> while GC runs.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Segfault with huge list...?

2017-02-10 Thread Lindsay John Lawrence
If it even matters, the overhead of recurse is slowest here.
So impressive that picolisp can iterate/recurse over a 10M element list in
these times.
(VirtualBox VM, 4GB, 1Core, with 64bit Debian).

.. and 'make' is a lot more useful that I first realized.

/Lindsay

# Iterative
(de sumi (L)
   (let (Sum (car L))
  (while (setq L (cdr L))
 (setq Sum (+ Sum (car L))) ) ) )

# Recurse
(de sumr (N)
   (cond
  ((not N) 0)
  (T (+ (car N) (sumr (cdr N ) )

# This may take a moment...
: (setq bigly (range 1 1000) D NIL) -> NIL
: (bench (apply '+ bigly))  0.097 sec  -> 500500
: (bench (sum '+ bigly))0.139 sec  -> 500500
: (bench (sumi bigly))  0.275 sec  -> 500500
: (bench (sumr bigly))  0.639 sec  -> 500500

: (setq bigly (need 1000 1) D NIL) -> NIL
: (bench (apply '+ bigly))  0.099 sec  -> 1000
: (bench (sum '+ bigly))0.139 sec  -> 1000
: (bench (sumi bigly))  0.272 sec  -> 1000
: (bench (sumr bigly))  0.643 sec  -> 1000

: (bench (setq bigly (make (for X 1000 (link (+ (- 1000 X) 1)
(length bigly))0.437 sec -> 1000
: (bench (sumr bigly))  0.630 sec  -> 500500
: (bench (sumi bigly))  0.279 sec  -> 500500


Am 10.02.2017 15:28 schrieb "Mike Pechkin" :
>>
>>> hi,
>>>
>>> On Fri, Feb 10, 2017 at 3:07 PM, Christopher Howard <
>>> christopher.how...@qlfiles.net> wrote:
>>>
>>> > Hi list. When I try to do
>>> >
>>> > (apply '+ (range 1 100)
>>> >
>>>
>>>
>>> ​List of ​millions of items is not a problem.
>>> Problem how you use it.
>>> (apply) is not for free, ​It *creates*​ a function call with a million of
>>> arguments.
>>> Stack size make sense.
>>>
>>>
>>> > I get segfault. I thought maybe this was some kind of internal
>>> > limitation of the apply function, so I defined a foldl:
>>> >
>>> > (de foldl (Fn Acc Lst)
>>> > (if (== () Lst) Acc
>>> > (let Acc2 (Fn Acc (car Lst))
>>> >  (foldl Fn Acc2 (cdr Lst)) ) ) )
>>> >
>>> > : (foldl '+ 0 (range 1 1000))
>>> > (foldl '+ 0 (range 1 1000))
>>> > -> 500500
>>> > : (foldl '+ 0 (range 1 100))
>>> > (foldl '+ 0 (range 1 100))
>>> >
>>> >
>>> ​
>>> Stack size makes sense too.
>>> I like recursions this way:
>>>
>>> (de rec1 (F A L)
>>>(if L
>>>   (rec1 F (inc 'A (++ L)) L)
>>>   A ) )
>>>
>>> recursion with hidden accumulator from outer call and car-cdr:
>>> (de rec2 (F L A)
>>>(default A 0)
>>>(if L
>>>   (rec2 F (cdr L) (inc 'A (car L)))
>>>   A ) )
>>> The call will be:  (rec2 '+ (range 1 100)))
>>>
>>>
>>> As recursion just loop you can implement it without big stack too:
>>> (de sum1 (L)
>>>(let N 0
>>>   (for I L
>>>  (inc 'N I) ) ) )
>>>
>>> even without list creation:
>>> (de sum2 (X)
>>>(let N 0
>>>   (for I X
>>>  (inc 'N I) ) ) )
>>>
>>>
>>> And finally, that's why (sum) was implemented:
>>> (sum prog (range 1 100)))
>>>
>>>
>>> Bonus: for practice write recursion function to sum numbers without
>>> (range)
>>
>>
>


Re: conc: unexpected results

2017-02-10 Thread Alexander Burger
On Fri, Feb 10, 2017 at 10:31:20AM +0100, pd wrote:
> On Fri, Feb 10, 2017 at 6:47 AM, Lindsay John Lawrence <
> > Apologies for bothering everyone with this. It took some research (there
> > is surprising little discussion of the function online or even in most
> > books), but I at least understand how it works now.
> 
> It would be great if you explain how it works, at least for me since I
> cannot understand why 2. returns NIL rather than (A)

'conc' is the destructive version of 'append'.

Right Lindsay, this is called "nconc" in other versions of Lisp. There was the
convention - for some obscure reason - to put an "n" in front of the names of
destructive list operations: nconc, nreverse, ndelete ...

'conc' traverses each list argument and puts the next argument into the CDR of
the last cell:

   : (conc (1 2) (3))
   -> (1 2 3)

This has the consequence that if the last arg is atomic

   : (conc (1 2) 'a)
   -> (1 2 . a)

that atom is of course stored in that last CDR.

Now, if yet another argument follows, this last CDR gets overwritten

   : (conc (1 2) 'a (3))
   -> (1 2 3)

So as a result atomic arguments are simply lost. This happens also if the atom
is the first argument

   : (conc 'a (1 2))
   -> (1 2)


BTW, all the above applies to 'append' as well.

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


Re: unit testing?

2017-02-10 Thread andreas
Hi Dean

PicoLisp is an interpreted language, so very dynamic.
Therefore, why not just do it with a global flag variable?

(off *Scaffolding) # do not load scaffolding

...

(de myCode ...)

(when *Scaffolding
(de myScaffoldingFunc1 ...)
(de myScaffoldingFunc2 ...)
(de myScaffoldingFunc3 ...) )


So all the (de) is only executed if *Scaffolding is not NIL.
(off *Scaffolding) sets global variable *Scaffolding to NIL.
(on *Scaffolding) sets global variable to T (used as true in picolisp).

This can be made even shorter:

(off *Scaffolding) # or (on *Scaffolding), depending on context

...

(de myCode ...)

`*Scaffolding # evaluate *Scaffolding during reading of the source file, when 
its NIL, (load)ing stops

(de myScaffoldingFunc1 ...)
(de myScaffoldingFunc2 ...)
(de myScaffoldingFunc3 ...)

Regards,
beneroth

- Original Message -
From: dean [mailto:deangwillia...@gmail.com]
To: picolisp@software-lab.de
Sent: Wed, 8 Feb 2017 16:31:30 +
Subject: Re: unit testing?

Hi Alex and Christophe
In Python that __name__ variable stops things like a local main proc from
executing altogether...when Python detects that the module in which it
exists no longer needs it because it is being loaded by a bigger program,
which accesses the module's code like the local main does i.e. The local
main is hidden from Python under such circumstances.

I was wondering about  the "once" situation toobecause I have
experienced "function redeclared" or some such popping up. If you're
telling me that such messages are inconsequential compared to the benefits
of developing in a way which causes that.that's fine by me because it's
easier to ignore the redeclaration messages than not :)

Because PL seems to allow forward referencing...I was
1 Putting all the scaffolding down the bottom with my local main so it's
all in the same place.
2 Commenting it all out...
3 Loading the module into the wider program and then
4 Comment the helper functions back in as PL reported their absence.
Obviously the local main stays commented out.
This seems fairly convenient but my interpretation of the above is I only
need to comment out the local main and if that's right that's great.

Thank you Chrostophe for the further explanation re Python.

Best Regards
Dean






On 8 February 2017 at 14:47, Christophe Gragnic  wrote:

> On Wed, Feb 8, 2017 at 12:13 PM, Alexander Burger 
> wrote:
> >> I'm thinking of Python's `if __name__ == '__main__' and Perl's unless
> >> (caller) {...}
> >
> > I don't know Python and Perl well enough. But perhaps 'once' is what you
> think
> > of?
> >
> >(once (load "xxx.l"))
>
> No, it's different.
>
> In Python there's a «magic» variable named __name__.
> As files can be:
> - imported from another script/module
> - interpreted directly from top leve
> it provides a trick to distinguish between those two ways to use a
> script/module.
> See here:
> https://docs.python.org/3/library/__main__.html
>
>
> chri
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subjectUnsubscribe
>




Re: box? on address

2017-02-10 Thread Alexander Burger
H Danilo,

> Please take a quick look at [path "@doc64/structures"] and
> source code of `car' and `val'.
> 
> I am not sure what will happen if GC bit is 1.

This is a good question. The interpreter would crash with a bus error.
Fortunately this won't happen because this bit is guaranteed to be set only
while GC runs.

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


Re: binding free symbols in a lambda definition

2017-02-10 Thread Alexander Burger
Hi Lindsay,

> # append
> : (bench (let (N ()) (for X 1 (setq N (append N '(NIL (length N)))
> 0.548 sec
> -> 1
> 
> # cons
> : (bench (let (N '()) (for X 1 (setq N (cons NIL N))) (length N)))
> 0.000 sec
> -> 1

'append' in such a loop is a lot slower than a straightforward 'cons', because
'cons' creates only a single new cell and puts it in front of the existing list,
while 'append' makes a copy of the whole list (as it is non-destructive) and
then 'conc's the new cell.


> # conc
> : (bench (let (N (list)) (for X  (conc N (list))) (length N)))
> 0.067 sec
> -> 1
> ...
> Interestingly, I was expecting conc to be faster then (setq..(cons..). At
> least in this case, it was not.
> 
'conc' avoids the copying, but still traverses the (longer and longer) list each
time.


To build really long lists it is better to use (make ... (link ...))

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


Re: Segfault with huge list...?

2017-02-10 Thread Mike Pechkin
yea

On Fri, Feb 10, 2017 at 5:21 PM, Joh-Tob Schäg  wrote:

> (de natsum (N)
>   (if (=0 N)
> 0
> ( +  N
>   ( natsum ( dec N)
>
> Like that?
> Am 10.02.2017 15:28 schrieb "Mike Pechkin" :
>
>> hi,
>>
>> On Fri, Feb 10, 2017 at 3:07 PM, Christopher Howard <
>> christopher.how...@qlfiles.net> wrote:
>>
>> > Hi list. When I try to do
>> >
>> > (apply '+ (range 1 100)
>> >
>>
>>
>> ​List of ​millions of items is not a problem.
>> Problem how you use it.
>> (apply) is not for free, ​It *creates*​ a function call with a million of
>> arguments.
>> Stack size make sense.
>>
>>
>> > I get segfault. I thought maybe this was some kind of internal
>> > limitation of the apply function, so I defined a foldl:
>> >
>> > (de foldl (Fn Acc Lst)
>> > (if (== () Lst) Acc
>> > (let Acc2 (Fn Acc (car Lst))
>> >  (foldl Fn Acc2 (cdr Lst)) ) ) )
>> >
>> > : (foldl '+ 0 (range 1 1000))
>> > (foldl '+ 0 (range 1 1000))
>> > -> 500500
>> > : (foldl '+ 0 (range 1 100))
>> > (foldl '+ 0 (range 1 100))
>> >
>> >
>> ​
>> Stack size makes sense too.
>> I like recursions this way:
>>
>> (de rec1 (F A L)
>>(if L
>>   (rec1 F (inc 'A (++ L)) L)
>>   A ) )
>>
>> recursion with hidden accumulator from outer call and car-cdr:
>> (de rec2 (F L A)
>>(default A 0)
>>(if L
>>   (rec2 F (cdr L) (inc 'A (car L)))
>>   A ) )
>> The call will be:  (rec2 '+ (range 1 100)))
>>
>>
>> As recursion just loop you can implement it without big stack too:
>> (de sum1 (L)
>>(let N 0
>>   (for I L
>>  (inc 'N I) ) ) )
>>
>> even without list creation:
>> (de sum2 (X)
>>(let N 0
>>   (for I X
>>  (inc 'N I) ) ) )
>>
>>
>> And finally, that's why (sum) was implemented:
>> (sum prog (range 1 100)))
>>
>>
>> Bonus: for practice write recursion function to sum numbers without
>> (range)
>
>


Re: Segfault with huge list...?

2017-02-10 Thread Joh-Tob Schäg
(de natsum (N)
  (if (=0 N)
0
( +  N
  ( natsum ( dec N)

Like that?
Am 10.02.2017 15:28 schrieb "Mike Pechkin" :

> hi,
>
> On Fri, Feb 10, 2017 at 3:07 PM, Christopher Howard <
> christopher.how...@qlfiles.net> wrote:
>
> > Hi list. When I try to do
> >
> > (apply '+ (range 1 100)
> >
>
>
> ​List of ​millions of items is not a problem.
> Problem how you use it.
> (apply) is not for free, ​It *creates*​ a function call with a million of
> arguments.
> Stack size make sense.
>
>
> > I get segfault. I thought maybe this was some kind of internal
> > limitation of the apply function, so I defined a foldl:
> >
> > (de foldl (Fn Acc Lst)
> > (if (== () Lst) Acc
> > (let Acc2 (Fn Acc (car Lst))
> >  (foldl Fn Acc2 (cdr Lst)) ) ) )
> >
> > : (foldl '+ 0 (range 1 1000))
> > (foldl '+ 0 (range 1 1000))
> > -> 500500
> > : (foldl '+ 0 (range 1 100))
> > (foldl '+ 0 (range 1 100))
> >
> >
> ​
> Stack size makes sense too.
> I like recursions this way:
>
> (de rec1 (F A L)
>(if L
>   (rec1 F (inc 'A (++ L)) L)
>   A ) )
>
> recursion with hidden accumulator from outer call and car-cdr:
> (de rec2 (F L A)
>(default A 0)
>(if L
>   (rec2 F (cdr L) (inc 'A (car L)))
>   A ) )
> The call will be:  (rec2 '+ (range 1 100)))
>
>
> As recursion just loop you can implement it without big stack too:
> (de sum1 (L)
>(let N 0
>   (for I L
>  (inc 'N I) ) ) )
>
> even without list creation:
> (de sum2 (X)
>(let N 0
>   (for I X
>  (inc 'N I) ) ) )
>
>
> And finally, that's why (sum) was implemented:
> (sum prog (range 1 100)))
>
>
> Bonus: for practice write recursion function to sum numbers without (range)


Re: Segfault with huge list...?

2017-02-10 Thread Mike Pechkin
hi,

On Fri, Feb 10, 2017 at 3:07 PM, Christopher Howard <
christopher.how...@qlfiles.net> wrote:

> Hi list. When I try to do
>
> (apply '+ (range 1 100)
>


​List of ​millions of items is not a problem.
Problem how you use it.
(apply) is not for free, ​It *creates*​ a function call with a million of
arguments.
Stack size make sense.


> I get segfault. I thought maybe this was some kind of internal
> limitation of the apply function, so I defined a foldl:
>
> (de foldl (Fn Acc Lst)
> (if (== () Lst) Acc
> (let Acc2 (Fn Acc (car Lst))
>  (foldl Fn Acc2 (cdr Lst)) ) ) )
>
> : (foldl '+ 0 (range 1 1000))
> (foldl '+ 0 (range 1 1000))
> -> 500500
> : (foldl '+ 0 (range 1 100))
> (foldl '+ 0 (range 1 100))
>
>
​
Stack size makes sense too.
I like recursions this way:

(de rec1 (F A L)
   (if L
  (rec1 F (inc 'A (++ L)) L)
  A ) )

recursion with hidden accumulator from outer call and car-cdr:
(de rec2 (F L A)
   (default A 0)
   (if L
  (rec2 F (cdr L) (inc 'A (car L)))
  A ) )
The call will be:  (rec2 '+ (range 1 100)))


As recursion just loop you can implement it without big stack too:
(de sum1 (L)
   (let N 0
  (for I L
 (inc 'N I) ) ) )

even without list creation:
(de sum2 (X)
   (let N 0
  (for I X
 (inc 'N I) ) ) )


And finally, that's why (sum) was implemented:
(sum prog (range 1 100)))


Bonus: for practice write recursion function to sum numbers without (range)

Re: binding free symbols in a lambda definition

2017-02-10 Thread Joh-Tob Schäg
Why not
"(de myf FList
 (apply (car Flist) (cdr Flist))"?
Am 08.02.2017 05:04 schrieb "pd" :

> Hello,
>
> I wonder if there is any way to bind a free symbol in a lambda in order to
> pass the lambda to a defined function (for example)
>
> What I want to do is something like this:
>
> (de myf (f l) (f l))
>
> (let l 99 (myf '((x) (+ (car x) l)) (1 2)))
>
> I want it to return 100 but it fails with an error (1 2) number expected
>
> this is because free symbol l in lambda ((x) (+ (car x) l)) is not bind by
> let as pretended because of quoting of lambda
>
> In other words, I think the problem is quoting avoids let binding as in:
>
> (setq f (let n 10 '((x) (+ x n -> ((x) (+ x n))
>
> but I want it to return -> ((x) (+ x 10))
>
> or using the typicall example:
>
> (de adder (n) '((x) (+ x n)))  ->  ((n) '((x) (+ x n)))
>
> so (adder 1) should return ((x) (+ x 1)) but it returns ((x) (+ x n))
>
> Is there any way to manage this?  Something similar to "expand" in newlisp
> will do the job:
>
> newlisp:
>(define (badadder n) (lambda (x) (+ x n)))
>(badadder 3) -> (lambda (x) (+ x n))
>(define (adder n) (expand (lambda (x) (+ x n)) 'n))
>(adder 3) -> (lambda (x) (+ x 3))
>
> The fist example in newlisp will be:
>
> (define (myf f l) (f l))
>
> (let ((l 99)) (myf (lambda (x) (+ (first x) l)) '(1 2)))
>
> which fails for same reason picolisp fails but in newlisp the solution is:
>
> (define (myf f l) (f l))
>
> (let ((l 99)) (myf (expand (lambda (x) (+ (first x) l)) 'l) '(1 2)))  ->
> 100
>
>
> thanks
>
>
>


Re: Segfault with huge list...?

2017-02-10 Thread Joh-Tob Schäg
That sounds very plausible.
Am 10.02.2017 14:35 schrieb "Joe Bogner" :

> It sounds like it's exceeding the stack size. Have you tried setting it to
> unlimited? ulimit -s unlimited
>
> http://www.mail-archive.com/picolisp@software-lab.de/msg01203.html
>
> On Fri, Feb 10, 2017 at 8:07 AM, Christopher Howard <
> christopher.how...@qlfiles.net> wrote:
>
>> Hi list. When I try to do
>>
>> (apply '+ (range 1 100)
>>
>> I get segfault. I thought maybe this was some kind of internal
>> limitation of the apply function, so I defined a foldl:
>>
>> (de foldl (Fn Acc Lst)
>> (if (== () Lst) Acc
>> (let Acc2 (Fn Acc (car Lst))
>>  (foldl Fn Acc2 (cdr Lst)) ) ) )
>>
>> : (foldl '+ 0 (range 1 1000))
>> (foldl '+ 0 (range 1 1000))
>> -> 500500
>> : (foldl '+ 0 (range 1 100))
>> (foldl '+ 0 (range 1 100))
>>
>> .and again, a segfault.
>>
>> Am I doing something wrong?
>>
>> --
>> https://qlfiles.net
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>


Re: Segfault with huge list...?

2017-02-10 Thread Joe Bogner
It sounds like it's exceeding the stack size. Have you tried setting it to
unlimited? ulimit -s unlimited

http://www.mail-archive.com/picolisp@software-lab.de/msg01203.html

On Fri, Feb 10, 2017 at 8:07 AM, Christopher Howard <
christopher.how...@qlfiles.net> wrote:

> Hi list. When I try to do
>
> (apply '+ (range 1 100)
>
> I get segfault. I thought maybe this was some kind of internal
> limitation of the apply function, so I defined a foldl:
>
> (de foldl (Fn Acc Lst)
> (if (== () Lst) Acc
> (let Acc2 (Fn Acc (car Lst))
>  (foldl Fn Acc2 (cdr Lst)) ) ) )
>
> : (foldl '+ 0 (range 1 1000))
> (foldl '+ 0 (range 1 1000))
> -> 500500
> : (foldl '+ 0 (range 1 100))
> (foldl '+ 0 (range 1 100))
>
> ..and again, a segfault.
>
> Am I doing something wrong?
>
> --
> https://qlfiles.net
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Segfault with huge list...?

2017-02-10 Thread Joh-Tob Schäg
Maybe you want to try (nil (range 1 100)) and see if the problem is
there.
Am 10.02.2017 14:24 schrieb "Joh-Tob Schäg" :

> I had a similar experience. It tends to happen if you allocate to much at
> once. Should be around 16 Megabyte in this case which normally is no
> problem.
>
> If you have such a long list and want to apply functions to it I would use
> generators instead.
> They are less ram intensive.
>
> You do things wrong.
> For example you still forget to close you parathesis. This will leave us
> in a unresolved tension all day. Obligatory XKCD: https://xkcd.com/859/
> Am 10.02.2017 14:15 schrieb "Christopher Howard" <
> christopher.how...@qlfiles.net>:
>
>> Hi list. When I try to do
>>
>> (apply '+ (range 1 100)
>>
>> I get segfault. I thought maybe this was some kind of internal
>> limitation of the apply function, so I defined a foldl:
>>
>> (de foldl (Fn Acc Lst)
>> (if (== () Lst) Acc
>> (let Acc2 (Fn Acc (car Lst))
>>  (foldl Fn Acc2 (cdr Lst)) ) ) )
>>
>> : (foldl '+ 0 (range 1 1000))
>> (foldl '+ 0 (range 1 1000))
>> -> 500500
>> : (foldl '+ 0 (range 1 100))
>> (foldl '+ 0 (range 1 100))
>>
>> ..and again, a segfault.
>>
>> Am I doing something wrong?
>>
>> --
>> https://qlfiles.net
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>


Re: Segfault with huge list...?

2017-02-10 Thread Joh-Tob Schäg
I had a similar experience. It tends to happen if you allocate to much at
once. Should be around 16 Megabyte in this case which normally is no
problem.

If you have such a long list and want to apply functions to it I would use
generators instead.
They are less ram intensive.

You do things wrong.
For example you still forget to close you parathesis. This will leave us in
a unresolved tension all day. Obligatory XKCD: https://xkcd.com/859/
Am 10.02.2017 14:15 schrieb "Christopher Howard" <
christopher.how...@qlfiles.net>:

> Hi list. When I try to do
>
> (apply '+ (range 1 100)
>
> I get segfault. I thought maybe this was some kind of internal
> limitation of the apply function, so I defined a foldl:
>
> (de foldl (Fn Acc Lst)
> (if (== () Lst) Acc
> (let Acc2 (Fn Acc (car Lst))
>  (foldl Fn Acc2 (cdr Lst)) ) ) )
>
> : (foldl '+ 0 (range 1 1000))
> (foldl '+ 0 (range 1 1000))
> -> 500500
> : (foldl '+ 0 (range 1 100))
> (foldl '+ 0 (range 1 100))
>
> ..and again, a segfault.
>
> Am I doing something wrong?
>
> --
> https://qlfiles.net
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Segfault with huge list...?

2017-02-10 Thread Christopher Howard
Hi list. When I try to do

(apply '+ (range 1 100)

I get segfault. I thought maybe this was some kind of internal
limitation of the apply function, so I defined a foldl:

(de foldl (Fn Acc Lst)
(if (== () Lst) Acc
(let Acc2 (Fn Acc (car Lst))
 (foldl Fn Acc2 (cdr Lst)) ) ) )

: (foldl '+ 0 (range 1 1000))
(foldl '+ 0 (range 1 1000))
-> 500500
: (foldl '+ 0 (range 1 100))
(foldl '+ 0 (range 1 100))

..and again, a segfault.

Am I doing something wrong?

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


Re: conc: unexpected results

2017-02-10 Thread pd
On Fri, Feb 10, 2017 at 6:47 AM, Lindsay John Lawrence <
lawrence.lindsayj...@gmail.com> wrote:

>
> Apologies for bothering everyone with this. It took some research (there
> is surprising little discussion of the function online or even in most
> books), but I at least understand how it works now.
>

It would be great if you explain how it works, at least for me since I
cannot understand why 2. returns NIL rather than (A)


Re: conc: unexpected results

2017-02-10 Thread Danilo Kordic
Hi Lindsay.

AFAIK there is only one empty `list' in PL, and that is `NIL'.  So
after `conc'atenating to it's end it would no longer be empty.

How about:

[de ex1 []
  [make
[do 10
  [link 'A] ] ] ]

[de ex2 []
  [let [R [list]]
[do 10
  [conc R [list 'A]] ]
# Will have to find the end of `R' each time!!
# Even worse if `R' is `circ'ular, which will result in
infinite recursion and out of stack memory.
# In Your second implementation `'[A]' was `conc'ed to itself,
which resulted in `circ'ular list `[A .]'.
  # : [setq L1 '[A]] [conc [] L1 L1]
  # -> [A .]
# To avoid that it was corrected to `[list 'A]'.
(cdr R) ] ]

[de ex3 [N]
  [default N 10]
  [let [R []]
[for I 10
  [fifo 'R I] ]
[prog1 (cdr R)
  (con R []) ] ] ]
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: box? on address

2017-02-10 Thread Danilo Kordic
A few more examples:

: [setq S1 "A"]
-> "A"
: (box? S1)
-> NIL
: (name S1 "")
-> "NIL"  # ?!
: S1
-> "NIL"
: (name NIL)
-> NIL  # ?!
: (name 'S1)
-> "S1"

: [setq B1 [box 'val]]
-> $177002116445201
: (val B1)
-> val
: (name B1)
-> NIL
: (name S1 B1)
-> $177002116444132
: (name S1)
-> NIL
: (box? S1)
-> $177002116444132


Hi pd.

Isn't [doc 'car] clear enough?

Please take a quick look at [path "@doc64/structures"] and
source code of `car' and `val'.

I am not sure what will happen if GC bit is 1.
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe