robby
2017-2-18 17:49:27

@robby has joined the channel


robby
2017-2-18 17:49:28

@robby set the channel purpose: producing a pearl


dan
2017-2-18 17:49:28

@dan has joined the channel


florence
2017-2-18 17:49:28

@florence has joined the channel


robby
2017-2-18 17:49:53

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


robby
2017-2-18 17:49:58

But I think we need to get a copy.


robby
2017-2-18 17:50:04

It seems to be partly in google books:



robby
2017-2-18 17:50:22

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


robby
2017-2-18 17:50:37

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


robby
2017-2-18 17:50:51

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


robby
2017-2-18 20:30:39

these things are so pretty


robby
2017-2-18 20:31:08

robby
2017-2-18 22:14:32

robby
2017-2-19 00:31:03

got the book fromteh wayback machine! :0


robby
2017-2-19 00:31:04

:slightly_smiling_face:


shu--hung
2017-2-19 00:32:34

@shu—hung has joined the channel


robby
2017-2-19 00:33:59

concrete syntax is the worst


robby
2017-2-19 00:34:10

anyway, here’s the book.



robby
2017-2-19 00:34:42

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.


robby
2017-2-19 00:35:16

I was thinking of something like this:


robby
2017-2-19 00:35:18
#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)))

robby
2017-2-19 00:35:46

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


robby
2017-2-19 00:36:09

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


robby
2017-2-19 00:36:19

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


robby
2017-2-19 00:36:28

The book has things like this:


robby
2017-2-19 00:36:40
n=20
A
A->AB
B->A

robby
2017-2-19 00:36:44

as the spec of the system.


robby
2017-2-19 00:37:05

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


robby
2017-2-19 00:37:08

Ah well.


robby
2017-2-19 00:37:11

keep thinking


dan
2017-2-19 01:30:16

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


robby
2017-2-19 01:30:47

The axiom is always a string of things in lsystems


robby
2017-2-19 01:30:56

It doesn’t compute.


robby
2017-2-19 01:31:04

(Is that what you are asking?)


robby
2017-2-19 01:32:32

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.


robby
2017-2-19 01:32:41

I need to fully embrace that.


dan
2017-2-19 01:33:25

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


dan
2017-2-19 01:33:57

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


robby
2017-2-19 01:36:07

Yes



robby
2017-2-19 01:38:17

the axiom there is FA


robby
2017-2-19 01:38:22

FX, rather.



robby
2017-2-19 01:39:01

The axiom there is F-G-G


robby
2017-2-19 01:41:43

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


robby
2017-2-19 01:55:55

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


robby
2017-2-19 01:55:58
#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)))

robby
2017-2-19 01:56:15

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


robby
2017-2-19 01:56:27

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


robby
2017-2-19 01:57:06

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


robby
2017-2-19 01:57:37

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.


robby
2017-2-19 01:57:44

It must also exprt start and finish


robby
2017-2-19 01:57:59

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


robby
2017-2-19 01:58:13

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


robby
2017-2-19 01:58:19

I’ll see how that turns out.


florence
2017-2-19 01:59:19

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


robby
2017-2-19 01:59:26

Yeah, that was wrong.


robby
2017-2-19 01:59:32

Here is a closer attempt:


robby
2017-2-19 02:00:19

oh, crap.


robby
2017-2-19 02:00:41

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


robby
2017-2-19 02:00:45
#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)))

robby
2017-2-19 02:01:00

Oh, nevermind. I know what to do.


robby
2017-2-19 02:01:01

one sec


robby
2017-2-19 02:01:43

Probably still errors, but this is closer:


robby
2017-2-19 02:01:45
#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)))

robby
2017-2-19 02:02:01

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


robby
2017-2-19 02:02:18

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


robby
2017-2-19 02:02:32

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


robby
2017-2-19 02:03:01
#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)))

robby
2017-2-19 02:03:47

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).


robby
2017-2-19 02:04:35

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


robby
2017-2-19 02:05:15

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


robby
2017-2-19 02:05:33

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


robby
2017-2-19 02:05:40

not sure why lazy would be useful, tho.


robby
2017-2-19 02:05:59

does that make more sense?


florence
2017-2-19 02:07:20

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?


robby
2017-2-19 02:07:36

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


robby
2017-2-19 02:07:49

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


robby
2017-2-19 02:08:04

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


robby
2017-2-19 02:08:15

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


florence
2017-2-19 02:08:32

Oooooh. Cool!


robby
2017-2-19 02:08:37

:slightly_smiling_face:


robby
2017-2-19 02:09:01

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


robby
2017-2-19 02:09:07

since that seems to be a standard thing


robby
2017-2-19 02:09:44

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


robby
2017-2-19 02:09:47
#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)))

robby
2017-2-19 02:10:28

we’ll definitely need a syntax colorer.


robby
2017-2-19 02:10:50

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


florence
2017-2-19 02:11:00

(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)


robby
2017-2-19 02:11:18

which file is the the file in that comment?


robby
2017-2-19 02:11:45

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


robby
2017-2-19 02:12:29

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


florence
2017-2-19 02:13:53

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.


florence
2017-2-19 02:14:10

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


robby
2017-2-19 02:14:52

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


florence
2017-2-19 02:15:03

yeah!


robby
2017-2-19 02:15:11

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


robby
2017-2-19 02:15:31

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


robby
2017-2-19 02:15:48

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


robby
2017-2-19 02:16:02

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


robby
2017-2-19 02:16:17

So if this were the file:


robby
2017-2-19 02:16:19
#lang lindenmayer racket

## axiom ##
A

## rules ##
A -> AB
B -> A

## variables ##
n=20

robby
2017-2-19 02:16:22

then you’d get this output:


robby
2017-2-19 02:17:15

ABAABABAABAABABAABABA


robby
2017-2-19 02:17:20

(well, with n=6)


robby
2017-2-19 02:17:49

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


robby
2017-2-19 02:17:58

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


florence
2017-2-19 02:19:51

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!


robby
2017-2-19 02:30:05

yes :slightly_smiling_face: it is too long.


robby
2017-2-19 02:30:08

Here’s 15:


robby
2017-2-19 02:30:10

ABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABABAABAABABAABAABABAABABAABAABABAABAAB


shu--hung
2017-2-19 03:35:54

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


dan
2017-2-19 03:37:13

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


shu--hung
2017-2-19 03:38:05

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


dan
2017-2-19 03:41:20

robby
2017-2-19 03:41:43

yep, pushed them earlier today


robby
2017-2-19 03:41:50

they are documented now!


robby
2017-2-19 03:41:57

(before they didn’t exist)


robby
2017-2-19 03:42:27

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


robby
2017-2-19 03:42:32

Or just make at the top-level


robby
2017-2-19 03:43:55

well, I’m fading fast.


robby
2017-2-19 03:44:35

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.


shu--hung
2017-2-19 03:46:12

oh, cool


robby
2017-2-19 03:57:53

okay, that works now.


robby
2017-2-19 03:58:01

I’ve pushed the parser and whatnot.


robby
2017-2-19 03:58:44

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.


robby
2017-2-19 03:59:00

I think that all the examples run, tho.


shu--hung
2017-2-19 04:04:34

night!


robby
2017-2-19 04:04:59

(okay, now all the examples run…)


robby
2017-2-19 04:05:10

‘night!