This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Any way to reduce type info in REPL?

6 replies
Sophie
Joined: 2011-11-10,
User offline. Last seen 42 years 45 weeks ago.

Is there any option to change this REPL behavior:

scala> "abc"->3
res2: (java.lang.String, Int) = (abc,3)

to this:

scala> "abc"->3
res2 = (abc,3)

I can always use

:type res2

if I want more type info, and all that typing clutters my REPL a lot.

Thanks!

Sophie
Joined: 2011-11-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Any way to reduce type info in REPL?

Bump?

More dramatically:

val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")

capitals: scala.collection.immutable.Map[java.lang.String, java.lang.String]
= Map(France -> Paris, Japan -> Tokyo)

when all I would care to see 99% of the time is:
capitals = Map(France -> Paris, Japan -> Tokyo)

Any way to dial down that noise?

On 2011-12-05 10:23:46 -0600, Sophie said:

> Is there any option to change this REPL behavior:
>
> scala> "abc"->3
> res2: (java.lang.String, Int) = (abc,3)
>
> to this:
>
> scala> "abc"->3
> res2 = (abc,3)
>
> I can always use
>
> :type res2
>
> if I want more type info, and all that typing clutters my REPL a lot.
>
> Thanks!

d_m
Joined: 2010-11-11,
User offline. Last seen 35 weeks 2 days ago.
Re: Re: Any way to reduce type info in REPL?

On Wed, Dec 07, 2011 at 01:06:09PM -0600, Sophie wrote:
> when all I would care to see 99% of the time is:
> capitals = Map(France -> Paris, Japan -> Tokyo)
>
> Any way to dial down that noise?

Hey Sophie,

Seems like a nice feature... I bet Paul would accept a patch to the REPL
that allowed you to toggle this behavior somehow (either via a
command line flag, or some kind of :cmd in the REPL).

I do think that many people use the result output to determine how type
inference is working, so I don't know that people would want this to
become the default.

I would probably use this feature though.

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: Re: Any way to reduce type info in REPL?
You can do this already in power mode with a little work.  Given a method

def myprint[T](t: => T) = {
  val s = t.toString
  val name = s.takeWhile(_ != ':')
  val idx = s.indexOf(" = ")
  val full = if (idx >= 0) name + s.substring(idx) else s
  val short = if (full.length>799) full.substring(0,796)+"..." else full
  print(short)
  t
}

First
  :power
then
  :wrap myprint
then
  :silent
and you're all good.

  --Rex

On Wed, Dec 7, 2011 at 2:06 PM, Sophie <itsme213 [at] hotmail [dot] com> wrote:
Bump?

More dramatically:

val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")

capitals: scala.collection.immutable.Map[java.lang.String, java.lang.String]
 = Map(France -> Paris, Japan -> Tokyo)

when all I would care to see 99% of the time is:
capitals = Map(France -> Paris, Japan -> Tokyo)

Any way to dial down that noise?


On 2011-12-05 10:23:46 -0600, Sophie said:

Is there any option to change this REPL behavior:

scala> "abc"->3
res2: (java.lang.String, Int) = (abc,3)

to this:

scala> "abc"->3
res2 = (abc,3)

I can always use

:type res2

if I want more type info, and all that typing clutters my REPL a lot.

Thanks!




roland.kuhn
Joined: 2011-02-21,
User offline. Last seen 35 weeks 3 days ago.
Re: Re: Any way to reduce type info in REPL?
Good to know, thanks! If only so that I can say “please keep the current behavior by default because I’d like to see the types” ;-)

Regards,

Roland

Am Mittwoch, 7. Dezember 2011 20:25:49 UTC+1 schrieb Rex Kerr:
You can do this already in power mode with a little work.  Given a method

def myprint[T](t: => T) = {
  val s = t.toString
  val name = s.takeWhile(_ != ':')
  val idx = s.indexOf(" = ")
  val full = if (idx >= 0) name + s.substring(idx) else s
  val short = if (full.length>799) full.substring(0,796)+"..." else full
  print(short)
  t
}

First
  :power
then
  :wrap myprint
then
  :silent
and you're all good.

  --Rex

On Wed, Dec 7, 2011 at 2:06 PM, Sophie <itsm [dot] [dot] [dot] [at] hotmail [dot] com> wrote:
Bump?

More dramatically:

val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")

capitals: scala.collection.immutable.Map[java.lang.String, java.lang.String]
 = Map(France -> Paris, Japan -> Tokyo)

when all I would care to see 99% of the time is:
capitals = Map(France -> Paris, Japan -> Tokyo)

Any way to dial down that noise?


On 2011-12-05 10:23:46 -0600, Sophie said:

Is there any option to change this REPL behavior:

scala> "abc"->3
res2: (java.lang.String, Int) = (abc,3)

to this:

scala> "abc"->3
res2 = (abc,3)

I can always use

:type res2

if I want more type info, and all that typing clutters my REPL a lot.

Thanks!




Sophie
Joined: 2011-11-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Any way to reduce type info in REPL?

Thanks Rex, this helps a lot, though it does now sometimes injects a mysterious
$ires6=

Is there an initialization file that the REPL loads where I can put
this, like eclipse.ini, or .emacs, without needing a command-line flag?

(p.s. The REPL is a great boon for a newbie, but I think the REPL's
volume of type information, using needlessly fully qualified names,
could turn off said newbie, specially since :type is always available)

On 2011-12-07 15:13:40 -0600, rkuhn said:

> Good to know, thanks! If only so that I can say “please keep the
> current behavior by default because I’d like to see the types” ;-)
>
> Regards,
>
> Roland
>
> Am Mittwoch, 7. Dezember 2011 20:25:49 UTC+1 schrieb Rex Kerr:
> You can do this already in power mode with a little work.  Given a method
>
> def myprint[T](t: => T) = {
>   val s = t.toString
>   val name = s.takeWhile(_ != ':')
>   val idx = s.indexOf(" = ")
>   val full = if (idx >= 0) name + s.substring(idx) else s
>   val short = if (full.length>799) full.substring(0,796)+"..." else full
>   print(short)
>   t
> }
>
> First
>   :power
> then
>   :wrap myprint
> then
>   :silent
> and you're all good.
>
>   --Rex
>
> On Wed, Dec 7, 2011 at 2:06 PM, Sophie
> wrote:
> Bump?
>
> More dramatically:
>
> val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")
>
> capitals: scala.collection.immutable.Map[java.lang.String, java.lang.String]
>  = Map(France -> Paris, Japan -> Tokyo)
>
> when all I would care to see 99% of the time is:
> capitals = Map(France -> Paris, Japan -> Tokyo)
>
> Any way to dial down that noise?
>
>
>
> On 2011-12-05 10:23:46 -0600, Sophie said:
>
> Is there any option to change this REPL behavior:
>
> scala> "abc"->3
> res2: (java.lang.String, Int) = (abc,3)
>
> to this:
>
> scala> "abc"->3
> res2 = (abc,3)
>
> I can always use
>
> :type res2
>
> if I want more type info, and all that typing clutters my REPL a lot.
>
> Thanks!

Andreas Scheinert
Joined: 2011-02-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Any way to reduce type info in REPL?

I guess that's what they mean with: "with great :power there must also
come great responsibility" :)

Andreas

On 8 Dez., 19:45, Sophie wrote:
> Thanks Rex, this helps a lot, though it does now sometimes injects a mysterious
>         $ires6=
>
> Is there an initialization file that the REPL loads where I can put
> this, like eclipse.ini, or .emacs, without needing a command-line flag?
>
> (p.s. The REPL is a great boon for a newbie, but I think the REPL's
> volume of type information, using needlessly fully qualified names,
> could turn off said newbie, specially since :type is always available)
>
> On 2011-12-07 15:13:40 -0600, rkuhn said:
>
>
>
> > Good to know, thanks! If only so that I can say “please keep the
> > current behavior by default because I’d like to see the types” ;-)
>
> > Regards,
>
> > Roland
>
> > Am Mittwoch, 7. Dezember 2011 20:25:49 UTC+1 schrieb Rex Kerr:
> > You can do this already in power mode with a little work.  Given a method
>
> > def myprint[T](t: => T) = {
> >   val s = t.toString
> >   val name = s.takeWhile(_ != ':')
> >   val idx = s.indexOf(" = ")
> >   val full = if (idx >= 0) name + s.substring(idx) else s
> >   val short = if (full.length>799) full.substring(0,796)+"..." else full
> >   print(short)
> >   t
> > }
>
> > First
> >   :power
> > then
> >   :wrap myprint
> > then
> >   :silent
> > and you're all good.
>
> >   --Rex
>
> > On Wed, Dec 7, 2011 at 2:06 PM, Sophie
> > wrote:
> > Bump?
>
> > More dramatically:
>
> > val capitals = Map("France" -> "Paris", "Japan" -> "Tokyo")
>
> > capitals: scala.collection.immutable.Map[java.lang.String, java.lang.String]
> >  = Map(France -> Paris, Japan -> Tokyo)
>
> > when all I would care to see 99% of the time is:
> > capitals = Map(France -> Paris, Japan -> Tokyo)
>
> > Any way to dial down that noise?
>
> > On 2011-12-05 10:23:46 -0600, Sophie said:
>
> > Is there any option to change this REPL behavior:
>
> > scala> "abc"->3
> > res2: (java.lang.String, Int) = (abc,3)
>
> > to this:
>
> > scala> "abc"->3
> > res2 = (abc,3)
>
> > I can always use
>
> > :type res2
>
> > if I want more type info, and all that typing clutters my REPL a lot.
>
> > Thanks!

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland