; CS 111 - Week 2 Lecture 1
; last modified: 2016-08-30

; more examples of compound expressions

(string-append "m" "oo")
(string? 3)
(string? "3")

; hey, it turns out you have to put CHARACTERS
;    inside of double-quotes for string simple
;    expressions...
; uncomment the following to see that you cannot
;    put an image inside of double quotes and get
;    a string:

;"."

; remember, case *matters* in Racket:

(string=? "moo" "Moo")

; and, thus, #True is not a simple expression --
;    uncomment the following to see this:

;(boolean? #True)

;... but #true is:

(boolean? #true)

; and BSL Racket, in DrRacket 6.6, allows several
;    aliases for the boolean value #true:

(boolean? true)
(boolean? #t)

; string-length expects a single string argument,
;    and returns the number of characters in that
;    string

(string-length "moo")
(string-length "")

; string->number expects a single string argument,
;    and returns a number version of that argument
;    if it can, and returns #false otherwise

(string->number "34.5")
(string->number "three")
(string->number "(+ 3 5)")

; and number->string expects a single number
;    argument, and returns a string version of
;    that argument
; (but sometimes the resulting string can be
;    a bit surprising!)

(number->string 42.3)

; BSL Racket has the usual collection of
;    relational operations
; > <  >=  <= =
; *   note that = expects arguments of type number!
; *   these return a boolean result

; BSL Racket has fairly typical boolean operations:
; and or not
; *   not
;     ...expects ONE argument, type boolean,
;     and returns #true if that argument's value is
;     #false, and vice versa
;     (logical negation)
; *   and
;     ...expects two or more boolean arguments,
;     and returns #true ONLY if ALL of them have the
;     value #true (and returns #false otherwise)
; *   or
;     ...expects two or more boolean arguments,
;     and returns #true if ANY of them has the
;     value #true (and only returns #false
;     if all of the arguments have the value #false)

"and test follows"
(and #true #t true (string=? "mabel" "Mabel"))

""
(not (= 3 5))

; BSL Racket in DrRacket environment makes a
;   number of teachpacks and modules
;   available --
; use the require operation with the name
;   of the teachpack as its argument
;   and returns nothing,
;   but has the SIDE EFFECT of allowing you
;   to then use things defined by that
;   teachpack

; 2htdp/image contains image-related functions
; 2htdp/universe contains functions that will allow
;    us to create animations and more

(require 2htdp/image)
(require 2htdp/universe)

; the circle function expects a radius in pixels,
;    "outline" or "solid", and a color,
;    and returns a circle image with those
;    specifications

(circle 65 "outline" "blue")
(circle 0.5 "solid" "black")

; the rectangle function expects a
;    width and a height in pixels,
;    "outline" or "solid", and a color,
;    and returns a rectangle image with those
;    specifications

(rectangle 100 50 "solid" "dark green")

; notice how you need to know how many and what type of
;    argument expressions a function expects, to be
;    able to write a compound expression using that
;    function with correct syntax?
; and you need to know the type the function returns
;    if you want to use that function in a compound
;    expression that's the argument to ANOTHER function?

; here's a notation we will use for that:
; a function SIGNATURE:
;
; function-name: type type ... type -> type
;                ^ type of each argument expression expected
;                                      ^ type function returns

; ...note, we use Racket *type* names only in function signatures;

; circle: number string color -> image

; SO, a function signature essentially gives the info you
;    need to call a function with the correct syntax;

; BUT -- a signature doesn't give you the info about what
;    the arguments *mean* -- about the meaning,
;    the semantics, of the function;

; rectangle: number number string color -> image

; ...what are the two number arguments meant to be, here?

; a PURPOSE STATEMENT *describes* what a function expects,
;    and *describes* what it returns;

; rectangle: number number string color -> image
; purpose: expects a width and height in pixels,
;    "outline" or "solid", and a color, and returns
;    a rectangle image with those specifications

; see how a signature and purpose, together, let you
;    know how to use a function?

; function: regular-polygon: number number string
;                            color -> image
; purpose: expects the length of each side of a polygon,
;    the number of sides, either "outline" or "solid",
;    and the desired color, and returns an image
;    of a polygon with those specifications

"what follows should be a solid purple"
"   pentagon with sides 15 pixels long:"

(regular-polygon 15 5 "solid" "purple")

; next time: giving names to values