CS 100 - Week 2 Lecture 1 - 8-28-12

Starting our coverage of Chapter 2 (with some computer-related
asides...)

critical thinking is often involved
with REASONS:
*   identifying reasons
*   evaluating reasons
*   giving reasons

*   IN critical thinking,
    passages that present REASONS for a
    claim are called ARGUMENTS
    *   in this chapter (2), we explore
        the concept of an argument,
        and how to distingush arguments
	from non-arguments

ASIDE: Intro to Boolean logic

*  first: smallest "chunk" in a natural
   language that has meaning is (arguably)
   a word;

   in a computer language, the smallest
   chunk that has meaning is (arguably)
   a SIMPLE EXPRESSION

*  we're going to play a bit with
   3 computer languages:
   Python, Racket (variant of Scheme),
   Prolog

*  in a natural language,
   you have grammar rules that tell
   how to build "proper" statements
   and sentences etc.
*  in a computer language, such
   grammar "rules" are called SYNTAX
   ...and if your computer language
   expression or statement doesn't
   follow the syntax for that language,
   it WON'T WORK. You'll get an error.

*  computer expressions are said to
   have a TYPE -- what TYPE of value
   they express

   numeric expressions!
   string expressions!
   boolean expressions!

*   in Prolog/Python/Racket,
    a simple expression of type number
    can have syntax such as:

    optionally start with a + or -
    1 or more digits
    optionally can contain a single period

*   string type:
    if you put something in DOUBLE
    QUOTES, in Python or Racket, or Prolog,
    that is considered to be a simple
    expression of type string

   78 <- number
   "78" <- string

*   what about type BOOLEAN?

    exactly TWO values:
    true  false   <- Racket
    True  False   <- Python

    "true" <- string
    true   <- in Racket, is a boolean!

    "under the hood", true is often
    represented as 1,
    and false is often represented as 0

*   the syntax so far has been for 
    expressions that happen to be
    simple expressions that are also
    LITERALS

    5 means the literal number 5
    true is the literal boolean truth
        value
    "Sharon" is the string literal of
        my first name

    ..that's different from a VARIABLE,
    a name I choose to HOLD or REPRESENT
    some value;
    ...like x in f(x) = 3+x
    ...x stands for a number to be
       named later...

    (a name YOU choose, like a variable,
    in a programming language is called
    an IDENTIFIER -- if you stick
    with names that start with a letter
    and are followed by letters, digits,
    and/or underscores, your identifiers
    will be following correct 
    Python/Racket syntax for identifiers)

*   compound expression in Racket:

    (operator expression expression ...)

(quick intro to boolean operators and, or, and not,
to be discussed further on Thursday...)

--------------------------------------------------
*   EXAMPLES from Python 3 interactions window:
--------------------------------------------------
Math-Tuttle-OSX:~ smtuttle$ python3
Python 3.2.2 (v3.2.2:137e45f15c0b, Sep  3 2011, 16:48:10) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3.5
3.5
>>> -14.678
-14.678
>>> 2.6.6.6
  File "<stdin>", line 1
    2.6.6.6
        ^
SyntaxError: invalid syntax
>>> "moo"
'moo'
>>> 9.
9.0
>>> True.
  File "<stdin>", line 1
    True.
        ^
SyntaxError: invalid syntax
>>> 

--------------------------------------------------
EXAMPLES from DrRacket interactions window:
--------------------------------------------------
> "moo"
"moo"
> 9.
9
> true.
true.: this variable is not defined
> (< 3 5)
true
> (and true true)
true
> (and (< 3 5) (> 3 5))
false
> (or (< 3 5) (> 3 5))
true
> (not true)
false
> (not false)
true
> (not (and (< 3 5) (> 3 5)))
true
> (and (or true false) (and (or false true) true))
true
>