Re: possible bug in miniPicoLisp?

2023-11-29 Thread C K Kashyap
Thanks Alex - half a dozen worked in my example :)

I completely get the idea of the inefficiency of CELLS=1 - the segfault
however seems like a silent bug (more likely some optimistic avoidance of a
NULL check somewhere perhaps). What do you think?

I say this because, even with CELLS=1, most of the stuff just works
(meaning no segfault - granted, highly inefficient)
If sample.l is the following - no problem
(de test (Pat . Prg)
   (bind (fish pat? Pat)
  (unless (match Pat (run Prg 1))
 (msg Prg)
 (quit 'fail Pat) ) ) )

(test '(B) (find pair (1 A 2 (B) 3 CDE)))
(test 4 (find > (1 2 3 4 5 6) (6 5 4 3 2 1)))
(test 4 (find '((A B) (> A B)) (1 2 3 4 5 6) (6 5 4 3 2 1)))
(let (A -1  B 2  C 3)
   (test 'B (find '((X) (gt0 (val X))) '(A B C)))
   (test 2 @@) )
# (test "h"
#(pick '((X) (get X 'str))
#   (list (box) (prog1 (box) (put @ 'str "Hello")) (box)) ) )


Regards,
Kashyap

On Tue, Nov 28, 2023 at 10:51 PM Alexander Burger 
wrote:

> Hi Kashyap,
>
> > I attempted to use 1 as the CELLS value in pico.h and immediately ran
> into
> > segfault
>
> Yes, this is not a good idea ;)
>
> CELLS is the number of cells per heap
>
>typedef struct heap {
>   cell cells[CELLS];
>   struct heap *next;
>} heap;
>
> and PicoLisp allocates as many heaps as needed.
>
> Setting it to 1 creates a huge overhead, because then you'll have one
> 'next'
> link for every cell.
>
> The cells in the heaps are maintained to hold internal linked lists for the
> unused cells. Probably this will not work if CELLS is 1.
>
>
> > Why am I trying CELLS = 1? Just poking around - I was just trying to
> figure
> > out the min number of CELLS I needed for certain programs.
>
> You can get the number of cells in a function with 'size':
>
>: (size '(a b c))
>-> 3
>
>: (pp 'test)
>(de test ("Pat" . "Prg")
>   (bind (fish pat? "Pat")
>  (unless (match "Pat" (run "Prg"))
> (msg "Prg")
> (quit "'test' failed" "Pat") ) ) )
>-> test
>
>: (size test)
>-> 23
>
> Even a minimal system needs a few thousand cells.
>
> Setting CELLS to just a few dozens would work, but the overhead of
> maintaining
> so many heaps will become relatively large.
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: possible bug in miniPicoLisp?

2023-11-29 Thread Alexander Burger
On Wed, Nov 29, 2023 at 08:08:33PM -0800, C K Kashyap wrote:
> Thanks Alex - half a dozen worked in my example :)

Great :)

> I completely get the idea of the inefficiency of CELLS=1 - the segfault

OK

> however seems like a silent bug (more likely some optimistic avoidance of a
> NULL check somewhere perhaps). What do you think?

Yes, it is definitely a bug if YOU set the heap to a bad size. As long as it is
big enough, a runtime check is meaningless and will never fire.

☺/ A!ex

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