​​
The initial iterative replacement solution I came up with (below) quickly
runs out of resources as it has to build the entire list before starting to
draw.

​What error did you get?
How much resources does picolisp use?
Do you call ulimit before?​


I think you may have some fundamental problems with garabarage allocation.
Please see if you understand that code.

(de expensive-list-increaser (A N)
   (default N 1)
   (prinl "call: " N)
   (if A
      (cons
          (+ 1 (car A))
          (expensive-list-increaser
              (copy (prinl (cdr A)))
              (inc N))))
   (prinl "A of " N " is no no longer refernced after the function number "
N " returns")
   @@)
(de compreku (D) (expensive-list-increaser (range 1 D))

Picolisp can not garbage collect A of the first call until all other are
finished since the first A could be needed inside first call at a later
point. This is related to PicoLisp not having tail recursion.
You also need to understand that 'mapcar and 'map returns a new list not
the old one modified. This means you create a copy of the list with each
mapcar the longest of which is only cleared after the first recursive call
is finished.

(de compiter (D) (for ( N . A) (range 1 D)
  (prinl "call: " N)
  (prinl (copy A))
  (prinl "The copy of A is no longer accessible so it can be deallocated")))

​# : (compreku 5)
call: 1
2345
call: 2
345
call: 3
45
call: 4
5
call: 5

call: 6
A of 6 is no no longer refernced after the function number 6 returns
A of 5 is no no longer refernced after the function number 5 returns
A of 4 is no no longer refernced after the function number 4 returns
A of 3 is no no longer refernced after the function number 3 returns
A of 2 is no no longer refernced after the function number 2 returns Y
A of 1 is no no longer refernced after the function number 1 returns
​
#: (compiter 5)
call: 1
1
The copy of A is no longer accessible so it can be deallocated
call: 2
2
The copy of A is no longer accessible so it can be deallocated
call: 3
3
The copy of A is no longer accessible so it can be deallocated
call: 4
4
The copy of A is no longer accessible so it can be deallocated
call: 5
5
The copy of A is no longer accessible so it can be deallocated


2017-03-03 12:47 GMT+01:00 Joh-Tob Schäg <johtob...@gmail.com>:

> Is the garbage collection in picolisp immediate if the resource can be
> released?
>
> No, picolisp uses a mark and sweep halt the world garage collector. During
> sweep phase the complete allocated RAM is checked. If that would happen
> after each release of a resource picolisp would be very slow.
> Furthermore in Picolisp it is not possible to decide whether a resource
> can be released or not with out doing mark and sweep. This is because of
> cyclic list and the fact that you could always have a symbol pointing to
> that cell.
>
>
>
> 2017-03-03 12:04 GMT+01:00 Lindsay John Lawrence <
> lawrence.lindsayj...@gmail.com>:
>
>>
>> Is the garbage collection in picolisp immediate if the resource can be
>> released?
>>
>> The initial iterative replacement solution I came up with (below) quickly
>> runs out of resources as it has to build the entire list before starting to
>> draw.
>>
>> I haven't figured out how to do it yet, but I think, in this case, a
>> 'recursive' solution that renders as points are created would use a lot
>> less resources, assuming that processed replacement rules are garbage
>> collected as the stack unwinds and elements are traversed over.
>>
>> It would be a nice accomplishment to be able to render the more complex
>> fractal plants expressed here:  https://en.wikipedia.org/wiki/L-system
>>
>> /Lindsay
>>
>>
>> # https://en.wikipedia.org/wiki/Gosper_curve
>> # Angle 60 degrees = PI/3
>> # Axiom A
>> # Replacement Rules
>> #   A :--> A - B - - B + A + + A A + B -
>> #   B :--> + A - B B - - B - A + + A + B
>>
>> # C (initially = A) grows...very quickly.
>> #: n=0 (length C) -> 15
>> #: n=1 (length (setq C (F C))) -> 113
>> #: n=2 -> 799, n=3 -> 5601, n=4 -> 39215, n=5 -> 274513, n=6 -> 1921599,
>> n=7 .
>>
>> # For n=6...
>> : (bench (nil (Draw-Gosper-Curve)))
>> -> 1.370 sec
>>
>> Which works out to:
>>
>> XY Cnt: 823543 coordinates to plot
>> Min-XY: -66,432.00 -42,345.11
>> Max-XY: 2,048.00 23,611.35"
>>
>> ...about 900K of serialized canvas instructions.
>>
>>
>> Full-code at: https://github.com/thinknlive/picolisp-gosper
>>
>> (de Gosper-Curve (Length Angle N)
>>    (let
>>       (A (chop "A-B--B+A++AA+B-")
>>          B (chop "+A-BB--B-A++A+B")
>>          C A
>>          F '((L) (fish atom
>>               (mapcar '((X)
>>                 (cond
>>                   ((= X "A") A)
>>                   ((= X "B") B)
>>                   (T X))) L))) )
>>
>>
>>       # Generate points
>>       (do N (setq C (F C)))
>>
>>       # Plot points
>>       (map '((R)
>>          (case (car R)
>>             (("A" "B") (Plot-Line Length Angle))
>>             ("+" (setq Angle (+ Angle PI/3)))
>>             ("-" (setq Angle (- Angle PI/3)))
>>             (T (msg (text "?Gosper-Curve: No-match: @1" @))) )) C )
>>
>>    ) )
>>
>>
>>
>

Reply via email to