miciek / grokkingfp-examples

All examples and exercises from the Grokking Functional Programming book
https://www.manning.com/books/grokking-functional-programming?utm_source=michal&utm_medium=affiliate&utm_campaign=book_khan_grokking_6_26_19&a_aid=michal&a_bid=7c041142
135 stars 52 forks source link

Cant start REPL in code directory #85

Closed okc0mputer closed 2 years ago

okc0mputer commented 2 years ago

receiving this error when running the sbt console command:

[info] welcome to sbt 1.6.2 (Azul Systems, Inc. Java 11.0.15) [info] loading settings for project grokkingfp-examples-master-build from plugins.sbt ... [info] loading project definition from /Users/okcomputer/grokkingfp-examples-master/project [info] loading settings for project root from build.sbt ... [info] set current project to grokkingfp-examples (in build file:/Users/okcomputer/grokkingfp-examples-master/) [info] compiling 36 Scala sources and 21 Java sources to /Users/okcomputer/grokkingfp-examples-master/target/scala-3.1.2/classes ... [error] /Users/okcomputer/grokkingfp-examples-master/src/main/java/ch02_ShoppingCartDiscounts.java:110:1: Illegal static declaration in inner class ch02_ShoppingCartDiscounts.ShoppingCart [error] modifier 'static' is only allowed in constant variable declarations [error] public static int getDiscountPercentage(List items) { [error] if(items.contains("Book")) { [error] return 5; [error] } else { [error] return 0; [error] } [error] } [error] /Users/okcomputer/grokkingfp-examples-master/src/main/java/ch02_TipCalculation.java:78:1: Illegal static declaration in inner class ch02_TipCalculation.TipCalculator [error] modifier 'static' is only allowed in constant variable declarations [error] public static int getTipPercentage(List names) { [error] if(names.size() > 5) { [error] return 20; [error] } else if(names.size() > 0) { [error] return 10; [error] } [error] return 0; [error] } [error] (Compile / compileIncremental) javac returned non-zero exit code [error] Total time: 15 s, completed May 21, 2022, 6:09:07 PM

miciek commented 2 years ago

Hey @okc0mputer. Thanks for reporting! The book uses Java 17 or higher (latest LTS JDK version). You are using Java 11.

This information is in the book. I will update the README file. Would you help me by letting me know where did you look for a resulution/setup instructions? Where would you put the Java 17 or higher information to make sure more people understands this?

Thanks for helping out and I hope you enjoy the rest of the book!

okc0mputer commented 2 years ago

While I did read the part in the book recommending java 17, I already have java 11 installed. The book says other LTS versions should be compatible, so I used it to avoid having to install another JDK. Screen Shot 2022-05-24 at 2 07 05 PM

I did not really look for a resolution simply because runnning book sample code is of minimal importance to me, and Scala works just fine with java 11. Reading a book should not require troubleshooting, in my opinion.
Definitely change the section regarding Installing the JDK so that it does not say other versions should work. Even better, change the code to work with the older LTS versions. That would provide better accessibility to readers such as myself (and many others I'm sure) who have a JDK version < 17 installed already.
While I am new to Java/JVM languages, I am planning on applying what I learn from this book to my Clojure learning. At the time I installed Clojure java 11 was the currently recommended JDK, which is why I had not already upgraded. Your readers will be similar to myself in that they may have an existing JDK and are using your book to apply knowledge to another functional language - whether on the JVM or otherwise.

miciek commented 2 years ago

Thanks @okc0mputer! I completely agree!

I committed the version that works with Java 11 as well. Please checkout the github version and let me know if that works fine. We will update the book code too.

I hope you'll enjoy the rest of the book. Thanks for the feedback.