;=====
; Racket examples from CS 111 - Week 1 Lecture 2,
;    cleaned up after class!
; last modified: 2024-08-29

; this is a comment (anything from a semicolon to the end of the line)
; *   comments are IGNORED by the computer!
; *   they are there for HUMANS to read

;=====
; data type: number
;     can have digits smushed together,
;     optionally with a single . decimal point
;     optionally starting with a + or -

; these are all simple expressions of type number

27     ; I am also a comment
2
123456789.0111
+27
-27

; in BSL Racket, you can separate expressions using blanks
;     as well as newlines
; below: eight simple expressions of data type number

1 2 3 4 5 -7 5555 .45

; this attempted simple expression below does NOT follow
;     the syntax ruls for a number;
; UNCOMMENT the line below (REMOVE the ;) and click run
;     to see the error message you get!

; 1.2.3

;=====
; data type: string
; anything written in double quotes is considered
;    a simple expression literal of type string

; three simple expressions of data type string

"moo"
"Hello how are you ?"
"oh
    does
   this
work?"

;=====
; data type: boolean
; for BSL Racket: the two most-basic literal simple expressions
;                 of type boolean
;                 are #true and #false
; BUT!!!! it also accepts true and #t for #true (considers true and #t to
;             also have the value #true)
;         it also accepts false and #f for #false (consider false and #f to
;             also have the value #false

; so - these are six simple expressions all of data type boolean

#true
#false
#t
#f
true
false

;=====
; data type: image
; you can paste in a copied .jpg or .png or .tiff or .svg
;   image into DrRacket and that is considered a simple
;   expression of type image

;=====
; I searched for "dachshund small image" in a browser,
;    right-clicked on and copied the desired image in the
;        browser results,
;    then clicked on DrRacket's Interactions window,
;    and used control/command v to paste in the image!
;    (Edit menu -> Paste works, also)

dachshund image

; NOTE: pasting in an image changes the Racket format "under the hood"
;    in the .rkt file so that the image can be represented --
; in DrRacket it looks fine,
;    but if you open the .rkt file in something OTHER than DrRacket,
;    the format looks decidedly strange!

;=====
; compound expressions
;
; because we want to DO things! simple expressions alone are not
;     enough!
;
; in BSL Racket, here is THE syntax for compound expressions:
;
; (operation expression expression expression ...)
;            ^ these expressions are called arguments
;
;            operation is followed by at least one blank/newline,
;            argument expressions are separated by at least one
;                blank/newline
;
; semantics: what is the value of a compound expression?
;    the value returned by its operation when it is executed
;    using those argument expressions
;
; NOTE: the data type of a compound expression is the data type
;    of the value its operation returns
; NOTE: it depends on the individual operation
;    how many and
;    what data types of argument expressions it expects,
;    and what order they must be in

;=====
; * is a supported operator for multiplication
;
; operator * expects two or more arguments of type number
;     and returns the product of it number arguments

(* 3  8
   5)

; THIS IS BAD STYLE

(*       3

    8
5
     )

; common arithmetic operators that Racket supports!
;     each expects two more more argument expressions of type number,
;     returns a value of type number that is the result of applying
;     that operation to those argument expressions (in the order they
;     appear)
;
; * multiply
; / divide
; + add
; - subtraction

(* 3 5)
(/ 3 5)
(+ 3 5)
(- 3 5)

; BY THE WAY -- we said a compound expression expects one or more
;     expressions after its operation;
; ...those can be simple expressions OR compound expressions!

(+ 6 7
   (* 3 2.2)
   (- 7 8))

;=====
; some operations have names -- functions!
; and some operations return a value with a data type
;     other than number!

; for example!
;=====
; string-append expects two or more string arguments
;   and returns ONE string of those all smushed together

(string-append "m" "ooooo" "!" " ha! ")

;=====
; operators
; < > =
;    expect two or more number arguments,
;    return a boolean whose value is whether the number arguments
;    meet that relationship

(< 3 5)
(> 3 5)
(= 3 5)

(< (+ 3 5)
   (* 3 5))

; NOTE -- = operator ONLY works with argument expressions of type number!
; *   but there ARE some operations to compare expressions of other types;
; *   FOR EXAMPLE:
;     string=? can be used to compare string expresssions, and returns
;     whether its string argument expressions have the same value

(string=? "moo"
          (string-append "m" "oo"))

;=====
; and IF you add this module using the special require operation:

(require 2htdp/image)

; NOW you can use operations from this Racket module!
; NOW I have image operations!

; for example:
; the circle function expects a desired radius in pixels,
;     the desired style expressed as a string: "solid" or "outline:,
;     and a color (one option is to write a known color name as a string),
; and it returns an image depicting a circle image with that radius,
;     style, and color!

(circle 30 "solid" "cyan")

; uncomment to see the error you get if you try to call it with
;    a "bad" color argument expression:

;(circle 30 "solid" "moo")

; for example:
; the above function expects one or more images
;    and returns a single image that is a vertical "stack"
;    of the image argument expressions

(above (circle 30 "solid" "cyan")
       (rectangle 100 30 "outline" "purple"))

;=====
; You can read about more of the operations/functions in
;     the module 2htdp/image in the DrRacket documentation --
; *   go to the DrRacket Help menu,
; *   select "Racket Documentation" near the top,
; *   enter in 2htdp/image in the ...search manuals... textfield
;     in the top-left corner
; ...and select the link to the 2htdp/image module's documentation
;    that results --
; ...scroll through the index on the left-hand-side, it has links to
;    descriptions of the many functions in the 2htdp/image module!