Skip to main content
Contents Index
Dark Mode Prev Up Next Scratch ActiveCode
\(\newcommand{\identity}{\mathrm{id}}
\newcommand{\notdivide}{{\not{\mid}}}
\newcommand{\notsubset}{\not\subset}
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\gf}{\operatorname{GF}}
\newcommand{\inn}{\operatorname{Inn}}
\newcommand{\aut}{\operatorname{Aut}}
\newcommand{\Hom}{\operatorname{Hom}}
\newcommand{\cis}{\operatorname{cis}}
\newcommand{\chr}{\operatorname{char}}
\newcommand{\Null}{\operatorname{Null}}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\newcommand{\sfrac}[2]{{#1}/{#2}}
\)
Section 5.3 Code Lens
CodeLens is an interactive tool for following program execution, much like a debugger, without the ability to influence flow control or variable values. For use without a server, traces must be computed beforehand. First, we have some trivial programs, to provide minimal testing.
Listing 5.3.1. A Python program, stepable with CodeLens
Listing 5.3.2. An C program, stepable with CodeLens
Listing 5.3.3. A Java program, stepable with CodeLens
Codelens interactives can be given one or more checkpoints where the user is asked a question as the code is executed:
Listing 5.3.4. A Python program, stepable with CodeLens, with questions
If a Codelens contains checkpoints, it is also possible to make it into an exercise. For use on Runestone, there should be an
@label on the exercise:
Checkpoint 5.3.5 . A C++ program as CodeLens exercise.
Run the codelens and answer the questions it asks.
Now some moderately more complicated programs to find the prime numbers less than
\(20\text{.}\) We do not vouch for the quality of these, or even their correctness!
Listing 5.3.6. Sieve of Eratosthenes, Java
Listing 5.3.7. Sieve of Eratosthenes, C++
Listing 5.3.8. Sieve of Eratosthenes, Java