By Developers, For Developers

Historical errata for Modern Systems Programming with Scala Native

PDF PgPaper PgTypeDescriptionFixed onComments
Page SUGGEST

In general I find the code samples hards to follow. It is not made clear where the line endings are and it is also not made clear whether one is at the command line or inside the Docker instance.

Specifically this block of code
“:scala-native:~ $ mkdir ~/my_code
> docker run -it -p 8080:8080 -v
~/my_code:/root/my_code
scala-native> ~/book-code # ls ..
​book-code my_code”

I could be getting this wrong but ….
1) it appears I am trying to run this inside an already running docks/scala instance which seems wrong
2) I have made different assumptions where the line breaks are and although it seems to take some actions

if I start a docker/scala-native session with
“docker run -it -p 8080:8080 rwhaling/scala-native-book”

then run the next command I get this
":scala-native:~ $ mkdir /my_code > docker run -it -p 8080:8080 -v/my_code:/root/my_code scala-native> ~/book-code
mkdir: unrecognized option: i
BusyBox v1.25.1 (2016-10-26 16:15:20 GMT) multi-call binary.

Usage: mkdir [OPTIONS] DIRECTORY…

Create DIRECTORY

\t-m MODE\tMode
\t-p\tNo error if exists; make parent directories as needed"

So if I run it a the Mac cli I get
“mkdir: /Users/johnmontaguehowitt/my_code:/root: No such file or directory” but in my home directory it gives me these directories & files
-rw-r—r— 1 johnmontaguehowitt staff 0 3 Feb 10:50 docker
-rw-r—r— 1 johnmontaguehowitt staff 0 3 Feb 10:50 book-code
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 my_code
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 run
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 -it
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 -p
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 8080:8080
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 -v
drwxr-xr-x 2 johnmontaguehowitt staff 64 3 Feb 10:50 scala-native
all of which are empty

I have tried other combinations such as
“mkdir /my_code > docker run -it -p 8080:8080 -v/my_code:/root/my_code scala-native > ~/my_code”

and

“mkdir /my_code > docker run -it -p 8080:8080 -v/my_code:/root/my_code scala-native > ~/book-code”

but get the same result

2019-09-09
12TYPO

“All the code in this book been tested with Scala Native 0.3.8,”
‘has’ is missing before ‘been’

2019-09-09
19SUGGEST

“You should also see a 4.2MB file at target/scala-2.11/hello-minimal-out”

This has been already described in the previous paragraph and thus should be changed.

2019-09-09
30SUGGEST

“but we’ll use disk files” -> “but we’ll also use disk files”

2019-09-09
33TYPO

“to scan a multiple items from the line” -> “to scan multiple items from the line”

2019-09-09
35TYPO

“to be able isolate” -> “to be able to isolate”

2019-09-09
38OK

``````
val word = split_fields(0)
val year = split_fields(1).toInt
val count = split_fields(2).toInt
if (count > max) {
`
I would move some arrays accesses inside the if block
`
val word = split_fields(0)
if (count > max) {
val year = split_fields(1).toInt
val count = split_fields(2).toInt
`

2019-09-10I like that stylistically, but I think it creates a logic issue - since we are using `count` in the if clause's predicate, we cannot declare it afterward, inside the block.
41TYPO

“whereas Scala Native took 30 seconds”

Final dot is missing

2019-09-09
66TYPO

“Scala Naive provides helper methods” -> “Scala Native provides helper methods”

2019-09-09
66TYPO

“a different size than what it is nominally expecting from the function defintion” ->
“a different size than what it is nominally expecting from the function definition”

Typo on definition

2019-09-09
67TYPO

“as well as multiple entires” -> “as well as multiple entries”

2019-09-09
145TYPO

“Although most Scala ExecutionContexts use some kind of thread poll”
Isn’t it thread pool in this context?

2019-09-09
176TYPO

" to refer to to control mechanism" -> " to refer to the control mechanism"

2019-09-09
217SUGGEST

I would mention the SQLite C library in the section “Other Integrations”

2019-09-10Good catch! I've also added a shout-out to your sqlite4s library :-)
27TYPO

> We aren’t passing any arguments yet, so we don’t have any additional arguments or placeholders in the format string.

> Second, the string itself now looks like this: c“hello, world\
”.

The discussed code (p26) does have the arguments and the string is different:
> stdio.printf(c“hello native %s!\
”,c“world”)

22TYPO

There’s this:

> If you look in your build directory at target/scala-2.11, you’ll see a 4.2MB executable file called hello-minimal-out.

And the next paragraph reads this:

> You should also see a 4.2MB file at target/scala-2.11/hello-minimal-out.

That’s the same file. I had to re-read it a couple of times to see if I’m missing or misreading something.

xviTYPO

There is a closing parenthesis missing on the line:

def main(args:Array[String]:Unit = {

114SUGGEST

In LibUVServer/async_tcp/main.scala listing:

the meaning of these two lines is not obvious at first:
var client_state_ptr = (!client).asInstanceOf[Ptr[ClientState]]
client_state_ptr = initialize_client_state(client)

Only tip is page 113 is a reference to “tcp handle’s inner Ptr[Byte]”.
But I had to check in the header file uv.h that the first field of the uv_tcp_s structure
is client storage “void* data”, and that thus it is OK to access it using the address of the structure.
It may be useful to readers to add a comment that it is a technical trick to access the first field of the
struct defined as an opaque type.

114ERROR

in main.scala listing client_state_ptr is set twice,
both inside initialize_client_state(…) : !client = client_state_ptr.asInstanceOf[Ptr[Byte]] before returning it
and in the calling context apply(…) : client_state_ptr = initialize_client_state(…)

NB: both functions have its own “client_state_ptr” variable, I would have preferred distinct names,
for instance client_state_field_ptr / allocated_client_state_ptr to point out their roles.

6TYPO

It says that hexadecimal address consists of 16 characters, but actually it has 14 characters

Categories: