1 Getting started
Install from a local checkout with raco pkg install –link .. This first example makes a plan for the young Galileo question: does a pendulum’s period change as its swing gets smaller? It describes work to do; it does not measure a pendulum.
Examples with different spellings have Compact and Verbose tabs. Your choice is remembered across the manual. Compact and verbose syntax explains the two spellings.
1.1 Your first investigation
Save this as investigation.rkt and run racket investigation.rkt:
#lang sciencelogo |
|
workflow "Does the period change as the swing gets smaller?" |
do timing-plan as plan |
print plan |
|
to timing-plan [ |
output "Time ten swings as the swing gets smaller." |
] |
to defines a reusable procedure. do calls it, output returns its text, and as plan names that result. The caller prints the plan. Definitions may appear after calls. This program prints a sentence; it neither times swings nor records evidence.
1.2 Calculate a period
This second program shows how a procedure receives values and returns a number. The example numbers illustrate the calculation; they are not recorded timings:
#lang sciencelogo |
|
workflow "Calculate one example period" |
do calculate-period 20 10 as seconds-per-swing |
print seconds-per-swing |
|
to calculate-period :elapsed :swings [ |
output :elapsed / :swings |
] |
:elapsed and :swings are inputs local to calculate-period. output returns their quotient; as seconds-per-swing names it for the caller. A real investigation would identify the observations, units, and conditions behind its values. Read Values and expressions and Procedures and control flow for the exact rules. Then Stages and state shows how a written method declares what enters and leaves a stage. Its paired stage form is checked by the reader but is not executed. Data sources and storage shows how the method names data outside the workflow and records where values would be read or written. The language does not perform those transfers.