;========
; Fall 2026 - CS 111
; Week 6 Lab Exercise - save as lab6.rkt
;
; date: 2026-10-02
;========

;-----
; this file will use definitions and functions from these modules:

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

;*************
; *** NOTE ***
; This lab has even MORE explanations than
;     usual! Look for
;*** DO THIS ***
;     ...right before the parts YOU are to add.

;========
; also NOTE:
; *   To receive credit for this lab exercise, you must:
;     *   be present during your lab section,
;         either in BSS 313 or in the lab Zoom session,
;         based on your lab section
;     *   participate appropriately in a pair,
;         either in BSS 313 or in a Zoom breakout room
;

;========
; USING pair-programming:
; 1. COPY and PASTE the contents of this
;    file into a DrRacket Definitions window, and save as:
;
;        lab6.rkt
;
; 2. ADD comments and expressions TO THIS as specified below
;    (one student saying what to type, the other student typing it
;    into DrRacket)
;
;        ********
;    *   DO NOT DELETE THE COMMENTS! They speed up grading!
;        ********
;
;        ********
;    *   DO NOT change or remove the string expressions
;        already included to act as labels!
;        ********
;
;    *   remember: it is a class style standard to put a
;        BLANK LINE between each comment-block and an expression
;        following it
;
; 3. SAVE the contents of your definitions window frequently
;    as you are working, to the driver's Google Drive,
;    using a file name of lab6.rkt.
;
; 4. RUN the resulting file frequently as you are working,
;    fixing any errors that arise.
;
; 5. When you are done, use Gmail to MAIL a copy of the
;    resulting filled-in lab6.rkt file
;
;    *** AS WELL AS YOUR PROGRAM-CREATED FILE practice.txt ***,
;
;    to BOTH of you.
;
; 6. And, EACH of you should SUBMIT these TWO files,
;
;    *** lab6.rkt AND practice.txt ***,
;
;    to Canvas BEFORE you leave lab.
;
; 7. REMEMBER to also answer the
;    "Week 6 Lab Exercise - Pair-Programming Peer Review Survey"
;    in Canvas, posted along with this lab exercise, by
;    11:59 pm TONIGHT (Friday, October 2)
;========

;*** DO THIS ***
;=====
; Leave a blank line, and then put COMMENT(s) containing BOTH
;     of your names (include first AND last names)





;========
; PROBLEM 1 - trying out some file input/output
;========
; this expression lets you use DrRacket's file input/output
;     functions, especially useful for
;     "batch"-style programs

(require 2htdp/batch-io)

;-----
; 1 part a
;-----
; REMINDER: you can say that you want a
;    newline character in a Racket string by
;    writing it as "\n"
;-----
; Consider the following signature and
;     purpose comment for function write-file,
;     from 2htdp/batch-io:
;========
; signature: write-file: string string -> string
; purpose: expects the name of a file
;     written as a string
;     AND the string to write to that file,
;
;     has the SIDE-EFFECT of trying to
;     write that string to that 
;     file (creating that file if necessary), 
;
;     and returns the name of the file

""
"should see the name of the file written:"
"----------------------------------------"

;*** DO THIS ***
;-----
; WRITE an expression, using write-file, whose
;     side-effects should be: 
;     *   to create a file named practice.txt
;
;     *   that contains AT LEAST FIVE lines
;         of contents of your choice,
;
;     *   making sure that AT LEAST TWO lines
;         contain MORE THAN ONE WORD each.





;-----
; 1 part b
;-----
; Consider the following signature and
;     purpose comment for function read-file,
;     from 2htdp/batch-io:
;========
; signature: read-file: string -> string
; purpose: expects the name of a file
;     written as a string,
;
;     has the SIDE-EFFECT of trying to
;     open that file and read its contents,
;  
;     then returns the contents read as
;     a single string

""
"practice.txt contents as a SINGLE string:"
"----------------------------------------"

;*** DO THIS ***
;----- 
; WRITE an expression, using read-file,
;     whose value will be a SINGLE string
;     containing all of the contents
;     of practice.txt:





;-----
; 1 part c
;-----
; Consider the following signature and
;     purpose comment for function read-lines,
;     from 2htdp/batch-io:
;========
; signature: read-lines: string -> list
; purpose: expects the name of a file
;     written as a string,
;
;     has the SIDE-EFFECT of trying to
;     open and read the contents of that file, 
; 
;     and returns the read contents as a
;     LIST of strings, each line being one
;     string in the list

""
"practice.txt contents as a list of "
"    line-strings:"
"----------------------------------------"

;*** DO THIS ***
;----- 
; WRITE an expression, using read-lines,
;     whose value will be a LIST of strings,
;     such that each string is ONE
;     line from practice.txt:





;-----
; 1 part d
;-----
; Consider the following signature and
;     purpose comment for function read-words,
;     from 2htdp/batch-io:
;========
; signature: read-words: string -> list
; purpose: expects the name of a file
;     written as a string,
;
;     has the SIDE-EFFECT of trying to
;     open and read the contents of that file, 
;
;     and returns those contents as a list
;     of strings, with each
;     white-space-separated "chunk" being a
;     string in this list

""
"practice.txt contents as a list of"
"    word-strings:"
"----------------------------------------"

;*** DO THIS ***
;-----
; WRITE an expression, using read-words,
;     whose value will again be a LIST of
;     strings -- but THIS time, each string
;     will be one white-space-separated
;     "WORD"/chunk from practice.txt:





;-----
; 1 part e
;-----
; Consider the following signature and
;     purpose comment for function
;     read-words/line, from 2htdp/batch-io:
;========
; signature: read-words/line: string -> list
; purpose: expects the name of a file
;     written as a string,
;
;     has the SIDE-EFFECT of trying to open
;     and read the contents of that file, 
;     
;     and returns its contents as a list of
;     lists, one sub-list per line, with
;     the white-space-separated
;     "words"/chunks in that line as
;     strings in that line's list

""
"practice.txt contents as a list of "
"    line-lists of word-strings:"
"----------------------------------------"

;*** DO THIS ***
;----- 
; WRITE an expression, using read-words/line,
;     whose value will be a LIST of LISTS of
;     strings -- such that each sub-list is
;     a list of white-space-separated
;     "WORD"/chunk strings from one line
;     from practice.txt:





;========
; PROBLEM 2 - writing a function that
;     "walks through" a list
;========
;==== TEMPLATE for a function that needs
;     to "walk through" all of the elements of a
;     variable-length list
;
; (define (a-list-funct ... a-list ...)
;     (cond
;         [(empty? a-list) ...]
;         [else (...
;                  ... (first a-list) ...
;                  (a-list-funct ... (rest a-list) ...) ...)
;         ]
;     )
; )

;*** DO THIS ***
;--------
; Using the DESIGN RECIPE, design a function
;     sum-list, which expects a list of numbers,
;     and just returns the SUM of the numbers in
;     that list. If called with an empty list,
;     it should return 0.
;
;     *   That is, if this function has as
;         its argument a list of numbers
;         containing 7, 10, and 41, then it
;         would return 58.
;
; Amongst its tests, include at least:
; *   one whose argument is an empty list
; *   one whose argument is a list of three or more numbers




;=====
; Remember: once you have Run these and are satisfied
;     with them,
; *   Use Gmail to EMAIL copies of this file lab6.rkt
;     *** AND ALSO YOUR FILE practice.txt ***,
;     to BOTH of you
;
; *   BOTH of you should submit this file
;     *** AND ALSO YOUR FILE practice.txt ***
;     to Canvas BEFORE you leave lab.
;
; *   ALSO answer the
;     "Week 6 Lab Exercise - Pair-Programming Peer Review Survey"
;     in Canvas, posted along with this lab exercise, by
;     11:59 pm TONIGHT (Friday, October 2)
;=====