[Thread Prev] [Thread Next]
On Thu, 19 Jun 2008 20:30:02 -0500, Julio C. Dominguez
<juliodominguezm@xxxxxxxxx> wrote:
> to go
>
> make "queue [] make "h 90
>
> /// makes a variable named "queue" which assigns its value back to 0
The value of queue is an "empty list" it is not 0. For example:
make "queue []
show list? :queue
true
show empty? :queue
true
show number? :queue
false
show 0 = :queue
false
>
> Cc
>
> ///Clears the command console, but why?
it is not necessary.
> carefully[newturtle "head][]
>
> ///creates a new turtle if not yet added to the stage, if it has been added
> it will create no error that's why it has the blank brackets
>
> carefully [turtlesown "posh][]
>
> /// creates a individual variable for each turtle, but why didn't head get
> assigned this variable as well?
it does.
turtlesown allows for *every turtle* to have the variable "posh".
> Also i didn't know posh was position and
> heading at the same time... why isn't in microworlds vocabulary?
"posh" is just the name of a variable that each turtle is going to have. It
could be any other name and the content is decided by the programmer.
>
> Follow
>
> /// launches a new procedure
not true. "follow" is not launched.
"follow" is invoked, "follow" is called. Just like in this example:
to roof
...
end
to base
...
end
to house
roof
base
end
notice that "roof" IS NOT launched.
> forever[path]
>
> /// same as above, except it's forever*
>
> forever[direct]
>
> /// *
>
> end
>
>
> to make.queue
>
> dolist[i get "page1 "turtles]
>
> /// creates a list and is assigned to a temporally variable "i" gets all the
> turtles that are on page one
not quite.
The "get" command receives two inputs and reports a list.
"dolist" uses that list and it iterates through the elements of that list. "i"
is assigned each of the elements of the list in turn, with each iteration.
> [tto :i
>
> /// talks to all the turtles on the stage
yeah, one by one, with each interation.
> make "queue lput list pos heading :queue]
>
> /// creates a separate variable that is going to be used later in the final
> output, "lput" puts the first x,y cord of the first turtle at the end of the
> list??
The variable "queue" was already created earlier, remember? It was created
with an empty list.
"lput" puts a list consisting of:
* the position of the current turtle and* the heading of the current turtle
at the end of the "queue" list.
"queue" then will be a list of pairs: position-heading, position-heading...
> Then creates a list? With position and heading? :queue??? What is
> the final :queue for?
that line is interepreted like this:
make "queue (lput (list pos heading) :queue)
> op bl :queue
>
> /// outputs the list, excluding the last item? Of queue?
outputs a list consisting of all the elements of queue except the last one.
> end
>
>
> to follow
>
> make "queue make.queue
>
> /// this is going to redefine the value of "queue" once the procedure is
> completed to create a new value, in this case a list
yes.
> dolist[i bf get "page1 "turtles]
>
> /// recreates the list to be used to set the position of each individual
> turtle and runs for ever as below
>
> [forever
>
> [tto :i
>
> setposh item bf :i :queue
>
> /// sets the position of each item or turtle in this case excluding the
> first which in microworlds would be head, :i??? :queue????
>
> seth last posh setpos first posh
>
> /// ??????????????????????????????????????????????
>
> ]
>
> ]
>
> end
Looking at this code as a whole:
to followmake "queue make.queue
dolist[i bf get "page1 "turtles]
[forever
[tto :i
setposh item bf :i :queue
seth last posh setpos first posh
]
]end
it means:
* queue will have the positions and headings of all the turtles except for the
last turtle.
* for each of the turtles (except for the first one) launch a process that
does the following:
** talk to the turtle
** set its "posh" personal variable to the correponding pair in the queue
** set the heading of the turtle to the heading element in the posh pair
** set the position of the turtle to the position element in the posh pair
so, after running "follow" you will have one process running for each of the
turtles, except for the first one. Each process will continually set the
heading and position of the turtles according to what the queue says at the
moment.
>
> to path
>
> head,
>
> seth :h fd 15 wait 1
>
> make "queue fput list pos heading bl :queue
>
> end
This is where the queue changes. An element enters the queue and another
element leaves the queue.
the head turtle will move
and the queue will now consist of
* all but the last element in the queue
* and, as it's new first element it will contain the pair position-heading of
the "head" turtle.
This line:
make "queue fput list pos heading bl :queue
is interpreted like this:
make "queue (fput (list pos heading) (bl :queue))
Daniel
OpenWorld Learning
Previous by thread:
explain
Next by thread:
MIA, Ask an Expert: eating dots and ghosts
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|