
@robby has joined the channel

@robby set the channel purpose: producing a pearl

@dan has joined the channel

@florence has joined the channel

@dan I couldn’t find the book “the algorithmic beauty of plants” because of dns issues.

But I think we need to get a copy.

It seems to be partly in google books:


And I think that starting there and searching forward for citations is the way to go.

Look for papers that cite thatone and that have a lot of citations themselves. skim them and see what they do.

those are the first steps to figuring out some paper/book/idea’s influence

these things are so pretty



got the book fromteh wayback machine! :0

:slightly_smiling_face:

@shu—hung has joined the channel

concrete syntax is the worst

anyway, here’s the book.


I think I need to ponder the examples given there a little bit more before I implement the parser. I’m not sure I’m exactly capturing the right way to embed them into a PL.

I was thinking of something like this:

#lang lindenmayer racket
#:axiom
A
#:rules
A -> AB
B -> A
#:convert-start (cons 0 0)
#:convert-finish finish
#:iterations 20
------------------------------------------------------------
(define (finish pr) (* 1. (if (zero? (cdr pr)) +inf.0 (/ (car pr) (cdr pr)))))
(define (A pr) (cons (+ (car pr) 1) (cdr pr)))
(define (B pr) (cons (car pr) (+ (cdr pr) 1)))

where the symbols in the rules are names of functions that follow the hyphens.

And those functions tell you how to build something (in this case, an approximation to the golden ratio).

But the convert-start and convert-finish are ugly.

The book has things like this:

n=20
A
A->AB
B->A

as the spec of the system.

But I’ve not got my head around how that would work quite yet.

Ah well.

keep thinking

@robby: what if the axiom has to refer to a binding below the hyphens and that takes the place of the convert-start?

The axiom is always a string of things in lsystems

It doesn’t compute.

(Is that what you are asking?)

My main thought after playing around with various things in my brain is that all my trouble is coming from the way I imagine the langauage as a mixin.

I need to fully embrace that.

Is the axiom just a string of nonterminals or nonterminals+terminals?

So it could be “A A A” rather than just “A” in the example ?

Yes


the axiom there is FA

FX
, rather.


The axiom there is F-G-G

Page 35 has some context sensitive l-systems with longer axioms https://web.archive.org/web/20160304022519/http://algorithmicbotany.org/papers/abop/abop.pdf

Here’s my current thinking on what the langauge is going to look like:

#lang lindenmayer racket
## axiom ##
X
## rules ##
X -> F-[[X]+X]+F[+FX]-X
F -> FF
## variables ##
n=6
------------------------------------------------------------
(provide (all-defined-out))
(require graphics/value-turtles)
(define θ 22.5)
(define (X turtles) turtles)
(define (F turtles) (cons (draw 3 (car turtles)) (cdr turtles)))
(define (- turtles) (cons (turn (- θ) (car turtles)) (cdr turtles)))
(define (+ turtles) (cons (turn θ (car turtles)) (cdr turtles)))
(define (\|[\| turtles) (list* (car turtles) (turtle-state (car turtles)) (cdr turtles)))
(define (\|]\| turtles) (cons (restore-turtle-state (car turtles) (cadr turtles))
(cddr turtles)))
(define w 400)
(define h 500)
(define start (cons (move (/ h -2) (turn 90 (move (/ w 10) (turtles w h)))) '()))
(define (finish turtles) (clean (car turtles)))

The first part is a series of sections (the ##
lines).

Those sections are always (in some order), axiom, rules, and variables.

The line of hyphens (which should have been =
signs, sorry) separates the lindenmayer system from the support that extracts a value from the system.

The support at the end is expected to be a program in the racket
language (because of the first line of the file) that exports F
and X
and [
etc.

It must also exprt start
and finish

start
will get a table with all of the variables in it.

So we can have mutltiple lindenmayer systems with the same support in the same file.

I’ll see how that turns out.

@robby what does “start will get a table” mean? Start seems to be a pair in your example

Yeah, that was wrong.

Here is a closer attempt:

oh, crap.

Here is what I had intended, but it doesn’t work:

#lang lindenmayer racket
## axiom ##
X
## rules ##
X -> F-[[X]+X]+F[+FX]-X
F -> FF
## variables ##
n=6
θ=22.5
============================================================
(provide (all-defined-out))
(require graphics/value-turtles)
(define (X turtles) turtles)
(define (F turtles) (cons (draw 3 (car turtles)) (cdr turtles)))
(define (- turtles) (cons (turn (- (θ)) (car turtles)) (cdr turtles)))
(define (+ turtles) (cons (turn (θ) (car turtles)) (cdr turtles)))
(define (\|[\| turtles) (list* (car turtles) (turtle-state (car turtles)) (cdr turtles)))
(define (\|]\| turtles) (cons (restore-turtle-state (car turtles) (cadr turtles))
(cddr turtles)))
(define w 400)
(define h 500)
(define (start variables)
(cons (move (/ h -2) (turn 90 (move (/ w 10) (turtles w h)))) '()))
(define (finish turtles) (clean (car turtles)))

Oh, nevermind. I know what to do.

one sec

Probably still errors, but this is closer:

#lang lindenmayer racket
## axiom ##
X
## rules ##
X -> F-[[X]+X]+F[+FX]-X
F -> FF
## variables ##
n=6
θ=22.5
============================================================
(provide (all-defined-out))
(require graphics/value-turtles)
(define (X turtles variables) turtles)
(define (F turtles variables) (cons (draw 3 (car turtles)) (cdr turtles)))
(define (- turtles variables) (cons (turn (- (hash-ref variables 'θ)) (car turtles)) (cdr turtles)))
(define (+ turtles variables) (cons (turn (hash-ref variables 'θ) (car turtles)) (cdr turtles)))
(define (\|[\| turtles variables) (list* (car turtles) (turtle-state (car turtles)) (cdr turtles)))
(define (\|]\| turtles variables)
(cons (restore-turtle-state (car turtles) (cadr turtles))
(cddr turtles)))
(define w 400)
(define h 500)
(define (start variables)
(cons (move (/ h -2) (turn 90 (move (/ w 10) (turtles w h)))) '()))
(define (finish turtles) (clean (car turtles)))

the variables
section gets turned into a hash and passed to all of the functions.

The n
variable is special; it tells us how many iterations to run of this system.

Oh, and actually this is how we’d write taht one:

#lang lindenmayer racket
## axiom ##
X
## rules ##
X -> F-[[X]+X]+F[+FX]-X
F -> FF
## variables ##
n=6
θ=22.5
w=400
h=500
============================================================
(provide (all-defined-out))
(require graphics/value-turtles)
(define (X turtles variables) turtles)
(define (F turtles variables) (cons (draw 3 (car turtles)) (cdr turtles)))
(define (- turtles variables) (cons (turn (- (hash-ref variables 'θ)) (car turtles)) (cdr turtles)))
(define (+ turtles variables) (cons (turn (hash-ref variables 'θ) (car turtles)) (cdr turtles)))
(define (\|[\| turtles variables) (list* (car turtles) (turtle-state (car turtles)) (cdr turtles)))
(define (\|]\| turtles variables)
(cons (restore-turtle-state (car turtles) (cadr turtles))
(cddr turtles)))
(define (start variables)
(define w (hash-ref variables 'w))
(define h (hash-ref variables 'h))
(cons (move (/ h -2) (turn 90 (move (/ w 10) (turtles w h)))) '()))
(define (finish turtles) (clean (car turtles)))

So: start
gets only variables and produces a value. That value is threaded through all of the other functions based on the state of the lindenmayer system after n
iterations (6 here).

With this set up, I think that I can do all of the examples on page 25 of the pdf https://web.archive.org/web/20160304022519/http://algorithmicbotany.org/papers/abop/abop.pdf in a single file

That code at the bottom can be written in any language that support’s racket’s hash tables and functions.

which, I guess, means either lazy, TR, or R.

not sure why lazy would be useful, tho.

does that make more sense?

When you say “do all the examples in a single file”, how do you specify multiple variations of the variables? Or would you edit the file?

You have multiple of the sections at the top, separated by ---------

the last separator is =======
to separate it from the support code.

So you’d have N of the axiom, rules, and variables sections.

And you’d get N thingies printed out in the REPL. (Turtles windows in this case)

Oooooh. Cool!

:slightly_smiling_face:

And, indeed, the stuff after the ======
in this case would probably be just (require lindenmayer/turtles)

since that seems to be a standard thing

Here’s how the one that computes the golden ratio would looke:

#lang lindenmayer racket
## axiom ##
A
## rules ##
A -> AB
B -> A
## variables ##
n=20
------------------------------------------------------------
(provide (all-defined-out))
(define (start variables) (cons 0 0))
(define (finish pr variables) (* 1. (if (zero? (cdr pr)) +inf.0 (/ (car pr) (cdr pr)))))
(define (A pr variables) (cons (+ (car pr) 1) (cdr pr)))
(define (B pr variables) (cons (car pr) (+ (cdr pr) 1)))

we’ll definitely need a syntax colorer.

But it seems important to actually get this running for now. and then perhaps time to move to trying to do some writing.

(I was thinking it might be nice to have the file provide a racket function to which you could provide values for all of those variables)

which file
is the the file
in that comment?

(is this a “great minds think alike” moment? Or would you change something?)

This is going to be a totally line-oriented syntax :slightly_smiling_face:

I was thinking that, if there were only one system per file, there could be a function run-the-system
to which you supplied all of the variables. So in the golden ratio the function would take one argument, n
.
That way you wouldn’t have to copy/paste the system to play with new variables.

(not a huge thing, just a thought floating through my brain)

Are you saying that the code above the line of hyphens would evaluate to a function that accepted the parameters?

yeah!

My goal was to make the code above the hyphen look like the book, roughly.

And then code below the line would be code dedicated to turning the l-system into something pleasing to look at.

So the code above the line is “in control” and running it runs the system.

I’m also thinking that if there never is a line of hyphens, then you just get the string out.

So if this were the file:

#lang lindenmayer racket
## axiom ##
A
## rules ##
A -> AB
B -> A
## variables ##
n=20

then you’d get this output:

ABAABABAABAABABAABABA

(well, with n=6)

That seems to be the way that these people conceptualize these things.

I’m not completely sure, of course, but just going by what I’m reading.

I was gonna say, I thought n=20 would be longer :stuck_out_tongue:
Also I agree, It seems like “looks like what’s in the book” is a good goal!

yes :slightly_smiling_face: it is too long.

Here’s 15:

ABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAAB

Is the turtle-state
and restore-turtle-state
function in some other library?

@shu—hung: I think they’re in graphics/value-turtles

hmm, which version? They appeared to be unbound and is not documented

Oh, looks like Robby just added them today https://github.com/racket/htdp/commit/a30c48dad607357eda02c682528f3237cd2041ca

yep, pushed them earlier today

they are documented now!

(before they didn’t exist)

you should get them if you do raco pkg update htdp-lib
I think

Or just make
at the top-level

well, I’m fading fast.

I’ve got the bare bones of the new syntax implemented but my reader isn’t constructing the right syntax objects and that’s causing me pain at the moment. I’ll try for a bit longer to get this sorted out.

oh, cool

okay, that works now.

I’ve pushed the parser and whatnot.

I didn’t do the "multiple l-systems in one file” part or the “if there is no ====
line then just print things out”, but I think I’m going to head to bed. ‘night all.

I think that all the examples run, tho.

night!

(okay, now all the examples run…)

‘night!