diff options
author | elioat <elioat@tilde.institute> | 2023-08-23 07:52:19 -0400 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2023-08-23 07:52:19 -0400 |
commit | 562a9a52d599d9a05f871404050968a5fd282640 (patch) | |
tree | 7d3305c1252c043bfe246ccc7deff0056aa6b5ab /js/games/nluqo.github.io/~bh/ssch8/part3.html | |
parent | 5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff) | |
download | tour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz |
*
Diffstat (limited to 'js/games/nluqo.github.io/~bh/ssch8/part3.html')
-rw-r--r-- | js/games/nluqo.github.io/~bh/ssch8/part3.html | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/ssch8/part3.html b/js/games/nluqo.github.io/~bh/ssch8/part3.html new file mode 100644 index 0000000..859a67b --- /dev/null +++ b/js/games/nluqo.github.io/~bh/ssch8/part3.html @@ -0,0 +1,108 @@ +<P> + +<P> +<HTML> +<HEAD> +<TITLE>Simply Scheme: Introducing Computer Science, Part 8: Functions as Data</TITLE> +</HEAD> +<BODY> +<CITE>Simply Scheme:</CITE> +<CITE>Introducing Computer Science</CITE> 2/e Copyright (C) 1999 MIT +<H2>Part III</H2> +<H1>Functions as Data</H1> + +<TABLE width="100%"><TR><TD> +<IMG SRC="../simply.jpg" ALT="cover photo"> +<TD><TABLE> +<TR><TD align="right"><CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian +Harvey</A><BR>University of California, Berkeley</CITE> +<TR><TD align="right"><CITE><A HREF="http://ccrma.stanford.edu/~matt">Matthew +Wright</A><BR>University of California, Santa Barbara</CITE> +<TR><TD align="right"><BR> +<TR><TD align="right"><A HREF="../pdf/ssch08.pdf">Download PDF version</A> +<TR><TD align="right"><A HREF="../ss-toc2.html">Back to Table of Contents</A> +<TR><TD align="right"><A HREF="../ssch7/variables.html"><STRONG>BACK</STRONG></A> +chapter thread <A HREF="higher.html"><STRONG>NEXT</STRONG></A> +<TR><TD align="right"><A HREF="http://mitpress.mit.edu/0262082810">MIT +Press web page for <CITE>Simply Scheme</CITE></A> +</TABLE></TABLE> + +<HR><BIG> + +<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: + +<P><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: + +<P><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> +</BIG> +<HR> +<P><A HREF="../ss-toc2.html">(back to Table of Contents)</A><P> +<A HREF="../ssch7/variables.html"><STRONG>BACK</STRONG></A> +chapter thread <A HREF="higher.html"><STRONG>NEXT</STRONG></A> + +<P> +<ADDRESS> +<A HREF="../index.html">Brian Harvey</A>, +<CODE>bh@cs.berkeley.edu</CODE> +</ADDRESS> +</BODY> +</HTML> |