LOGO Procedures


Here is some Logo code related to recursion and program design.
to dothing :x
 if lessp :x 1 [stop]
 forward :x right 90 forward :x right ~
 90 forward :x right 90 forward :x ~
 right 90 forward :x/2 right 45
 dothing :x/1.414
end

to fastfib :n
 output first fiblist :n
end

to fiblist :n
 ; Procedure to output a reversed list of Fibonacci numbers (back to n).
 if lessp :n 2 [output [1 1]]
 output newfib fiblist :n-1     ; Adds Fibonacci number n to the first of the list.
end

to newfib :list
 ; Procedure to add a Fibonacci number to the first position of a list of Fibonacci numbers.
 output sentence (sum item 1 :list item 2 :list) :list
end

to square :side
 repeat [forward :side right 90]
end

to tree :size
 if lessp :size 1 [stop]        ; Stop when branches are too small to see
 trunk :size                    ; Trunk
 forward :size
 right 30 tree :size/1.8        ; Right branch
 left 60 tree :size/1.8         ; Left branch
 right 30 back :size
end

to trunk :size
 forward :size
 back :size
end