[{"id":"/sicpjs/1","tag":"TITLE","body":"1  \n    Building Abstractions with \n    \n      \n      Functions"},{"tag":"EPIGRAPH","child":[{"body":"\n    The acts of the mind, wherein it exerts its power over simple ideas,\n    are chiefly these three: 1. Combining several simple ideas into one\n    compound one, and thus all complex ideas are made.  2. The second is\n    bringing two ideas, whether simple or complex, together, and setting\n    them by one another so as to take a view of them at once, without\n    uniting them into one, by which it gets all its ideas of relations.\n    3.  The third is separating them from all other ideas that accompany\n    them in their real existence: this is called abstraction, and thus all\n    its general ideas are made.\n    ","tag":"#text"}],"author":" John Locke, ","title":"An Essay Concerning Human Understanding","date":" (1690)"},{"tag":"TEXT","id":"#p1","child":[{"body":"\n    We are about to study the idea of a\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"computational process","tag":"#text"}]},{"body":".\n    \n    Computational processes are abstract beings that inhabit computers.\n    As they evolve, processes manipulate other abstract things called\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"data","tag":"#text"}]},{"body":".\n    \n    The evolution of a process is directed by a pattern of rules\n    called a\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"program","tag":"#text"}]},{"body":".\n    People create programs to direct processes.\n    In effect, we conjure the spirits of the computer with our spells.\n  ","tag":"#text"}]},{"tag":"TEXT","id":"#p2","child":[{"body":"\n    A computational process is indeed much like a sorcerer's idea of a\n    spirit.  It cannot be seen or touched.  It is not composed of matter\n    at all.  However, it is very real.  It can perform intellectual work.\n    It can answer questions.  It can affect the world by disbursing money\n    at a bank or by controlling a robot arm in a factory.  The programs we\n    use to conjure processes are like a sorcerer's spells.  They are\n    carefully composed from symbolic expressions in arcane and esoteric\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"programming languages","tag":"#text"}]},{"body":"\n    that prescribe the tasks we want our\n    processes to perform.\n  ","tag":"#text"}]},{"tag":"TEXT","id":"#p3","child":[{"body":"\n    A computational process, in a correctly working computer, executes\n    programs precisely and accurately.  Thus, like the sorcerer's\n    apprentice, novice programmers must learn to understand and to\n    anticipate the consequences of their conjuring.  Even small errors\n    \n    (usually called ","tag":"#text"},{"tag":"EM","child":[{"body":"bugs","tag":"#text"}]},{"body":")\n      \n   \n    in programs can have complex and unanticipated consequences.\n  ","tag":"#text"}]},{"tag":"TEXT","id":"#p4","child":[{"body":"\n    Fortunately, learning to program is considerably less dangerous than\n    learning sorcery, because the spirits we deal with are conveniently\n    contained in a secure way.  Real-world programming, however,\n    requires care, expertise, and wisdom.  A small bug in a computer-aided\n    design program, for example, can lead to the catastrophic collapse of\n    an airplane or a dam or the self-destruction of an industrial robot.\n  ","tag":"#text"}]},{"tag":"TEXT","id":"#p5","child":[{"body":"\n    Master software engineers have the ability to organize programs so\n    that they can be reasonably sure that the resulting processes will\n    perform the tasks intended.  They can visualize the behavior of their\n    systems in advance.  They know how to structure programs so that\n    unanticipated problems do not lead to catastrophic consequences, and\n    when problems do arise, they can\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"debug","tag":"#text"}]},{"body":"\n    their programs.  Well-designed\n    computational systems, like well-designed automobiles or nuclear\n    reactors, are designed in a modular manner, so that the parts can be\n    constructed, replaced, and debugged separately.\n  ","tag":"#text"}]},{"tag":"SUBHEADING","id":"#h1","child":[{"body":"Programming in JavaScript","tag":"#text"}]},{"tag":"TEXT","id":"#p6","child":[{"body":"\n        We need an appropriate language for describing processes, and we will\n        use for this purpose the programming language JavaScript.  Just as our\n        everyday thoughts are usually expressed in our natural language (such\n        as English, Swedish, or Chinese), and descriptions of quantitative\n        phenomena are expressed with mathematical notations, our procedural\n        thoughts will be expressed in JavaScript. \n        \n        JavaScript was developed in 1995\n\tas a programming language for controlling the behavior \n        of World Wide Web browsers through scripts that are embedded\n\tin web pages.\n        The language was conceived by \n        \n        Brendan Eich, originally under the name ","tag":"#text"},{"tag":"EM","child":[{"body":"Mocha","tag":"#text"}]},{"body":", which\n        was later renamed to ","tag":"#text"},{"tag":"EM","child":[{"body":"LiveScript","tag":"#text"}]},{"body":", and finally to JavaScript.\n        \n        The name \"","tag":"#text"},{"body":"JavaScript","tag":"#text"},{"body":"\" is a trademark\n\tof Oracle Corporation.\n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p7","child":[{"body":"\n        Despite its inception as a language for scripting the web, JavaScript\n        \n        is a general-purpose programming language. A JavaScript\n\t","tag":"#text"},{"tag":"EM","child":[{"body":"interpreter","tag":"#text"}]},{"body":" is a machine that carries out processes described\n\tin the JavaScript language.\n        \n\tThe first JavaScript interpreter was implemented by Eich\n        at Netscape Communications Corporation for the Netscape Navigator web \n        browser.\n        \n\tJavaScript inherited its core features from the \n        \n        Scheme and Self programming languages. Scheme is a dialect of Lisp, and\n        \n        was used as the programming language for the original version of this\n\tbook. From Scheme, JavaScript inherited its most fundamental design\n\tprinciples,\n        such as lexically scoped first-class \n        functions and dynamic typing.\n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p8","child":[{"body":"\n\tJavaScript bears only superficial resemblance to the language Java, \n\tafter which it was\n\t(eventually) named; both Java and JavaScript use the block structure of\n\tthe language C. In contrast with Java and C, which usually\n\temploy compilation to lower-level\n\tlanguages, JavaScript programs were initially\n\t","tag":"#text"},{"tag":"EM","child":[{"body":"interpreted","tag":"#text"}]},{"body":"\n\tby web browsers.\n\t\n\tAfter Netscape Navigator, other web browsers provided interpreters\n\tfor the language, including Microsoft's Internet Explorer, whose\n\tJavaScript version is called\n\t","tag":"#text"},{"tag":"EM","child":[{"body":"JScript","tag":"#text"}]},{"body":". The popularity of JavaScript for controlling web\n\tbrowsers gave rise to a standardization effort, culminating in \n\t","tag":"#text"},{"tag":"EM","child":[{"body":"ECMAScript","tag":"#text"}]},{"body":". The\n\t\n\tfirst edition of the ECMAScript standard was led by Guy Lewis \n\tSteele Jr. and completed in June 1997\n\t(ECMA 1997).\n\tThe sixth edition, known as ECMAScript 2015, was led by \n\tAllen Wirfs-Brock and adopted by the General Assembly of ECMA in\n\tJune 2015 (ECMA 2015). \n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p9","child":[{"body":"\n\tThe practice of embedding JavaScript programs in web pages encouraged\n\tthe developers of web browsers to implement JavaScript interpreters.\n\tAs these programs became more complex,\n\tthe interpreters became more efficient in executing them, eventually\n\tusing sophisticated implementation techniques such as Just-In-Time\n\t(JIT) compilation.\n\tThe majority of JavaScript programs as of this writing (2021) are embedded\n\tin web pages and interpreted by browsers, but JavaScript is increasingly\n\tused as a general-purpose programming language, using systems such as\n\tNode.js.\n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p10","child":[{"body":"\n\t  However, it is the ability of\n\t  \n\t  browsers to execute JavaScript\n\t  programs that makes it an ideal language for an online version\n\t  of a book on computer programs. Executing programs by clicking on\n\t  things on a web page comes naturally in JavaScript—after\n\t  all that is what JavaScript was designed for! More fundamentally,\n\t\n\tECMAScript 2015 possesses a set of features that make it an excellent\n\tmedium for studying important programming constructs and data\n\tstructures and for relating them to the linguistic features that\n\tsupport them. Its\n\tlexically scoped first-class functions and their syntactic support\n\tthrough lambda expressions provide direct and concise access to\n\tfunctional abstraction, and\n\tdynamic typing allows the adaptation to remain close to the\n\tScheme original throughout the book. Above and beyond these\n\tconsiderations, programming in JavaScript is great fun.\n      ","tag":"#text"}]}]