Please send questions to
st10@humboldt.edu .
; DON'T TRY TO RUN THIS TEXT VERSION!
; ...it has a . where the little car image should be! 8-)
; CIS 130 - Week 3, Monday, 02-01-10
; you can give a name of your choice a value
; using the define operation
; syntax:
; (define name-of-your-choice expression)
; semantics:
; this odd expression does not have a type!
; ...it has a SIDE-EFFECT instead, it makes that
; name have the value of that expression as its value
(define fave-color "red")
; result of this?
; fave-color is now a simple expression,
; whose value is "red"
; whose type is string
; that can be used anywhere a string expression can be used
(create-solid-fabric fave-color 300 200)
; a name you choose in a program is called an IDENTIFIER
; in Scheme, here are the syntax rules for an identifier:
; * must start with a letter
; * cannot contain blanks
; * first letter may be followed by 0 or more
; letters,
; digits,
; or several other "permitted" characters such as _ - ?
; * avoid using the characters " ' , ` # ; | \
; * also avoid using [ ] or { }
; let's talk STYLE --
; when you choose identifiers, they should be
; descriptive, meaningful, and not misleading;
; that's a STYLE "rule" or guideline, not syntax;
; once defined, you can use that new name for the rest
; of that set of definitions...
(define PI 3.14159)
PI
(add-vertical-stripe fave-color 7 chili)
(add-vertical-stripe fave-color PI worm)
(define fave-box (create-solid-fabric fave-color 20 20))
fave-box
(define WIDGET-MAX 13)
(+ WIDGET-MAX 15)
(define my-car .)
my-car
(add-print my-car chili)
; we want to work our way up to defining
; our OWN operations, which we'll call
; functions
(define red-swatch (create-solid-fabric "red" 300 150))
red-swatch
(add-horiz-stripe "black" 10 red-swatch)
(add-print chili red-swatch)
(add-horiz-stripe "green" 10 (create-solid-fabric "blue" 100 100))
(add-horiz-stripe "red" 10 (create-solid-fabric "purple" 100 100))
; what if I decide -- I'm going to be doing this a lot,
; I WISH I had an operation -- a function -- that I could
; just give two colors to, and get a 100x100 pixel horizontally
; striped box image of those colors?
; here is the syntax for defining a FUNCTION
; a PARAMETER is a name for a value that a function will expect
; when it is used
; (define (new-function-name parameter-name-1 parameter-name-2 ...)
; expression)
; semantics:
; define a new operation -- a new function -- named new-function-name,
; that expects the same number of expressions as parameters given,
; whose value is the value of the expression (called the function's
; body)
(define (make-striped-box color1 color2)
; IN the body of the function -- the expression in the function --
; USE the parameters to represent the eventual values the user
; will provide
(add-horiz-stripe color1 10 (create-solid-fabric color2 100 100))
)
(make-striped-box "green" "blue")
(make-striped-box "red" "purple")
(make-striped-box "orange" "magenta")
(add-print chili (make-striped-box "black" "teal"))