#lang racket

(require csc151)

;; CSC 151-01 (Spring 2021, Term 1)
;; Lab: Basic Types (Side B)
;;   https://rebelsky.cs.grinnell.edu/Courses/CSC151/2021Sp2/labs/basic-types
;; Authors: YOUR NAMES HERE
;; Date: THE DATE HERE
;; Acknowledgements:
;;   ACKNOWLEDGEMENTS HERE

#|
In this lab you will be working with your partner to discover
common ways we manipulate the basic primitive types of Racket.
Please refer to the lab write-up as well as the reference page
on the course website for more information about the various
functions we introduce in this lab.

For this lab, the A side will begin driving and B side will navigate.
The A side of this lab consists of exploration of the primitive
numeric types.

Once you are done with the A side, switch to the B side problems
that have your team explore the textual primitive types.  Here,
B side should drive and A side should nevigate.  When you are done,
combine both your files, rename them to basic-types.rkt, and upload
the file to Gradescope.

As a reminder, please make sure to work synchronously on this lab.
That is, you should not take your individual parts and work on them
in isolation.  The lab is designed for you to work together and
collaborate on a solution!  In particular, the navigator should be
focused on the problem the driver is working on and doing other
stuff.  
|#

#| A |#

; +----------------------------------------+-------------------------
; | Exercise 1: Simple numeric computation |
; +----------------------------------------+

; +------------------------+-----------------------------------------
; | Exercise 2: Remainders |
; +------------------------+

; +------------------------------------+-----------------------------
; | Exercise 3: From reals to integers |
; +------------------------------------+

; +---------------------------+-------------------------------------
; | Exercise 4: Large numbers |
; +---------------------------+

; +--------------------------+---------------------------------------
; | Exercise 5: Digit tricks |
; +--------------------------+

#| AB |#

#| 
Switch driver and navigator.  (B will now drive, A will now navigate.)
|#

#| B |#

; +--------------------------+---------------------------------------
; | Exercise 6: Creating @'s |
; +--------------------------+

#|
Develop three ways of constructing the string "@@@": one using a call
to make-string, one a call to string, and one a call to list->string.
Copy the this code snippet to your file and replace the placeholder
strings in each define with one of the expressions you create.
|#

(define making-@s-1 "todo!")

(define making-@s-2 "todo!")

(define making-@s-3 "todo!")

; +-----------------------------+------------------------------------
; | Exercise 7: Textual corners |
; +-----------------------------+

#|
Each of the following expressions evaluates to a string.  For each
expression write (a) its length of its resulting string value and
(b) a sentence description of the resulting string.
|#

#|
Length of corner-1: 
Description of corner-1: 
|#
(define corner-1 "")

#|
Length of corner-2: 
Description of corner-2: 
|#
(define corner-2 "hello world!")


#|
Length of corner-3: 
Description of corner-3: 
|#
(define corner-3 "\"hello world!\"")

#|
Length of corner-4: 
Description of corner-4: 
|#
(define corner-4 (string #\space))

#|
Length of corner-5: 
Description of corner-5: 
|#
(define corner-5 (string))

#|
Enter any notes on what you've learned from this exercise.

|#

; +------------------------+-----------------------------------------
; | Exercise 8: Substrings |
; +------------------------+

#|
Consider the string "Department". Using the substring procedure, we
can extract a wide variety of words from this one string. Write a
Racket expression to extract each of the requested words below. You
may use substring multiple times in combination with string-append,
but please do not use string constants (e.g. "apart"), characters, or
any other procedures.

a. Write an expression to extract the string "Depart" from "Department".
b. Write an expression to extract the string "part" from "Department".
c. Write an expression to extract the string "ment" from "Department".
d. Write an expression to extract the string "a" from "Department".
e. Write an expression to extract the empty string from "Department".
f. Write an expression to extract the string "Dent" from
   "Department". Note that you may need to use two calls to substring
   along with a call to string-append.
g. Write an expression to extract the string "apartment" from
   "Department". Once again, you may need multiple calls.

Use the interactions pane to check that each of your defined
expressions produces the desired value.
|#

(define substring-ex-a "TODO!")

(define substring-ex-b "TODO!")

(define substring-ex-c "TODO!")

(define substring-ex-d "TODO!")

(define substring-ex-e "TODO!")

(define substring-ex-f "TODO!")

(define substring-ex-g "TODO!")

; +---------------------------------+--------------------------------
; | Exercise 9: Referencing lengths |
; +---------------------------------+

#|
Here are two opposing views about the relationship between
string-length and string-ref:

a. "No matter what string str is, provided that it is not the empty
   string, (string-ref str (string-length str)) will return the last
   character in the string."
b. "No matter what string str is,
   (string-ref str (string-length str)) is an error."

Which, if either, of these views is correct? Why? Experiment with code
in the interactions pane, substituting concrete strings for str (e.g.,
"hello world!"), to arrive at an answer. Answer this in a sentence or
two in the space below.

<TODO: write your response here>
|#

; +---------------------------------------+--------------------------
; | Exercise 10: Collating your sequences |
; +---------------------------------------+

#|
In the reading, we discussed the fact that Racket assigns each of its
characters a unique integer.  These numbers are called a collating
sequence.  In this exercise, we'll explore these sequences in more
detail.
|#

#|
a. Compare notes with your partner about your answers to Check 2:
Collating sequences from the reading.  Use this acquired knowledge
to answer the following question:

What are the collating sequence numbers for the uppercase English
letters (A--Z)?  Write your answer in the space below:

<TODO: write your description here>

(Hint: the description should be shorter than listing 26 letter-number
pairs!)
|#

#|
b. Use your answer from part (a) to describe in a few sentences a
method for determining if a character is an upper-case English letter
by using collating sequences and subtraction.

<TODO: describe your method here>
|#

#|
c. Describe how you would extend your answer to part (b) to also
include lower-case English letters.  Can you just use the numbers
corresponding to 'A' (the beginning of the uppercase letter sequence)
and 'z' (the end of the lowercase letter sequence) or do we need to do
something more complicated?

<TODO: describe your updated method here
|#

#|
d. Finally, let's think a little bit more broadly!  What about other
languages?  For example, below are lowercase and uppercase alpha and
omega, the beginning and end of the Greek alphabet:

Α (uppercase alpha---note: *not* A!)
α (lowercase alpha)
Ω (uppercase omega)
ω (lowercase omega)

Describe in a few sentences how you would incorporate other languages
into your technique.  If you have the capability, try out letters in
other languages to see if your technique still works!

<TODO: describe your updated method here>
|#

#| AB |#

#|
Wrapping up

At this point, you should know how to combine your lab files and submit
them to Gradescope.  Please call the result basic-types.rkt.
|#
