Friday, March 9

Journal; Logo procedures

To start with, please make sure that you hand in your crossword puzzle.  When you hand it in please make sure that you have your name on the top of the paper!

Next, I need you to submit your journal to me.  Here is the process you'll need to follow to do this:

  1. Open your blog and go to your journal page
  2. Copy your journal page URL (it should look like this - "http://yourblogaddress.blogspot.com/p/journal.html")
  3. Open up Gmail and send me an email with a the above link to my school email address.  Remember, you need to have a subject line, and you should also include your name at the end of your email.

In Logo, procedures are "mini-programs" (my term, not something that Logo uses) that you can create by defining a set of instructions for Logo to follow.  These procedures need to be defined using a word that is NOT a command that Logo already "knows".  The advantage to creating and using procedures is that once you define (or create) the procedure all you need to do is "call" (this is programming speak which means that you want Logo to run the "mini-program") the procedure to make it run.

For example, I could create a procedure to draw a square (I would probably call it "Square"), and then every time within the Logo instructions I wanted to have Logo draw a square I would just simply need to type in 'Square'.  Once defined, the procedure is available to use again as long as you save your file that you are working on (the extension for Logo files is .lg).  If you are going to save please make sure to do so in your account.

At this point you should see how we are progressing through learning how to program.  We started with simple instructions (forward, back, right, left), and now have moved to creating a procedure that we can use over and over to accomplish a Logo "task".

Just as with the REPEAT command, there is a specific way that you have to tell Logo that you are creating a procedure.  First, you enter the word "to" and then label the procedure with a name; next you provide the instructions to create the procedure; and finally you enter the word "end" so that Logo knows you are done.  In Logo it would look like this:

? to square
>repeat 4 [fd 100 rt 90]
>end

Once I have defined what I want a square to be, then all I need to do the next time I want Logo to draw a square is simply enter the word square.  Go ahead - try it!

No comments:

Post a Comment