Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Created June 3, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethTisue/1006801 to your computer and use it in GitHub Desktop.
Save SethTisue/1006801 to your computer and use it in GitHub Desktop.
Last login: Fri Jun 3 10:17:44 on ttys003
~ % scala29
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :q
scala29 -Dr
~ % scala29 -Dscala.repl.power=true (master⚡)
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
Starting in power mode, one moment...
** Power User mode enabled - BEEP BOOP WHIR **
** scala.tools.nsc._ has been imported **
** global._ and definitions._ also imported **
** New vals! Try repl, intp, global, power **
** New cmds! :help to discover them **
** New defs! Type power.<tab> to reveal **
scala> def f = None.members.map(_.defString)
f: List[String]
scala> f
res0: List[String] = List(def get(): java.lang.Object, def readResolve(): java.lang.Object, def canEqual(x$1: java.lang.Object): Boolean, def productElement(x$1: Int): java.lang.Object, def productArity(): Int, def productPrefix(): java.lang.String, final def toString(): java.lang.String, def get(): scala.runtime.Nothing$, def isEmpty(): Boolean, def toLeft(right: Function0): Either, def toRight(left: Function0): Either, def toList(): List, def iterator(): Iterator, def orElse(alternative: Function0): Option, def collect(pf: PartialFunction): Option, def foreach(f: Function1): Unit, def exists(p: Function1): Boolean, def withFilter(p: Function1): Option$WithFilter, def filterNot(p: Function1): Option, def filter(p: Function1): Option, def flatMap(f: Funct
ion1): Option, def map(f: Functi...
scala> :phase next
'next' does not appear to represent a valid phase.
scala> :phase typer.next
Active phase is now: Superaccessors (typer.next)
scala> f
res1: List[String] = List(def get(): java.lang.Object, def readResolve(): java.lang.Object, def canEqual(x$1: Any): Boolean, def productElement(x$1: Int): java.lang.Object, def productArity(): Int, def productPrefix(): java.lang.String, final def toString(): java.lang.String, def get(): scala.runtime.Nothing$, def isEmpty(): Boolean, def toLeft[X](right: => X): Product with Either[A,X] with Serializable, def toRight[X](left: => X): Product with Either[X,A] with Serializable, def toList: List[A], def iterator: Iterator[A], def orElse[B >: A](alternative: => Option[B]): Option[B], def collect[B](pf: PartialFunction[A,B]): Option[B], def foreach[U](f: (A) => U): Unit, def exists(p: (A) => Boolean): Boolean, class WithFilter extends java.lang.Object with Scal
aObject{private val p: <?>; def ...
scala> f.head
res2: String = def get(): java.lang.Object
scala> :phase uncurry.next
Active phase is now: Tailcalls (uncurry.next)
scala> f.take(3)
res3: List[String] = List(def get(): java.lang.Object, def readResolve(): java.lang.Object, def canEqual(x$1: Any): Boolean)
scala> f.take(3).foreach(println)
def get(): java.lang.Object
def readResolve(): java.lang.Object
def canEqual(x$1: Any): Boolean
scala> f.take(3).filter(_.containsSlice("getOrElse")).foreach(println)
scala> f.filter(_.containsSlice("getOrElse")).foreach(println)
def getOrElse[B >: A](default: () => B): B
scala> :phase erasure.next
Active phase is now: Lazyvals (erasure.next)
scala> f.filter(_.containsSlice("getOrElse")).foreach(println)
def getOrElse(default: Function0): java.lang.Object
scala> :phase terminal
Active phase is now: Terminal
scala> f.filter(_.containsSlice("getOrElse")).foreach(println)
def getOrElse(default: Function0): java.lang.Object
scala> :phase parser
Active phase is now: Parser
scala> f.filter(_.containsSlice("getOrElse")).foreach(println)
def getOrElse[B >: A](default: => B): B
scala> val x = ?[List[_]]
<console>:21: error: not found: value ?
val x = ?[List[_]]
^
scala> power.InternalInfo[List[_]]
res10: power.InternalInfo[List[_]] = scala.collection.immutable.List
scala> x
<console>:22: error: not found: value x
x
^
scala> res10
res12: power.InternalInfo[List[_]] = scala.collection.immutable.List
scala> :implicits
/* 23 implicit members imported from scala.collection.JavaConverters */
/* 23 defined in scala.collection.JavaConverters */
implicit def asJavaConcurrentMapConverter[A,B](m: mutable.ConcurrentMap[A,B]): AsJava[java.util.concurrent.ConcurrentMap[A,B]]
implicit def asJavaIterableConverter[A](i: Iterable[A]): AsJava[jl.Iterable[A]]
implicit def asJavaIteratorConverter[A](i: Iterator[A]): AsJava[java.util.Iterator[A]]
implicit def bufferAsJavaListConverter[A](b: mutable.Buffer[A]): AsJava[java.util.List[A]]
implicit def mapAsJavaMapConverter[A,B](m: scala.collection.Map[A,B]): AsJava[java.util.Map[A,B]]
implicit def mutableMapAsJavaMapConverter[A,B](m: mutable.Map[A,B]): AsJava[java.util.Map[A,B]]
implicit def mutableSeqAsJavaListConverter[A](b: mutable.Seq[A]): AsJava[java.util.List[A]]
implicit def mutableSetAsJavaSetConverter[A](s: mutable.Set[A]): AsJava[java.util.Set[A]]
implicit def seqAsJavaListConverter[A](b: Seq[A]): AsJava[java.util.List[A]]
implicit def setAsJavaSetConverter[A](s: scala.collection.Set[A]): AsJava[java.util.Set[A]]
implicit def asScalaBufferConverter[A](l: java.util.List[A]): AsScala[mutable.Buffer[A]]
implicit def asScalaConcurrentMapConverter[A,B](m: java.util.concurrent.ConcurrentMap[A,B]): AsScala[mutable.ConcurrentMap[A,B]]
implicit def asScalaIteratorConverter[A](i: java.util.Iterator[A]): AsScala[Iterator[A]]
implicit def asScalaSetConverter[A](s: java.util.Set[A]): AsScala[mutable.Set[A]]
implicit def collectionAsScalaIterableConverter[A](i: java.util.Collection[A]): AsScala[Iterable[A]]
implicit def dictionaryAsScalaMapConverter[A,B](p: java.util.Dictionary[A,B]): AsScala[mutable.Map[A,B]]
implicit def enumerationAsScalaIteratorConverter[A](i: java.util.Enumeration[A]): AsScala[Iterator[A]]
implicit def iterableAsScalaIterableConverter[A](i: jl.Iterable[A]): AsScala[Iterable[A]]
implicit def mapAsScalaMapConverter[A,B](m: java.util.Map[A,B]): AsScala[mutable.Map[A,B]]
implicit def propertiesAsScalaMapConverter(p: java.util.Properties): AsScala[mutable.Map[String,String]]
implicit def asJavaCollectionConverter[A](i: Iterable[A]): AsJavaCollection[A]
implicit def asJavaDictionaryConverter[A,B](m: mutable.Map[A,B]): AsJavaDictionary[A,B]
implicit def asJavaEnumerationConverter[A](i: Iterator[A]): AsJavaEnumeration[A]
/* 3 implicit members imported from scala.tools.nsc.Global */
/* 1 inherited from scala.tools.nsc.ast.Trees */
implicit def treeWrapper(tree: Tree): TreeOps
/* 1 inherited from scala.reflect.generic.StdNames */
implicit def stringToTermName(s: String): TermName
/* 1 inherited from scala.reflect.generic.Names */
implicit def promoteTermNamesAsNecessary(name: Name): TermName
/* 14 implicit members imported from scala.tools.nsc.interpreter.Power$Implicits */
/* 9 inherited from scala.tools.nsc.interpreter.Power$Implicits2 */
implicit lazy val powerNameOrdering: Ordering[Implicits2.this.Name]
implicit lazy val powerSymbolOrdering: Ordering[Implicits2.this.Symbol]
implicit lazy val powerTypeOrdering: Ordering[Implicits2.this.Type]
implicit def replCollPrinting[T](xs: TraversableOnce[T])(implicit evidence$8: Power.this.Prettifier[T]): Power.this.MultiPrintingConvenience[T]
implicit def replInputStream(in: scala.tools.nsc.interpreter.package.InputStream)(implicit codec: scala.io.Codec): Power.this.RichInputStream
implicit def replInputStreamURL(url: java.net.URL)(implicit codec: scala.io.Codec): Power.this.RichInputStream
implicit def replInternalInfo[T](x: T)(implicit evidence$9: Manifest[T]): Power.this.InternalInfo[T]
implicit def replPrettifier[T]: Power.this.Prettifier[T]
implicit def replTypeApplication(sym: Implicits2.this.Symbol): Implicits2.this.RichSymbol
/* 4 inherited from scala.tools.nsc.interpreter.SharesGlobal */
implicit def upDependentName(x: AnyName): Name
implicit def upDependentSymbol(x: AnySymbol): Symbol
implicit def upDependentTree(x: AnyTree): Tree
implicit def upDependentType(x: AnyType): Type
/* 1 inherited from scala.tools.nsc.interpreter.Power$Implicits1 */
implicit def replPrinting[T](x: T)(implicit pretty: Power.this.Prettifier[T]): Power.this.PrintingConvenience[T]
scala> :imports
1) import java.lang._ (152 types, 157 terms)
2) import scala._ (797 types, 812 terms)
3) import scala.Predef._ (16 types, 167 terms, 96 are implicit)
4) import scala.tools.nsc._ (289 types, 305 terms)
5) import scala.collection.JavaConverters._ (5 types, 58 terms, 23 are implicit)
6) import global.{error=>_, _} (218 types, 474 terms, 3 are implicit)
7) import power.Implicits._ (41 terms, 14 are implicit)
scala> power.InternalInfo[scala.collection.immutable.Stream[_]]
res13: power.InternalInfo[scala.collection.immutable.Stream[_]] = scala.collection.immutable.Stream
scala> res13.types
res14: List[power.global.Symbol] = List(class StreamWithFilter, class CombinationsItr, class PermutationsItr, class WithFilter, type Self)
scala> res13.types.foreach(println
| )
class StreamWithFilter
class CombinationsItr
class PermutationsItr
class WithFilter
type Self
scala> scala.util.NameTransformer.encode("==")
<console>:22: error: object NameTransformer is not a member of package util
scala.util.NameTransformer.encode("==")
^
scala> scala.reflect.NameTransformer.encode("==")
res17: String = $eq$eq
scala>
scala> scala.reflect.NameTransformer.decode(res17)
res18: String = ==
scala> power.trees("class Bippy { def = 5 }").head
<console>:1: error: identifier expected but '=' found.
class Bippy { def = 5 }
^
java.util.NoSuchElementException: head of empty list
at scala.collection.immutable.Nil$.head(List.scala:371)
at scala.collection.immutable.Nil$.head(List.scala:368)
at .<init>(<console>:22)
at .<clinit>(<console>)
at $anonfun$1.apply(<console>:11)
at $anonfun$1.apply(<console>:10)
at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:96)
at scala.tools.nsc.interpreter.Phased$class.atCurrent(Phased.scala:72)
at scala.tools.nsc.interpreter.Power$$anon$3.atCurrent(Power.scala:351)
at .<init>(<console>:10)
at .<clinit>(<console>)
at $export(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:592)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$10.apply(IMain.scala:828)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:31)
at java.lang.Thread.run(Thread.java:680)
scala> val t = power.trees("class Bippy { def = 5 }").head
<console>:1: error: identifier expected but '=' found.
class Bippy { def = 5 }
^
java.util.NoSuchElementException: head of empty list
at scala.collection.immutable.Nil$.head(List.scala:371)
at scala.collection.immutable.Nil$.head(List.scala:368)
at .<init>(<console>:21)
at .<clinit>(<console>)
at $anonfun$1.apply(<console>:11)
at $anonfun$1.apply(<console>:10)
at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:96)
at scala.tools.nsc.interpreter.Phased$class.atCurrent(Phased.scala:72)
at scala.tools.nsc.interpreter.Power$$anon$3.atCurrent(Power.scala:351)
at .<init>(<console>:10)
at .<clinit>(<console>)
at $export(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:592)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$10.apply(IMain.scala:828)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:31)
at java.lang.Thread.run(Thread.java:680)
scala> val t = power.trees("class Bippy { def = 5 }")
<console>:1: error: identifier expected but '=' found.
class Bippy { def = 5 }
^
t: List[power.intp.global.Tree] = List()
scala> val t = power.trees("class Bippy { def x = 5 }")
t: List[power.intp.global.Tree] =
List(class Bippy extends scala.ScalaObject {
def <init>() = {
super.<init>();
()
};
def x = 5
})
scala> "the symbolic stuff is actually in the latest new builds?"
res20: java.lang.String = the symbolic stuff is actually in the latest new builds?
scala> class Foo { def x = 5 }
defined class Foo
scala> :javap -v Foo
Compiled from "<console>"
public class Foo extends java.lang.Object implements scala.ScalaObject
SourceFile: "<console>"
Scala: length = 0x
InnerClass:
public #19= #16 of #18; //Foo=class Foo of class
minor version: 0
major version: 49
Constant pool:
const #1 = Asciz SourceFile;
const #2 = Asciz <console>;
const #3 = Asciz x;
const #4 = Asciz ()I;
const #5 = Asciz Code;
const #6 = Asciz LineNumberTable;
const #7 = Asciz <init>;
const #8 = Asciz ()V;
const #9 = Asciz java/lang/Object;
const #10 = class #9; // java/lang/Object
const #11 = NameAndType #7:#8;// "<init>":()V
const #12 = Method #10.#11; // java/lang/Object."<init>":()V
const #13 = Asciz Scala;
const #14 = Asciz InnerClasses;
const #15 = Asciz Foo;
const #16 = class #15; // Foo
const #17 = Asciz ;
const #18 = class #17; //
const #19 = Asciz Foo;
const #20 = Asciz scala/ScalaObject;
const #21 = class #20; // scala/ScalaObject
{
public int x();
Code:
Stack=1, Locals=1, Args_size=1
0: iconst_5
1: ireturn
LineNumberTable:
line 21: 0
public Foo();
Code:
Stack=1, Locals=1, Args_size=1
0: aload_0
1: invokespecial #12; //Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 21: 0
}
scala> :wrap clear
Cleared execution wrapper.
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment