Re: Segfault with huge list...?
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ägwrote: > Linsday when you want to prevent values from neing printed take a look at > the 'nil function. > >
Re: Segfault with huge list...?
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: Segfault with huge list...?
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: Segfault with huge list...?
yea On Fri, Feb 10, 2017 at 5:21 PM, Joh-Tob Schägwrote: > (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...?
(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...?
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...?
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...?
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...?
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...?
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...?
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