- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Any way to reduce type info in REPL?
Mon, 2011-12-05, 17:24
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!
Wed, 2011-12-07, 20:21
#2
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.
Wed, 2011-12-07, 20:41
#3
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:
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!
Wed, 2011-12-07, 22:21
#4
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:
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!
Thu, 2011-12-08, 19:51
#5
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!
Fri, 2011-12-09, 09:11
#6
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!
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!