#lang racket
(require gigls/unsafe)

;;; File:
;;;   io-lab.rkt
;;; Authors:
;;;   Samuel A. Rebelsky
;;;   YOUR NAME HERE
;;; Summary:
;;;   A variety of procedures for playing with input and output and issues
;;;   of side effects.

; +----------------+--------------------------------------------------
; | Textual Output |
; +----------------+

;;; Procedure:
;;;   greet
;;; Parameters:
;;;   name, a symbol or strong
;;; Purpose:
;;;   Prints a friendly message.
;;; Produces:
;;;   [Nothing; called for the side effect.]
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   Some text has been printed.
(define greet
  (lambda (name)
    (display "Hello, ")
    (display name)
    (display ".  ")
    (display "It's nice to meet you.")
    (newline)))

; +-------------------------------+-----------------------------------
; | Exploring Order of Operations |
; +-------------------------------+

;;; Procedure:
;;;   yield
;;; Parameters:
;;;   val, a value
;;; Purpose:
;;;   Display a short message about val
;;; Produces:
;;;   val, the same value
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   A short message is displayed
(define yield
  (lambda (val)
    (display "  yields ")
    (display val)
    (newline)
    val))

(define add
  (lambda (x y)
    (display "add ") (display x) (display " and ") (display y) (newline)
    (yield (+ x y))))

(define subtract
  (lambda (x y)
    (display "subtract ") (display y) (display " from ") (display x) (newline)
    (yield (- x y))))

(define multiply
  (lambda (x y)
    (display "multiply ") (display x) (display " and ") (display y) (newline)
    (yield (* x y))))

(define divide
  (lambda (x y)
    (display "divide ") (display x) (display " by ") (display y) (newline)
    (yield (/ x y))))

(define negate
  (lambda (x)
    (display "negate ") (display x) (newline)
    (yield (- x))))

; +-----------------------------------------+-------------------------
; | Observing the transformations of colors |
; +-----------------------------------------+

;;; Procedure:
;;;   irgb-yield
;;; Parameters:
;;;   color, an irgb color
;;; Purpose:
;;;   Display a short message about color
;;; Produces:
;;;   color, the same color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   A short message is displayed
(define irgb-yield
  (lambda (color)
    (display " yields ")
    (display (irgb->string color))
    (newline)
    color))

(define irgb-redder_*
  (lambda (color)
    (display "Making ")
    (display (irgb->string color))
    (display " redder")
    (irgb-yield (irgb-redder color))))

(define irgb-lighter_*
  (lambda (color)
    (display "Making ")
    (display (irgb->string color))
    (display " lighter")
    (irgb-yield (irgb-lighter color))))

(define irgb_*
  (lambda (red green blue)
    (display "(irgb ")
    (display red)
    (display " ")
    (display green)
    (display " ")
    (display blue)
    (display ")")
    (irgb-yield (irgb red green blue))))

(define irgb-red_*
  (lambda (color)
    (display "(irgb-red ")
    (display (irgb->string color))
    (display ")")
    (yield (irgb-red color))))

(define irgb-green_*
  (lambda (color)
    (display "(irgb-green ")
    (display (irgb->string color))
    (display ")")
    (yield (irgb-green color))))

(define irgb-blue_*
  (lambda (color)
    (display "(irgb-blue ")
    (display (irgb->string color))
    (display ")")
    (yield (irgb-blue color))))

