Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting package in Scala REPL

Is there a way in the Scala REPL to set the "active" package scope ? Say I have a package com.package with class A, I want to be able to type new A() instead of new com.package.A() without explicitly doing import com.package.A. There might be a number of other classes in that package I'm interested into and I don't want to polute my REPL's global namespace by doing import com.package._.

Even better, I'd like to define class A without typing its fully qualified name. Something like:

package com.package // do this once

class A
class B

val a = new A()
val b = new B()

I'm aware of the :paste -raw command, but that would require me to type package com.package for each block; I'm really looking for a stateful command to change the "current working package", if you will.

like image 974
gsimard Avatar asked Aug 16 '14 19:08

gsimard


1 Answers

Simply put, you cannot.

Each command in the scala REPL is wrapped into a newly generated package, as explained here.

Also, there was a ticket asking package { } support in the REPL, but it was dismissed as :paste -raw was considered enough for the purpose.

like image 122
Gabriele Petronella Avatar answered Sep 20 '22 11:09

Gabriele Petronella