How to use ScalaCheck in the SBT console

If you add ScalaCheck to an SBT project like this:

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"

it’s only available in the SBT “test” scope. This means that when you start a Scala REPL session inside of SBT with its console command, the ScalaCheck library won’t be available in that scope.

To use ScalaCheck with the SBT console (REPL), don’t use its console command — use test:console instead. A complete example looks like this:

$ sbt

> test:console

scala> import org.scalacheck.Gen.choose

Note that after you type test:console your project may be compiled, so that step may take a few moments.

In summary, use SBT’s console command to start a “normal” Scala REPL inside SBT, and use test:console to start a REPL that you can run tests inside of. (Note that this same advice also applies to using ScalaTest or specs2.)

How to start a Scala REPL session inside SBT (Simple Build Tool)

Scala FAQ: How do I start a Scala REPL session from SBT (i.e., inside the Simple Build Tool)?

Answer: Type console to start a REPL session from inside SBT. This (a) compiles your Scala project and then (b) starts a REPL session.

If you don’t want to compile your project before starting a REPL session from inside SBT, type consoleQuick instead. alvin April 21, 2014 - 8:29am is a nice way to test JavaScript snippets. It’s a little like a REPL, but you need to press “run” for it to evaluate anything, and printing to the JavaScript console seems like the best way to see output.

The Chrome JavaScript debug console and [Object object] alvin August 11, 2013 - 1:38pm

As I’ve gotten back into client-side web development -- specifically using Sencha Touch 2, a JavaScript framework -- I’ve quickly run into a problem in the Chrome JavaScript debug console. When I try to use console.debug() to debug an object, I get this non-useful output about the JavaScript object I’m printing:

[Object object]

There may be better ways to print the desired object, but I quickly discovered this trick to printing all of the properties of a JavaScript object:

Getting help on Play Framework console commands alvin October 15, 2012 - 9:58am

It took me a few minutes to figure out that when you want help on Play Framework console commands (i.e., the Play command line tool), you may get more useful help by typing help play instead of just help. Using the first command shows information on commands like clean, compile, console, etc., which is what I'm more interested in.

To take a quick look at this, here's what you get when you type help play:

Common SBT commands (Scala SBT) alvin June 5, 2012 - 4:38pm

I had the common Scala SBT commands in the notes for my project named SARAH, and thought I'd list them here to make them easier to find:

Scala shell scripts and the command line: Prompting the user, and reading input alvin May 17, 2012 - 9:02am

A great thing about Scala is that not only is it scalable, it was also created to help you work on small tasks, including being useful in shell scripts. This includes small shell script tasks like prompting a user interactively from a shell script, and reading their input.

You can prompt users with print commands like println and print, and you can read their input with all of these methods that are available on the Scala Console class:

Mac OS X debug tip - Check the log files alvin December 11, 2010 - 6:33pm

Mac OS X debug FAQ: Help, I'm having a problem with [fill in the blank] on my Mac OS X system, how do I troubleshoot it?

I just ran into a problem when trying to create a Safari web clip dashboard widget, where the web clip isn't properly updating itself, and I stopped for a moment to think about how to troubleshoot/debug this Mac OS X problem. That's when I thought, "Okay, a Mac is a Unix system, check the log files." So I cracked open a Mac Terminal window, and checked the system log file: