#lang racket

(provide (all-defined-out))
(require csc151)
(require csc151/rex)

;; CSC-151-01 (Spring 2021, Term 1)
;; Lab: NAME (Side A)
;;   https://rebelsky.cs.grinnell.edu/Courses/CSC151/2021Sp1/labs/files-rex
;; Authors: YOUR NAMES HERE
;; Date: THE DATE HERE
;; Acknowledgements:
;;   ACKNOWLEDGEMENTS HERE

#|
In this lab, you and your partner will practice manipulating files
and strings using file and regular-expression (rex) procedures.

The person with the problem description should drive and their
partner should navigate.  Again, make sure to be good partners and
focus completely on solving the current problem on the driver's screen
rather than working ahead or on their own.

Also: Don't forget our new "start of session".  Chat with your partner
about working habits and strengths.  Maybe share something interesting
about yourself
|#

; +---------------+--------------------------------------------------
; | Provided code |
; +---------------+

(define phishy
  "fishy: one cat, one hat, two things, \none fish, two fish, red fish, blue fish, green and yellow fish \nred books \n\n\none and two\tor\tthree and four\nthat is flat\n")

#| AB |#

; +--------------------------------+---------------------------------
; | Exercise 1: Working with texts |
; +--------------------------------+

#|
Project Gutenberg <https://www.gutenberg.org/> provides an extensive
collection of public domain books in a variety of forms, including
"plain text".

a. Navigate to the Project Gutenberg Web site and download one or two books 
in plain text format. Strive for short- to medium-length books.
_Jane Eyre_ <https://www.gutenberg.org/ebooks/1260> is okay. _The Complete 
Works of William Shakespeare_ <https://www.gutenberg.org/ebooks/100> is not.

Both partners should download the same books.

<TODO: Enter the titles of the books and the corresponding file names.>

b. Pick one of the books you've downloaded and open it in a text editor
to view the content.

<TODO: Enter notes of anything you observe.>
|#

#| A |#

; +-------------------------------------------+----------------------
; | Exercise 2: Working with texts, revisited |
; +-------------------------------------------+

#|
a. Using a file you downloaded in the prior exercise, write
instructions in the definitions pane to read the characters, words,
lines, and complete contents from the book. (The contents should
be a single string.)  Call the results book-letters, book-words,
book-lines, and book-contents. For example,

(define book-letters (file->chars "pg1260.txt"))
|#

(define book-characters "<FILL IN>")

(define book-words "<FILL IN>")

(define book-lines "<FILL IN>")

(define book-contents "<FILL IN>")

#|
b. Write instructions to extract the first 20 characters, 10 words,
and 5 lines from the book.
|#

(define first-20-chars "<FILL IN>")

(define first-ten-words "<FILL IN>")

(define first-five-lines "<FILL IN>")

#|
c. Determine how many letters (letters, not characters) appear 
in the book.
|#

(define total-letters "<FILL IN>")

#|
d. Write instructions to extract lines 100 (inclusive) through 120
(exclusive) from the book.
|#

(define lines-100-to-120 "<FILL IN>")

#|
e. Write instructions to determine how many times the letter "a" appears 
in the book. (You need deal only with lowercase "a".)
|#

(define count-of-as "<FILL IN>")

#| B |#

; +----------------------------+-------------------------------------
; | Exercise 3: Creating files |
; +----------------------------+

#| A |#

; +---------------------------+--------------------------------------
; | Exercise 4: Miscellaneous |
; +---------------------------+

#|
If you return to the top of this file, you will see that we defined
a variable named `phishy`.
|#

#|
a. Suppose we create a file with 

    (string->file phishy "phishy.txt") 

What do you expect the contents of that file to look like?

<TODO: Enter an answer here.>
|#

#|
b. Check your answer experimentally.

<TODO: Cut and paste the results of your experiment here.>
|#

#|
c. One way to break up that string is at each space. Write an expression 
to do so. (You should not need regular expressions, at least not yet;
`string-split` should suffice.)
|#

(define split-at-space "<TODO>")

#|
d. Another way to break up that string is at each newline character.
Write an expression to do so. (You still should not need regular
expressions, at least not yet.)
|#

(define split-at-newline "<TODO>")

#|
e. The word "and" appears a few times in that string. Split it at that word.
|#

(define split-at-and "<TODO>")

#| B |#

; +--------------------------------------------------------+---------
; | Exercise 5: Splitting strings with regular expressions |
; +--------------------------------------------------------+

; +------------------------------+-----------------------------------
; | Exercise 6: Extracting words |
; +------------------------------+

