### LOGO Procedures

Here is some Logo code you might find helpful when working with Chapter 5.

to factorial :posint
local "result ; Create a local (not global) variable
make "result 1 ; Store a starting value for n! in the variable
for [i 1 :n] ~ ; Variable i will take on values 1, 2, 3, ..., n
[make "result product :result :i] ; This multiplies :result by :i and stores the new value
output :result ; Why use "output" and not "print"?
end
to initials :name ; An example copied from page 78 of Computer Science Logo Style.
local "result
make "result []
for [i 1 [count :name]] ~
[make "result sentence :result first (item :i :name)]
output :result
end
to addup ; An example using the "for" command.
make "total 0
for [i 1 100]~
[make "total sum :total :i]
print sentence [The total is] :total
end
make "coordslist [[0 0] [-100 0] [-50 50] [0 0] [25 25] [50 0] [0 0]]
to connect.the.dots :pointlist ; An example of using the for command with graphics.
; May be useful for the linear algebra project.
pu
setpos item 1 :pointlist ; Move to the first point on the list.
pd
for [i 1 [count :pointlist]] ~
[setpos item :i :pointlist] ; Moves the turtle to the i'th point.
end
to reflectxy :point ; A sample support procedure for the linear algebra midterm project.
output (list last :point first :point)
end
to reflect :point ; A sample support procedure for the linear algebra midterm project.
output list (product -1 (first :point)) last :point
end
to dilate :point ; A sample support procedure for the linear algebra midterm project.
output sentence (product 2 first :point) (product 2 last :point)
end