Coder Social home page Coder Social logo

atomic-scala-corrections's People

Contributors

bruceeckel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atomic-scala-corrections's Issues

scala package import example problem p97

Hi, I am having trouble with the following code on page 97 re importing a package

Run the script as usual with:
scala ImportPythagorean.scala
You need ‘.’ In your CLASSPATH for this to work. A bug in Scala 2.11 and below causes a delay between compiling and making the classes available for import. To get around this bug, use nocompdaemon:
scala -nocompdaemon ImportPythagorean.scala

even when I attempt to run the script using the '-nocompdaemon' command it still fails giving error:

error: not found: value pythagorean
import pythagorean.RightTriangle

the directory structure appears correct after compiling PythagoreanTheorem.scala showing a new dir with name pythagorean containing a single class RightTriangle.class

the info given, doesn't really explain how what you really need to add to your CLASSPATH or what to if the workaround fails? I've looked online but as a noob I can't fathom it! I am actually amazed that in v2.11 there are any bugs regarding making any compiled classes available? Anyway any help would be greatly appreciated.

Dave

SimplyPrint.scala Not Found

Atom "Idiomatic Scala", exercise #4 refers to SimplyPrint.scala from the "Methods" atom, but there is no such program/script anywhere in the book or in the example files.

'new' keyword

There is an uneasy tension with the ‘new’ keyword. Right up through Summary 2 we are told that everything is an object and instances are created with the ‘new’ keyword. And then we create Vector without the ‘new’ keyword.

The Vectors atom is probably the earliest use of this technique. But it does not really explain why we seem not to follow the "rules" when constructing a Vector.

I know companion objects will be explained later in the book, but it deserves a bit of explanation when the reader first sees it.

Missing dependency 'object scala in compiler mirror'

From Activator >> Run >> ExampleRunner with Try.scala gives the following error. If there is a solution somewhere, please provide link. thanks.

error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by C:\Program Files\Java\jdk1.8.0_05\jre\lib\rt.jar(java/lang/Object.class)
Exception in thread "main" scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:53)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:173)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:161)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:161)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:162)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:162)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1392)
at scala.tools.nsc.Global$Run.(Global.scala:1216)
at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$compile$1(ScriptRunner.scala:110)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:161)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.util.package$.trackingThreads(package.scala:43)
at scala.tools.nsc.util.package$.waitingForThreads(package.scala:27)
at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:128)
at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:192)
at utils.RunFile$.apply(RunFile.scala:12)
at ExampleRunner$.delayedEndpoint$ExampleRunner$1(ExampleRunner.scala:3)
at ExampleRunner$delayedInit$body.apply(ExampleRunner.scala:1)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at ExampleRunner$.main(ExampleRunner.scala:1)
at ExampleRunner.main(ExampleRunner.scala)

From Andrew Harmel-Law

On page 233, paragraph 1, it says "as on lines 7, 8, and 11". I think this should be "as on lines 7, 9, and 11"

[ Page number doesn't track but will find with search ]

--- and ---

Atom: Reaching into Java
Exercise 1. "mayDate.getMonth" should be "mayDay.getMonth" ?

Atom: Installation (Mac) - path corrections

Unzipping does not produce a folder literally called “AtomicScala”, and there is no subdirectory called “code”. As it comes out of the zip the paths turn out to be “/atomic-scala-examples-master/examples”.

testall.sh ends up with permissions 644 after unzipping. So as directed “./testall.sh” will give permission denied. Need to chmod it. I think this is mentioned in the linux section, but mac section needs it too.

print(f) before f

on page 139, it is said

"And even though the println on line 5 appears to happen before f is defined, all the definitions (values and methods) are actually initialized before the rest of the body is executed, so it doesn’t matter that line 5 appears first - f is still available at that point."

The example is as def f, which goes fine by the compiler, but when doing val f or var f, the compiler gives a warning, and there are differences in the end execution upon object creation at runtime.

When it is def f, everything is normal, while creating new object, f indeed is available at println(f). In rest of the cases, when it's either val or var f, upon object creation, f is available at println(f) as 0, which is what is printed upon object creation. Later, doing object.f gives the expected value, but at first, f is not available as expected.

Should this not be included as a special note? Anyway, I haven't gotten through what is happening here.

Pg149 - Overloading as a language feature

The difference sought to be expressed in the first 2 sentences of the last paragraph, seems to be weakly resolved. Both sentences expose opposite theme based on presence and absence of overloading as a language feature. First line ends in "valuable simplification that produces more readable code." Second line ends in "puts less mental load on the reader." Both seem to arrive at similar ends - ease of use for the programmer.

Perhaps both the sentences need a better linguistic contrast?

Atom:Using Traits - The 5th and 6th exercises (and start points and solutions) seem screwed

Taking the Atom text itself (as in AtomicScalaV1.1.pdf), and the solutions in the downloadable zip (from https://github.com/AtomicScala/atomic-scala-solutions/archive/master.zip as of 10/10/2013) there seems to be a gap between what the exercise talks about and what the solution provides. The solution has things like Color, Texture and Dimension which come out of nowhere. Was there originally a exercise 4(b) which would have led up to this?

I've not posted to https://github.com/AtomicScala/atomic-scala-solutions/issues as it seemed more relevant to put it here.

println(obj) prints hash code, not object's memory location

Thank you very much for your great book.

In atom "Creating Classes" on page 88 and 89 it reads:

The part before the ‘@’ is the class name, and the number (yes, that’s a number even though it includes some letters – it’s called “hexadecimal notation” and you can learn about it in Wikipedia) indicates the address where the object is located in your computer’s memory.

I think the text I emphasized is not true. println(obj) calls obj.hashCode() if the object is not null. For the HotSpot implementation of the JVM for JDK 8 this means a call to os::random per default. Thus, the part after the @ has nothing to do with the object's memory location (which would lead to an ever-changing result of hashCode() because the JVM moves around objects in memory).

I'd propose changing the relevant text to something like "... and the number (...) is a random identifier for the object."

Pg 18: remove bold on the word "displays"

On the second bullet point, the 4th word, "displays", is bold when it should not be. This could confuse a beginner to type in "ls displays" in the terminal, when what they want is to type "ls". I'm looking at the 2nd edition of the book.

Many "Error Bookmark not defined" in pdf ToC

Downloaded the sample's today:
Saw many lines like this in the Table Of Contents:
For Loops ...................................................... Error! Bookmark not defined.
This might be related because of the sample, but it still looks unpolished.

pg158 - first line of an auxiliary constructor

Exercise element 3 is not valid because the first line of an auxiliary constructor can be a call to another auxiliary constructor and it needn't always be a call to the primary constructor.

Pg75 -

First para, 2nd line goes:

Note that declaring arguments is just like declaring vals: the argument name, a colon, and the type returned from the method.

Does the last clause ( "type returned from the method" ) belong to the context of the sentence, which is about method arguments' declaration being like vals' declaration ?

Solution 3 to Comprehensions Exercise 3 problem

This solution doesn't match what the exercise asks (apparently).
We're asked: "Modify yielding3 so the result is defined with an explicit type declaration."

This is yielding3:
def yielding3(v:Vector[Int]):Vector[Int]={
for {
n <- v
if n < 10
isOdd = (n % 2 != 0)
if(isOdd)
} yield {
val u = n * 10
u + 2
}
}

The solution starts using Lists and its generally unclear what the exercise whats me to do.
Here is the solution:
// Solution-3.scala
// Solution to Exercise 3 in "Comprehensions"
import com.atomicscala.AtomicTest._

def yielding3(l: List[Int]) : List[Int] = {
val result = for { n <- l
if n < 10
if n % 2 != 0
}
yield n
result
}
val theList2 = List(1,2,3,5,6,7,8,10,13,14,17)
yielding3(theList2) is Vector(1,3,5,7)

new Fairy with Fighting symbol name not $anon$1

In the chapter Polymorphism, the supplied sample code proscribes the following behavior on line 60 of the sample code:

battle(new Fairy with Fighting) is "1, Fight!" // Name: $anon$1

However under Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL, the string returned by currentMirror.reflect(o).symbol.toString when invoked by Name.className is simply $anon and thus this code fails.

I confirmed that this behavior happens both when running the scala command interactively and when running it from within IntelliJ.

The following snippet duplicates the issue:

scala> import reflect.runtime.currentMirror
import reflect.runtime.currentMirror
scala> trait Traitorous
defined trait Traitorous
scala> val o1 = new Object with Traitorous
o1: Traitorous = $anon$1@3ecc4651
scala> val o2 = new Object with Traitorous
o2: Traitorous = $anon$1@7c77f8a9
scala> currentMirror.reflect(o1).symbol
res60: reflect.runtime.universe.ClassSymbol = $anon
scala> currentMirror.reflect(o2).symbol
res61: reflect.runtime.universe.ClassSymbol = $anon

Pg148 - Method Signature and Enclosing Class

Pg148 - last two sentences say:

"A method signature also includes information about the enclosing class. Thus, the overloaded f methods in Overloading1 don't clash with the f methods in Overloading2."

I feel the explanation for not clashing comes from namespace separation, considering that a method signature, as given in the same para

"consists of the name, argument list and return type."

For users (vs. compiler) of the language, I don't see how a method signature also includes information about the enclosing class.

Scala Testing error

Hello everybody,

Looking the testing part (pag. 99), i got the next error:

julios-Mac-mini:testing juliovg$ scalac AtomicTest.scala
julios-Mac-mini:testing juliovg$ scala prueba.scala
/Users/juliovg/Documents/trabajo/Desarrollos/Scala/pruebas/testing/prueba.scala:5: error: object atomicscala is not a member of package com
import com.atomicscala.AtomicTest._
^
/Users/juliovg/Documents/trabajo/Desarrollos/Scala/pruebas/testing/prueba.scala:10: error: value is is not a member of Int
v1 is 11
^
/Users/juliovg/Documents/trabajo/Desarrollos/Scala/pruebas/testing/prueba.scala:11: error: value is is not a member of String
v2 is "a String"
^
/Users/juliovg/Documents/trabajo/Desarrollos/Scala/pruebas/testing/prueba.scala:12: error: value is is not a member of String
v2 is "Produces Error"
^
four errors found

You can see on the image the structure: https://openmerchantaccount.com/img2/scala-error.png

alt text

Slight issue with AtomicTest

It thinks Lists and Vectors are the same thing:

// Solution-3.scala
// Solution to Exercise 3 in "Comprehensions"
import com.atomicscala.AtomicTest._

def yielding3(l:List[Int]):List[Int] = {
  val result:List[Int] = for {
    n <- l
    if n < 10
    if n % 2 != 0
  } yield n
  result
}

val theList2 = List(1,2,3,5,6,7,8,10,13,14,17)
yielding3(theList2) is Vector(1,3,5,7)

Two Package declarations in one .scala file

on page 97, it's written:
" You create your own package using the package keyword (this must be the first non-comment statement in the file) followed by the name of your package (all lowercase) "

This statement seems to be more advice than rule. The requirement of having package keyword as the first non-comment statement in the file seems dispensable. A source file having multiple package declarations, with the respective code in a pair of curly braces, seems to work fine.

Compilation of a source file with two package keywords (with their respective code) seems to create two folders, distributing the respective class files to them. The compiler doesn't complain if in the same source file, first a class is defined, then two packages are defined, all with their respective codes in curly braces.

Even package nesting seems to work, with the nesting scheme being manifested in the directory scheme created on the file system.

Typos in Defining Operators, Exercise no. 4?

In e-book v1.1, the "Defining Operators" atom, exercise no. 4 asks us to satisfy the following tests:

val a3 = new FancyNumber3(2.0)
a3. ^(3) is 8
val b3 = new FancyNumber3(10.0)
b3 ^ 2 is 100

Given the text of exercise no. 4, "add another method ** which does the same thing as ^", shouldn't the operator in the tests be ** instead of ^?

Exercise 4 on page 159 requires technique not yet taught

The solution given for exercise 4 involves using a class as a type. (The class being used as a type is SimpleTime.)

As far as I can tell, this concept had not been introduced before this exercise. I finally peeked at the solution, saw the first ":SimpleTime" that appears in the code and lightbulbled (oh! You can use classes as types?!) and figured it out.

But I don't think the authors probably meant for the learning to take place that way. Probably when they wrote this exercise they were thinking the use of classes as types had already been introduced, and that would certainly be better from a teaching standpoint--solutions to exercise should generally use already-introduced techniques, or else the student might become over-frustrated.

Instance of an object

On page 252, it is written about about Lines 70-71 that

"This technique creates a single instance of an object without creating a new named class just for that one usage."

I feel it should rather be:
"This technique creates a single instance of a class without creating a name for it, just for that one usage."
OR
"This technique creates a single instance of an anonymous class without a name, just for that one usage."

Atom: "Handling Non-Values with Option" Exercise 3 solution is empty

Atom: "Handling Non-Values with Option"

Exercise 3 solution is empty.

Suggest something like this is used:

// TicTacToe.scala
class Cell {
var entry = ' '
def set(e:Char):Option[String] = {
if(entry==' ' && (e=='X' || e=='O')) {
entry = e
Some("successful move")
} else
None
}
}

class Grid {
val cells = Vector(
Vector(new Cell, new Cell, new Cell),
Vector(new Cell, new Cell, new Cell),
Vector(new Cell, new Cell, new Cell)
)
def play(e:Char, x:Int, y:Int):Option[String] = {
if(x < 0 || x > 2 || y < 0 || y > 2)
None
else
cells(x)(y).set(e)
}
}

val grid = new Grid
grid.play('X', 1, 1) is Some("successful move")
grid.play('X', 1, 1) is None
grid.play('O', 1, 3) is None

Case Class Vals and Class Vals

On page 162, 2nd para 2nd line:

It says: "However, a case class automatically creates all the class arguments as vals."

This is also what happens by default, without a leading val/val in normal class arguments.

What was meant here to be communicated was about the accessibility of class parameters (apart from the implied 'bar on reassignment to vals').

Without the keyword val, the class parameter seems be accessible only in case classes and not in normal classes. This could be made explicit in this para, as a reader could think that it just means that vals can't be reassigned, when actually, there is an additional implied meaning about accessibility of class parameters from instances of case classes.

Small terminology issue in Summary 1 of Sample PDF

In the second code block of page 70, it is mentioned that the REPL will create a temporary variable for the result of the expression, in this case called res0, to hold the result of the expression. Technically speaking this is incorrect, because res0 is a val, not a var (even though I suspect that later on in the book there might be some discussion about how vals might be implemented as so-called "temporary vars", or vice versa). Proof of the claim follows:

scala> :paste
// Entering paste mode (ctrl-D to finish)

if(9 > 10) {
   42 
} else {
   50
}


// Exiting paste mode, now interpreting.

res0: Int = 50

scala> res0=10
<console>:8: error: reassignment to val
       res0=10

Pg100 - Cause-effect resolution

First line goes,

Robust code must be tested constantly

Shouldn't it be the other way round, something like, for code to be robust, it must be tested constantly?

CompoundExpressions2.scala

In CompoundExpressions2.scala the last else should be false instead of true, or else isOpen will always be true for other activities than "swimming" and "ice skating" regardless of the hour.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.