Breaking Down Compound Procedures in Lisp

With a sprinkle of JavaScript

(define (square x) (* x x))
(define (square  x)        (*         x     x))
To square something, multiply it by itself.
function square(x) {
return x * x;
}
(define (sum-of-squares x y)
(+ (square x) (square y)))
function sumOfSquares(x, y) {
return square(x) + square(y);
}
(define (f a)
(sum-of-squares (+ a 1) (* a 2)))
// Feed in the number 5:
(sum-of-squares (+ 5 1) (* 5 2))
// Before squaring:
(sum-of-squares (6) (10))
// After squaring:
(sum-of-squares (36) (100))
// After running the sum-of-squares procedure and "summing" them:
136
function f(a) {
return square(a + 1) + square(a * 2);
}

Coding, creativity, music, and books. Pianist & composer — @vontmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store