\documentclass[noanswers,addpoints,x11names,11pt]{exam}
\usepackage[xetex,text={6.5in,9in},centering]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{caption2}
\usepackage{soul}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{datetime}
\usepackage{enumerate}
\usepackage{xltxtra}

\usepackage{graphicx}
\usepackage[xetex]{hyperref}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{enumitem}
% compact itemized and then enumerated
\setlist{leftmargin=*,
  noitemsep,
  topsep=5pt,
  parsep=0pt,
  partopsep=0pt,
}

\setlist[enumerate]{leftmargin=*,
  itemsep=2pt,
  topsep=0pt,
  parsep=0pt,
  partopsep=0pt,
}

\setlist[description]{leftmargin=*,
  itemsep=2pt,
  topsep=0pt,
  parsep=0pt,
  partopsep=0pt,
}

\usepackage{tabu}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,decorations.pathmorphing,backgrounds,positioning,fit}
\usepackage{pgf-umlcd}

\usepackage{fontspec}
\IfFontExistsTF{Gentium Book Plus}{
  \setmainfont{Gentium Book Plus}
}{
  \setmainfont{Times New Roman}
}

\IfFontExistsTF{Comic Code}{
  \setmonofont{Comic Code}[
  Scale = 0.85,
  ]
}{
}

\usepackage{float}
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  numberstyle=\footnotesize,
  language=java,
}

\newcommand{\checkpoint}{{\Large $\checkmark$} }

% classname
\newcommand{\semester}{Spring 2025}
\newcommand{\className}{Programming Languages}
\newcommand{\classNumber}{CIS~443}
\newcommand{\classFullName}{\classNumber~\className}

\newcommand{\assignmentNumber}{01}
\newcommand{\assignmentName}{Quadratic}
\newcommand{\assignmentDescription}{Using REPL}

\newcommand{\assignmentTitle}{\texttt{p\assignmentName} --- \assignmentDescription}

\newcommand{\gitRepoName}{p\assignmentNumber-\assignmentName}

\renewcommand{\dateseparator}{-}
\yyyymmdddate

% /classname

\pagestyle{headandfoot}
\firstpageheader{\classFullName\\\semester}{\assignmentName\\~}{\today\\~}
\runningheader{\assignmentName}{}{\today}

\newenvironment{showExample}[1]{
  \begingroup
  \renewcommand{\solutiontitle}{\noindent\textbf{Example:}\enspace}
  \printanswers
  \begin{solution}[#1]
  }{
  \end{solution}
  \endgroup
}

\definecolor{javafile}{rgb}{0.90, 0.87, 0.7}
\definecolor{schemefile}{rgb}{0.70, 0.87, 0.7}
\definecolor{inputfile}{rgb}{1.0, 0.7, 0.6}
\definecolor{configfile}{rgb}{0.75, 0.84, 0.66}
\definecolor{outputlisting}{rgb}{0.66, 0.75, 0.84}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist

\begin{document}
\pointsinrightmargin{}

\begin{center}
  \textbf{\assignmentTitle{}}
\end{center}

\section*{Learning Outcomes}
After completing this program, students will be able to
\begin{itemize}
\item Start and stop the \textbf{Racket Scheme} REPL.
\item Start and stop the \textbf{Java} \lstinline{jshell} REPL.
\item Write and run a simple function in both Scheme and Java using
  their respective REPL.
\end{itemize}

This assignment is an introdution to using a \emph{read-execute-print}
loop (REPL). Students will start with a Java REPL, using a language
they know in a new, interpreted, way. Then they will explore the MIT
Scheme REPL, the version of Scheme that we will be using this
semester, doing the same work in the new language.


\section*{Procedure}
\begin{questions}
\question{} Read the \textbf{whole} assignment. This is important for
  \emph{every} assignment: it puts the task into your brain so that it
  can begin working on answering the questions. Of particular interest
  when you read are the SLO (first section above); gives you the links
  between the assignment to the big picture (learning computer
  science).

\question{} Configure your Racket by installing the
  \lstinline{simply-scheme} language definition.
  \begin{itemize}
  \item This need only be done once on the lab computers (or any other
    Racket/Dr. Racket installation).
  \item Using the \lstinline{raco} program, install the
    \lstinline{simply-scheme} language definition into your local
    directory:
\begin{lstlisting}[backgroundcolor=\color{outputlisting},language={}]
$ raco pkg install simply-scheme
\end{lstlisting}

    It should then download and compile some amount of code. You can
    test that it works by starting \lstinline{racket} with the new
    language definition:
\begin{lstlisting}[backgroundcolor=\color{outputlisting},language={}]
$ racket -I simply-scheme
  Welcome to Racket v8.14 [cs].
  >
\end{lstlisting}

    As shown, it should start the REPL w/o any error
    messages. \lstinline{Ctrl-D} (for ``end-of-file'') or the command
    \lstinline{(exit)} terminates the Racket REPL.
  \end{itemize}

\question{} Review how to solve the \emph{quadratic equation}:
  \begin{itemize}
  \item What are the \emph{input} value(s)?
  \item What are the \emph{output} value(s)?
  \item How is it calculated?
  \end{itemize}

\question{}
  Figure out how you will capture (to a text file) a session
  inside a terminal. You will be turning in one text file containing a
  session with the Scheme REPL and a session with the Java REPL.

  Probably the easiest way to do this is to cut and paste out of the
  terminal window. The terminal is using special characters to move
  the cursor around and those are captured by character capture
  programs.


  \subsection*{The Java REPL}
\question{} Since Java version 9, the package has included the \lstinline{jshell}
program in the SDK distribution. If the Java binaries (think
\lstinline{javac}, \lstinline{java}) are in the path in your terminal,
then \lstinline{jshell} should run:

\begin{lstlisting}[backgroundcolor=\color{outputlisting},language={}]
$ jshell
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=lcd
  Welcome to JShell -- Version 21.0.4
  For an introduction type: /help intro

jshell>
\end{lstlisting}

\footnote{\lstinline{_JAVA_OPTIONS} is set on lab machines to improve GUI
appearance.}

Use \lstinline{help} to get interactive help inside the program.

At the prompt you are in an interactive Java environment. To define a
function, say \lstinline{square}, just write what would go inside the
class definition:
\begin{lstlisting}[language={},backgroundcolor=\color{javafile}]
jshell> int square(int n) {
   ...>     return n * n;
   ...> }
  created method square(int)

jshell> square(7)
$2 ==> 49
jshell>
\end{lstlisting}

\texttt{jshell} (like many shell-like programs) ends when it
encounters the \lstinline{^D} (Ctrl-D) or End-Of-File character.

\subsection*{The Scheme REPL}
\question{} Racket (Dr. Racket is the GUI version; we will use the CLI) is a
Scheme implementation that is designed for teaching and for defining
other languages (variants of Scheme, mostly). We will use the
\lstinline{simply-scheme} variant so that we can use the exercises in
that book.

Start the Racket REPL with the command \lstinline{racket}. Quitting,
as described above, uses \lstinline{Ctrl-D} or the \lstinline{(exit)}
command.

You can submit properly formatted Scheme expressions to the REPL and
it will \textbf{R}ead, \textbf{E}valuate, and \textbf{P}rint the
results in a \textbf{L}oop. You can do math or define functions, like
\lstinline{square}:

\begin{lstlisting}[language={},backgroundcolor=\color{schemefile}]
$ racket -I simply-scheme
Welcome to Racket v8.14 [cs].
> (+ 1 2 3)
6
> (list (* 1 5) (* 2 5) (* 3 5))
'(5 10 15)
> (define (square n)
    (* n n)
  )
> (square 7)
49
>
\end{lstlisting}

\textbf{Error Handling} \lstinline{racket} shows an error message when
something is not right:

\begin{lstlisting}[language={},backgroundcolor=\color{schemefile}]
> (* a b)
a: undefined;
 cannot reference an identifier before its definition
  in module: top-level
 [,bt for context]
> user break [,bt for context]
\end{lstlisting}



\section*{Your Quadratic Equation}
\question{}
Each student will generate their own quadratic equation. Take each of
your three (3) initials (if you have fewer, select enough letters to
have three; if you have more, use the first three). Translate each
into a number by mapping the alphabet to the range 3..28: a=3, b=4,
c=5, \dots, y=27, z=28.

Call the three numbers $i_1$, $i_2$, and $i_3$ (initials one through
three).

Your quadratic equation is then

$(i_1 + i_2)x^2 + (i_1 + i_3)x - (i_2 + i_3)$

For example:

\noindent
\\Brian C. Ladd\\
$i_1 = 4$, $i_2 = 5$, $i_3 = 14$.\\
$q(x) = 9x^2 + 18 x - 19$

\section*{The Questions}
\question{}
For each of the two REPLs: run the REPL and capture the whole session
into a text file. Use the programming language in the interpreter to
answer the following questions, once in each language.

\begin{enumerate}
\item What version of the REPL are you running? (Very Easy)
\item Find the \emph{cube} of $i_1+i_2+i_3$.
\item Using the \emph{quadratic formula}, find \textbf{both} real
  roots (zeroes) of \emph{your} quadratic equation.
\item Write a function, \lstinline{q} that takes a floating point
  number and evaluates your quadratic equation at that point. Use it
  to verify your zeros and determine whether the quadratic is
  \emph{positive} or \emph{negative} between the two zeroes.
\end{enumerate}

\section*{Submit through Classroom Management System}
\question{}
Submit \emph{both} interactive sessions, one for Java and one
for Scheme, in one text file.
\end{questions}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
