Learning Objectives

Video Lessons

Reference

Testing for Understanding

  1. TFU #1
  2. TFU #2
  3. TFU #3
  4. TFU #4
  5. TFU #5

Related Links

Logo How-Tos

Logo in your browser

Logo Software

Logo Organizations

Logo Forums

The work on this shelf is powered by you and

MicroWorlds Web Player is officially supported under Internet Explorer or Netscape 4 or higher

Writing Reporters

From Procedures With Output in MicroWorlds EX Help:

In MicroWorlds, primitives are either commands or reporters. Most of the procedures in the previous sections have been commands. You can also define procedures that are reporters. To do this, you must use the output command.

The utility of defining reporters is immediately obvious when dealing with numbers. For example, define a procedure which squares its inputs using show.

to square :x
show :x * :x
end

Trying this out shows you the result:

square 5
25

But there is nothing more that you can do with it. You cannot use it as a building block in defining more complex procedures. For instance, you may want to compute the sum of the square of two numbers. To do this, you need to be able to communicate the result to another procedure. Square can be revised by replacing show with output:

to square :x
output :x * :x
end

Now square is a reporter:

square 5
I don't know what to do with 25

MicroWorlds complains because there is no command at the beginning of the line, so it doesn't know what to do with its output.

Try this instead:

show square 5
25

Square can be used as the input to sum to compute the sum of two squared numbers:

show sum square 5 square 3
34

Here is another arithmetic reporter that you can define, the average of two numbers:

to average :x :y
output (:x + :y) / 2
end

show average 20 50
35

Now you could combine the reporters by computing the square of the average:

show square average 20 50
1225

The procedures for words and lists which are reporters are ultimately more useful, and, in many cases, can function as tools. Tools are procedures that have many different purposes. A simple tool procedure doubles a word, linking it to itself:

to double :wd
output word :wd :wd
end

show double "oops
oopsoops

About the Center for Talent Development

Center for Talent Development (CTD), housed at Northwestern University's School of Education and Social Policy, is an accredited learning center and research facility that identifies, educates and supports gifted students and their families and serves as a leader in gifted education. Learn more about the Center for Talent Development.

Leone Learning Systems, Inc. (LLS) is a North Shore company that provides online courses for kids anywhere and local teaching and tutoring services for students in Chicago and the Northern Suburbs of Chicagoland. LLS also provides a free geometry software package for children age 6 and up, and free resources for teachers and parents. This site includes information about classes taught, availability for tutoring, learning activities for kids, lesson plans, and ongoing software and curriculum research and development efforts.