[{"id":"/sicp/1.1.1","tag":"TITLE","body":"1.1.1  Expressions"},{"tag":"TEXT","id":"#p1","child":[{"body":"\n    One easy way to get started at programming is to examine some typical\n    interactions with an interpreter for the\n    Scheme dialect of Lisp.\n\tImagine that you are sitting at a\n\tcomputer terminal.\n      \n    You type \n    an ","tag":"#text"},{"tag":"EM","child":[{"body":"expression","tag":"#text"}]},{"body":",\n    and the interpreter responds by displaying the\n    result of its ","tag":"#text"},{"tag":"EM","child":[{"body":"evaluating","tag":"#text"}]},{"body":" that\n    expression.","tag":"#text"}]},{"tag":"TEXT","id":"#p2","child":[{"body":"\n        One kind of primitive expression you might type is a number.  \n      \n    (More precisely, the expression that you type consists of the numerals that\n    represent the number in base 10.)\n    \n      If you ask our script to evaluate the expression statement\n      ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":1,"eval":false},{"body":"\n      by clicking it, it will respond by displaying a JavaScript interpreter\n      with the option\n      to evaluate the statement by pressing a \"","tag":"#text"},{"body":"Run","tag":"#text"},{"body":"\" button.\n      Click on the primitive expression statement, and see what happens!\n    ","tag":"#text"}]},{"tag":"TEXT","id":"#p3","child":[{"body":"\n        Expressions representing numbers may be combined with an\n        \n        expression representing a\n        \n        primitive procedure (such as \n        ","tag":"#text"},{"tag":"SCHEMEINLINE","body":"+"},{"body":" or ","tag":"#text"},{"tag":"SCHEMEINLINE","body":"*"},{"body":") to\n\tform a compound expression that represents the application of the\n\tprocedure to those numbers.  For example,\n        ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":2,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqBBmA7CLgCwCcAlEA","body":"(+ 137 349) ","output":"486"},{"tag":"SNIPPET","latex":false,"id":3,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBaBAGfIAzIQCwCUQA","body":"(- 1000 334) ","output":"666"},{"tag":"SNIPPET","latex":false,"id":4,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUAqEBWEAnAQJRA","body":"(* 5 99) ","output":"495"},{"tag":"SNIPPET","latex":false,"id":5,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUB6BAGEArAJRA","body":"(/ 10 5) ","output":"2"},{"tag":"SNIPPET","latex":false,"id":6,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqEAmRA7AgAwCUQA","body":"(+ 2.7 10) ","output":"12.7"}]},{"tag":"TEXT","id":"#p4","child":[{"body":"\n        Expressions such as these, formed by \n        \n        delimiting a list of expressions\n        within parentheses in order to denote\n        \n        procedure application,\n        are called ","tag":"#text"},{"tag":"EM","child":[{"body":"combinations","tag":"#text"}]},{"body":".  The leftmost\n        element in the list is called the \n        ","tag":"#text"},{"tag":"EM","child":[{"body":"operator","tag":"#text"}]},{"body":", and the other\n        elements are called \n        ","tag":"#text"},{"tag":"EM","child":[{"body":"operands","tag":"#text"}]},{"body":".  The\n        \n        value of a combination is\n        obtained by applying the procedure specified by the operator to the\n        ","tag":"#text"},{"tag":"EM","child":[{"body":"arguments","tag":"#text"}]},{"body":" that are the values of the operands.\n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p5","child":[{"body":"\n        The convention of placing the operator to the left of the operands is\n        known as \n        ","tag":"#text"},{"tag":"EM","child":[{"body":"prefix notation","tag":"#text"}]},{"body":", and it may be somewhat confusing at\n        first because it departs significantly from the customary mathematical\n        convention.  Prefix notation has several advantages, however.  One of\n        them is that it can accommodate \n        \n        procedures that may take an arbitrary\n        number of arguments, as in the following examples:\n        ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":7,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqEAmeIAzAKwK4gDsAlEA","body":"(+ 21 35 12 7) ","output":"75"},{"tag":"SNIPPET","latex":false,"id":8,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUAqEAmArCACwK4CUQA","body":"(* 25 4 12) ","output":"1200"},{"body":"\n        No ambiguity can arise, because the operator is always the leftmost \n        element and the entire combination is delimited by the\n        parentheses.\n      ","tag":"#text"}]},{"tag":"TEXT","id":"#p6","child":[{"body":"\n        A second advantage of prefix notation is that it extends in a\n        straightforward way to allow combinations to be\n        ","tag":"#text"},{"tag":"EM","child":[{"body":"nested","tag":"#text"}]},{"body":", that is, to have combinations whose elements are\n\tthemselves combinations:\n        ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":9,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqEGBUIAzCAKwCUuAtAgAwgBsZZQA","body":"(+ (* 3 5) (- 10 6)) ","output":"19"}]},{"tag":"TEXT","id":"#p7","child":[{"body":"\n        There is no limit (in principle) to the depth of such nesting and to the\n\toverall complexity of the expressions that the Lisp interpreter can\n\tevaluate. It is we humans who get confused by still relatively simple\n\texpressions such as\n        ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":10,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqEGBUIAzLjviAEwgAsAlCUSAKw0v0YC0CADCAOx0A2FkA","body":"(+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) "},{"body":"\n        which the interpreter would readily evaluate to be 57.  We can help\n        ourselves by writing such an expression in the form\n        ","tag":"#text"},{"tag":"SNIPPET","latex":false,"id":11,"eval":true,"prependLength":0,"program":"chap=1&prgrm=NwAgygkgwgCiCMA6J8BQqAUBqEGBUIAzKiKWdrgQEwgAsAlCWc7joSAKz3dOu4C0CAAwgA7IxYgAbNyA","body":"(+ (* 3\n      (+ (* 2 4)\n         (+ 3 5)))\n   (+ (- 10 7)\n      6)) "},{"body":"\n        following a formatting convention known as  \n        ","tag":"#text"},{"tag":"EM","child":[{"body":"pretty-printing","tag":"#text"}]},{"body":", in which each long combination is written so\n\tthat the operands are aligned vertically.  The resulting\n\t\n\tindentations\n\tdisplay clearly the structure of the expression.","tag":"#text"},{"tag":"FOOTNOTE_REF","id":"#footnote-link-1","body":"1","href":"/sicp/1.1.1#footnote-1"}]},{"tag":"TEXT","id":"#p8","child":[{"body":"\n    Even with complex expressions, the interpreter always operates in the\n    same basic cycle: It reads\n    an expression from the terminal,\n    evaluates the\n    expression,\n    and prints the result. This mode of operation is often expressed by saying\n    that the interpreter runs in a\n    ","tag":"#text"},{"tag":"EM","child":[{"body":"read-eval-print loop","tag":"#text"}]},{"body":".\n      \n    Observe in particular that it is not necessary to explicitly instruct the\n    interpreter to print the value of the\n    \n\texpression.","tag":"#text"},{"tag":"FOOTNOTE_REF","id":"#footnote-link-2","body":"2","href":"/sicp/1.1.1#footnote-2"}]},{"tag":"DISPLAYFOOTNOTE","id":"#footnote-1","count":1,"href":"/sicp/1.1.1#footnote-link-1","child":[{"body":"Lisp systems\n\ttypically provide\n        \n        features to aid the user in formatting expressions.  Two especially\n        useful features are one that automatically indents to the proper\n        pretty-print position whenever a new line is started and one that\n        highlights the matching left parenthesis whenever a right parenthesis\n        is typed.","tag":"#text"}]},{"tag":"DISPLAYFOOTNOTE","id":"#footnote-2","count":2,"href":"/sicp/1.1.1#footnote-link-2","child":[{"body":"Lisp obeys the convention that every\n\t\n\texpression has a value. This convention, together with the old\n\treputation of Lisp as an inefficient language, is the source of the\n\tquip by Alan Perlis (paraphrasing Oscar Wilde)\n\tthat \"","tag":"#text"},{"body":"Lisp programmers know the value of\n\teverything but the cost of nothing.","tag":"#text"},{"body":"\"","tag":"#text"}]}]