Installing a package in Scala REPL

Is there a way in the Scala REPL to set the β€œactive” area of ​​a package? Let's say I have package com.package with class A , I want to be able to type new A() instead of new com.package.A() without explicitly executing import com.package.A . There may be several other classes in this package, and I do not want to publish the global REPL namespace by doing import com.package._ .

Even better, I would like to define class A without entering its full name. Sort of:

 package com.package // do this once class A class B val a = new A() val b = new B() 

I know the command :paste -raw , but for this you need to enter package com.package for each block; I am really looking for a stateful command to change the "current work package" if you do.

+5
source share
1 answer

Simply put, you cannot.

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

In addition, there was a ticket requesting package { } support in the REPL , but was rejected as :paste -raw was considered sufficient for the purpose.

+6
source

Source: https://habr.com/ru/post/1200484/


All Articles