123 ; a simple expression of type ; number "moo" ; a simple expression of type ; string true ; a simple expression of type ; boolean ; in Scheme, we can combine simple ; expressions INTO compound ; expressions -- and in Scheme, ; these have THIS syntax: ; (operation expression expression ; expression ...) ; NOTE that a compound expression's ; expressions CAN be either simple ; or compound; ; NOTE that the expressions for an ; operation within a compound ; expression are often called ; arguments ; NOTE that each operation is written ; to expect some number of ; expressions/arguments of ; particular types ; + knows how to add any number ; of number expressions! (+ 3 5 7 9 11) ; UNCOMMENT the following to see ; that + cannot handle strings! ; (+ "moo" "cow") ; UNCOMMENT the following to see ; that + cannot handle booleans! ; (+ true false) ; putting the operation FIRST ; is also called PREFIX notation ; SO: in Math, if you had: 17 - 4 ; in Scheme, that would be: (- 17 4) ; what about 5 times 6? ; aha, in Scheme you multiply with ; the * operation! (* 5 6) ; what about 24 divided by 4? ; aha, in Scheme you divide with ; the / operation (/ 24 4) ; and, there are boolean logic ; operators, too: ; and - for boolean and (and true true) (and true false) (and false true) (and false false) ; or - for boolean or (or true true) (or true false) (or false true) (or false false) ; not - for boolean not (not true) (not false) ; there are string operations, also ; string-append expects string ; expressions ; and returns a string of all of ; those strings smushed together (string-append "how " "are " "you?") ; string-length expects a string ; and returns how many characters ; are in that string (string-length (string-append "how " "are " "you?")) (and (or true true) (and true false)) (and (or true false) (and (or false true) true) ) ; I can decide to define a name ; to represent a value! ; A name the programmer chooses ; is called an IDENTIFIER; ; this has syntax, too; ; it cannot follow the syntax ; for any other simple expression ; type, and it can't contain ; certain special characters; ; ; (if you start it with a letter ; and follow that with 0 or more ; letters, digits, _, -, ? then ; you WILL be fine) ; I can define a NAMED CONSTANT ; with THIS syntax: ; ; (define desired-name expression) ; ; this returns no value, BUT ; has the SIDE-EFFECT of making ; desired-name a simple expression ; whose value is that expression ; ; (this is ONLY the case from here ; until the END of this file) (define P true) P (define Q false) Q (and P Q)