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