about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/part3.html
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/part3.html
parent5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff)
downloadtour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz
*
Diffstat (limited to 'js/games/nluqo.github.io/~bh/part3.html')
-rw-r--r--js/games/nluqo.github.io/~bh/part3.html93
1 files changed, 93 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/part3.html b/js/games/nluqo.github.io/~bh/part3.html
new file mode 100644
index 0000000..080d96e
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/part3.html
@@ -0,0 +1,93 @@
+<HTML>
+<HEAD>
+<TITLE>Simply Scheme part III introduction</TITLE>
+</HEAD>
+<BODY>
+<CITE>Simply Scheme</CITE> 2/e Copyright (C) 1999 MIT
+<H1>Functions as Data</H1>
+
+<TABLE><TR><TD>
+<P><IMG SRC="simply.jpg" ALT="cover photo">
+<TD valign="center">
+<CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
+Harvey</A><BR><A HREF="http://www.cnmat.berkeley.edu/~matt">Matthew
+Wright</A><BR>University of California, Berkeley</CITE>
+<BR><BR><A HREF="http://www-mitpress.mit.edu/book-home.tcl?isbn=0262082810">MIT
+Press web page for Simply Scheme</A>
+</TABLE>
+
+<P><A HREF="simply-toc.html">(back to Table of Contents)</A>
+
+<HR>
+
+<P>By now you're accustomed to the idea of expressing a computational process
+in terms of the function whose value you want to compute, rather than in
+terms of a sequence of actions.  But you probably think of a function (or
+the procedure that embodies it) as something very different from the words,
+sentences, numbers, or other data that serve as arguments to the functions.
+It's like the distinction between verbs and nouns in English:  A verb
+represents something <EM>to do,</EM> while a noun represents something
+<EM>that is.</EM>
+
+<P>In this part of the book our goal is to overturn that distinction.
+
+<P>Like many big ideas, this one seems simple at first.  All we're saying is
+that a function can have <EM>functions</EM> as its domain or range.  One
+artificially simple example that you've seen earlier was the
+<CODE>number-of-arguments</CODE> function in Chapter 2.  That function
+takes a function as argument and returns a number.  It's not so different
+from <CODE>count</CODE>, which takes a word or sentence as argument and returns a
+number.
+
+<P>But you'll see that this idea leads to an enormous rise in the length and
+complexity of the processes you can express in a short procedure, because
+now a process can give rise to several other processes.  A typical example
+is the <CODE>acronym</CODE> procedure that we introduced in Chapter 1 and
+will examine now in more detail.  Instead of applying the <CODE>first</CODE>
+procedure to a single word, we use <CODE>first</CODE> as an argument to a procedure,
+<CODE>every</CODE>, that automatically applies it to every word of a sentence.  A
+single <CODE>every</CODE> process gives rise to several <CODE>first</CODE> processes.
+
+<P>The same idea of function as data allows us to write procedures that create
+and return new procedures.  At the beginning of Part II we showed a Scheme
+representation of a function that computes the third person singular of a
+verb.  Now, to illustrate the idea of function as data, we'll show how to
+represent in Scheme a function <CODE>make-conjugator</CODE> whose range is <EM>the
+whole family</EM> of verb-conjugation functions:
+
+<PRE>
+(define (make-conjugator prefix ending)
+  (lambda (verb) (sentence prefix (word verb ending))))
+</PRE>
+
+<P>Never mind the notation for now; the idea to think about is that
+we can use <CODE>make-conjugator</CODE> to create many functions similar to the
+<CODE>third-person</CODE> example of the Part II introduction:
+
+<PRE>
+> (define third-person (make-conjugator 'she 's))
+
+> (third-person 'program)
+(SHE PROGRAMS)
+
+> (define third-person-plural-past (make-conjugator 'they 'ed))
+
+> (third-person-plural-past 'play)
+(THEY PLAYED)
+
+> (define second-person-future-perfect
+    (make-conjugator '(you will have) 'ed))
+
+> (second-person-future-perfect 'laugh)
+(YOU WILL HAVE LAUGHED)
+</PRE>
+
+<P>We'll explore only a tiny fraction of the area opened up by the idea of
+allowing a program as data.  Further down the same road is the study of
+<EM>compilers</EM> and <EM>interpreters,</EM> the programs that translate your
+programs into instructions that computers can carry out.  A Scheme
+compiler is essentially a function whose domain is Scheme programs.
+
+<P><A HREF="simply-toc.html">(back to Table of Contents)</A>
+</BODY>
+</HTML>