Is there a Scala version of .irbrc or another way to define some default libraries for using REPL?

I wrote a small library that uses implicits to add functionality that is only needed when using REPL in Scala. Ruby has such libraries - for such things as beautiful printing, launching text editors (for example, the interactive_editor stone, which calls Vim from irb - see this post ), debuggers, etc. The library I'm trying to write adds some methods to the java.lang.Class and java.lang.reflect classes using the implicit conversion process "pimp my library" to help you find the documentation (first using Google, and then maybe using the JavaDoc / ScalaDoc viewer and possibly the StackOverflow API!). This is a scratch library: I spend so much time copying and pasting cool names on Google that I decided that I could automate the process.

This is the type of functionality that developers will want to add to their system for use only in REPL - they should not really add it to projects (partly because it may not be what their developers want, but also because if you spend some research development, it can only be with the Scala REPL, which is not called by the IDE or assembly tool).

In my case, I want to include several classes and install some implications - include .jar in CLASSPATH and import it mainly.

In Ruby, this is what you would add to your .irbrc file. Other REPLs have similar methods for setting parameters and importing libraries.

Is there a similar file or a way to do this for Scala REPL?

+6
scala shell configuration configuration-files
source share
3 answers

Not sure if this is what you are looking for, but if you put all the jars in the SCALA_HOME\lib directory. These banks will then be available for import into the REPL (using the import keyword).

EDIT: The most convenient option at the moment is to set the CLASSPATH environment variable. Any jars specified in the CLASSPATH variable are also available for import into REPL.

+1
source share

At the command line, you can use the -i option to load the file when running REPL:

 scala -cp mystuff.jar -i mydefs.scala 

Of course, you can wrap this in a shell script or batch file and run it instead of the usual scala command.

(I am using Scala 2.8.0 RC3).

+2
source share

The quick answer is probably not the one you are looking for, but what about input

: load path / to / some / scala / script / file.scala

in the console?

: The download will be read in the scala file and execute it as a script.

Another option is to use sbt to configure your dependencies and execute a console command.

The last option I can think of is to manually set the classpath on the command line and point it to the jars / class file folders that you should know about jvm about.

Let me know if this interests you, and I can provide more detailed information if necessary.

+1
source share

All Articles