about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/ssch3/part2
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
committerelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
commit562a9a52d599d9a05f871404050968a5fd282640 (patch)
tree7d3305c1252c043bfe246ccc7deff0056aa6b5ab /js/games/nluqo.github.io/~bh/ssch3/part2
parent5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff)
downloadtour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz
*
Diffstat (limited to 'js/games/nluqo.github.io/~bh/ssch3/part2')
-rw-r--r--js/games/nluqo.github.io/~bh/ssch3/part257
1 files changed, 57 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/ssch3/part2 b/js/games/nluqo.github.io/~bh/ssch3/part2
new file mode 100644
index 0000000..6a78f0e
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/ssch3/part2
@@ -0,0 +1,57 @@
+\input bkmacs
+
+\part{Composition of Functions}
+\justidx{composition of functions}
+\justidx{function composition}
+
+The big idea in this part of the book is deceptively simple.  It's that we
+can take the value returned by one function and use it as an argument to
+another function.  By ``hooking up'' two functions in this way, we invent a
+new, third function.  For example, let's say we have a function that adds
+the letter {\tt s} to the end of a word:
+
+\smallskip
+\centerline{{\it add-s\/}(``{\tt run}'') = ``{\tt runs}''}
+\smallskip
+
+\noindent and another function that puts two words together into a sentence:
+
+\smallskip
+\centerline{{\it sentence\/}(``{\tt day}'', ``{\tt tripper}'') = ``{\tt
+day tripper}''}
+\smallskip
+
+\noindent We can combine these to create a new function that represents the
+third person singular form of a verb:
+
+\smallskip
+\centerline{{\it third-person\/}(verb) = {\it sentence\/}(``{\tt
+she}'', {\it add-s\/}(verb))}
+\smallskip
+
+\noindent That general formula looks like this when applied to a particular
+verb:
+
+\smallskip
+\centerline{{\it third-person\/}(``{\tt sing}'') = ``{\tt she sings}''}
+\smallskip
+
+\noindent The way we say it in Scheme is
+
+{\prgex%
+(define (third-person verb)
+  (sentence 'she (add-s verb)))
+}
+
+\noindent (When we give an example like this at the beginning of a part,
+don't worry about the fact that you don't recognize the notation.  The
+example is meant as a preview of what you'll learn in the coming chapters.)
+\vfill\eject
+
+We know that this idea probably doesn't look like much of a big deal to
+you.  It seems obvious.  Nevertheless, it will turn out that we can express
+a wide variety of computational algorithms by linking functions together in
+this way.  This linking is what we mean by
+``\bkidx{functional}{programming}.''
+
+\bye