From: Jim Date: Sun, 1 Feb 2015 02:13:50 +0000 (-0500) Subject: update week1 notes X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=400b008fadb498ed7e308fd30cb30d5a287936cb update week1 notes --- diff --git a/week1.mdwn b/week1.mdwn index f6595bae..7a8b00aa 100644 --- a/week1.mdwn +++ b/week1.mdwn @@ -16,7 +16,7 @@ Here's another set of functions: ==, <, >, <=, >=, != -`==` is just what we non-programmers normally express by `=`. It's a relation that holds or not between two values. Here we'll treat it as a function that takes two values as arguments and returns a *boolean* value, that is a truth-value, as a result. The reason for using the doubled`=` symbol is that the single `=` symbol tends to get used in lots of different roles in programming, so we reserve `==` to express this meaning. I will deliberately try to minimize the uses of single `=` in this made-up language (but not eliminate it entirely), to reduce ambiguity and confusion. The `==` relation, or as we're treating it here, the `==` function that returns a boolean value, can at least take two numbers as arguments. Probably it makes sense for it to take other kinds of values as arguments, too. For example, it should operate on two truth-values as well. Maybe we'd want it to operate on a number and a truth-value, too? and always return false in that case? What about operating on two functions? Here we encounter the difficulty that the computer can't in general *decide* when two functions are equivalent. Let's not try to sort this all out just yet. We'll suppose that `==` can at least take two numbers as arguments, or two truth-values. +`==` is just what we non-programmers normally express by `=`. It's a relation that holds or not between two values. Here we'll treat it as a function that takes two values as arguments and returns a *boolean* value, that is a truth-value, as a result. The reason for using the doubled `=` symbol is that the single `=` symbol tends to get used in lots of different roles in programming, so we reserve `==` to express this meaning. I will deliberately try to minimize the uses of single `=` in this made-up language (but not eliminate it entirely), to reduce ambiguity and confusion. The `==` relation---or as we're treating it here, the `==` *function* that returns a boolean value---can at least take two numbers as arguments. Probably it makes sense for it to take other kinds of values as arguments, too. For example, it should operate on two truth-values as well. Maybe we'd want it to operate on a number and a truth-value, too? and always return false in that case? What about operating on two functions? Here we encounter the difficulty that the computer can't in general *decide* when two functions are equivalent. Let's not try to sort this all out just yet. We'll suppose that `==` can at least take two numbers as arguments, or two truth-values. As mentioned in class, we represent the truth-values like this: @@ -52,7 +52,7 @@ or perhaps like this: lessthan? x y -We'll get more acquainted with the difference and relation between these next week. For now, I'll just stick to the first form. +We'll get more acquainted with the difference between these next week. For now, I'll just stick to the first form. Another set of operations we have are: @@ -79,7 +79,7 @@ I've started throwing in some variables. We'll say variables are any expression x? xs -We'll follow a *convention* of using variables with short names and a final `s` to represent collections like sequences (to be discussed below). But this is just a convention to help us remember what we're up to, not a strict rule of the language. We'll also follow a convention of only using variables ending in `?` to represent functions that return a boolean value. Thus, for example, `zero?` is a function that expects a single number argument and returns a boolean corresponding to whether that number is `0`. `odd?` is a function tha expects a single number argument and returns a boolean corresponding to whether than number is odd. Above, I suggested we might use `lessthan?` to represent a function that expects *two* number arguments, and again returns a boolean result. +We'll follow a *convention* of using variables with short names and a final `s` to represent collections like sequences (to be discussed below). But this is just a convention to help us remember what we're up to, not a strict rule of the language. We'll also follow a convention of only using variables ending in `?` to represent functions that return a boolean value. Thus, for example, `zero?` will be a function that expects a single number argument and returns a boolean corresponding to whether that number is `0`. `odd?` will be a function that expects a single number argument and returns a boolean corresponding to whether than number is odd. Above, I suggested we might use `lessthan?` to represent a function that expects *two* number arguments, and again returns a boolean result. We also conventionally reserve variables ending in `!` for a different special class of functions, that we will explain later in the course. @@ -87,13 +87,13 @@ In fact you can think of `succ` and `pred` and `not` and all the rest as also be Only a few things in our language aren't variables. These include the **keywords** like `let` and `case` and so on that we'll discuss below. You can't use `let` as a variable, else the syntax of our language would become too hard to mechanically parse. (And probably too hard for our meager brains to parse, too.) -The rules for symbolic atoms are that a single quote `'` followed by any single word that could be a legal variable is a symbolic atom. Thus `'false` is a symbolic atom, but so too are `'x` and `'succ`. For the time being, I'll restrict myself to only talking about the symbolic atoms `'true` and `'false`. These are a special subgroup of symbolic atoms that we call the *booleans* or *truth-values*. Nothing deep hangs on these being a subclass of a larger category in this way; it just seems elegant. Other languages sometimes make booleans their own special type, not a subclass of any other limited type. Others make them a subclass of the numbers (yuck). We will think of them this way. +The rule for symbolic atoms is that a single quote `'` followed by any single word that could be a legal variable is a symbolic atom. Thus `'false` is a symbolic atom, but so too are `'x` and `'succ`. For the time being, I'll restrict myself to only talking about the symbolic atoms `'true` and `'false`. These are a special subgroup of symbolic atoms that we call the *booleans* or *truth-values*. Nothing deep hangs on these being a subclass of a larger category in this way; it just seems elegant. Other languages sometimes make booleans their own special type, not a subclass of any other limited type. Others make them a subclass of the numbers (yuck). We will think of them this way. Note that in symbolic atoms there is no closing `'`, just a `'` at the beginning. That's enough to make the whole word, up to the next space (or whatever) count as naming a symbolic atom. We call these things symbolic *atoms* because they aren't collections. Thus numbers are also atoms, just not symbolic ones. And functions are also atoms, but again, not symbolic ones. -Functions are another class of values we'll have in our language. They aren't "literal" values, though. Numbers and symbolic atoms are simple expressions in the language that evaluate to themselves. Functions aren't expressions in the language; they have to be generated from the evaluation of more complex expressions. +Functions are another class of values we'll have in our language. They aren't "literal" values, though. Numbers and symbolic atoms are simple expressions in the language that evaluate to themselves. That's what we mean by calling them "literals." Functions aren't expressions in the language at all; they have to be generated from the evaluation of more complex expressions. (By the way, I really am serious about thinking of *the numbers themselves* as being expressions in this language; rather than some "numerals" that aren't themselves numbers. We can talk about this down the road. For now, don't worry about it too much.)