Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic checking of Scala examples #19

Open
winitzki opened this issue Sep 17, 2020 · 1 comment
Open

Automatic checking of Scala examples #19

winitzki opened this issue Sep 17, 2020 · 1 comment

Comments

@winitzki
Copy link
Owner

Scala code examples in the book are not automatically checked for correctness. So, some of the code examples may contain errors that are difficult to spot manually.

Initially, all code examples were tested in the Scala interpreter and copy/pasted into the book. However, the book text has been edited, which made it necessary to change some of the code samples as well. The result is that some of the code samples have small errors (e.g. changing the name of a variable in one place but not in another place).

The idea is to enable automatic checking of the book's text against a separate set of files that have been run through the Scala compiler.

Steps to implement:

  1. Create an mdoc file (or a set of files) containing all Scala code samples from the book, organized in such a way that everything compiles and runs. This requires adding all the necessary import statements, perhaps putting some code into objects for encapsulation, etc.
  2. Run the files through mdoc to make sure everything compiles, and prepare output files.
  3. Create a script that extracts Scala code examples from the .tex or .lyx files in the book's source code.
  4. For each code example from the book, make sure that exactly the same code is present in one of the mdoc output files.

Note that mdoc output contains some Scala REPL output as comments. We may or may not be able to use that.

Some of the Scala code examples contain Scala REPL lines, such as

scala> 1 + 2
res0: Int = 3

It is not clear whether we can easily parse these lines and verify that the mdoc output contains the correct results. It may be necessary to skip all these lines.

@winitzki
Copy link
Owner Author

winitzki commented Jul 15, 2021

At the moment, all examples are extracted into the mdoc/ subdirectory when the pdf file is build (by running make_sofp_pdf.sh).

for f in $name-*tex; do g=basename "$f" .tex; cat $g.pre.md <(perl extract_scala_snippets.pl < $f) > mdoc/$g.md; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant