You will find the procedure and its inputs in a call, then work out a nested calculation. You will also distinguish a call from a definition.
No programming experience is needed. Try each runnable example in the Playground, which shows its result.
Read a call
(+ 2 3)Result
5The first item, +, names the procedure to call. A procedure performs an
operation on the values you pass to it. Here those values, called arguments,
are 2 and 3.
An ordinary call has this shape.
(operation input1 input2 ...)Lispex evaluates the first item to get a procedure. It then evaluates the input expressions from left to right and calls the procedure with their values.
Read a nested call
(+ 10 (* 2 3))Result
16Lispex looks up +, evaluates 10, and then evaluates (* 2 3).
The multiplication returns 6. The outer call then adds 10 and 6.
The parentheses group the inputs of each call. Here they put the
multiplication inside the addition, so its result becomes an argument to +.
Read a definition
The procedure below adds trim width and the total bleed across both edges. Both inputs use the same unit.
(define (width-with-bleed trim-width bleed)
(+ trim-width bleed))This defines width-with-bleed and prints nothing. The procedure takes two
arguments, named trim-width and bleed. Its body, (+ trim-width bleed), runs when you
call the procedure.
define is a special form. A special form has its own rules for which
parts to evaluate. Here (width-with-bleed trim-width bleed) declares the procedure
and its input names. It is not a call.
Other special forms include if, quote, and lambda. Each uses parentheses,
but you must follow that form's rules to know what runs.
Try this
Predict the value before running the expression.
(+ 1 (* 2 (+ 3 4)))Show answer
The result is 15. First, (+ 3 4) returns 7. Then (* 2 7) returns
14. Finally, (+ 1 14) returns 15.
In the definition above, identify the procedure name, its two input names, and the call in its body.
Show answer
The procedure name is width-with-bleed. Its input names are trim-width and bleed.
The body calls + with the values of those two names when the procedure runs.
Continue to First Program to run a complete program.