scalaにもevalあるよぉ

まぁREPL限定*1 かつ 標準のライブラリではない*2ですが(´・ω・`)
ちなみに、実行したのは、version2.8.1です



追記:
2.9ではこのままでは動かないらしいですよ!*3twitterが作ってるEvalというライブラリがあるので、実用するならまだこっちのほうがいいかも
https://github.com/twitter/util/tree/master/util-eval google:twitter util Eval



以下、実行結果まるまる貼りつけ↓

scalaのREPLは、
:power
と打つと、普段使わない*4コンパイラまわりのAPIが使えるようになります。上の
:power
と打ったあとの表示結果にあるように、
scala.tools.nsc. 以下が名前空間に入り、また、

  • repl
  • global
  • power

という名前のオブジェクトが、存在するようになるみたいです

たとえば、globalというオブジェクトのメソッドがこんな感じ↓

scala> global.
Display all 322 possibilities? (y or n)
Alternative                                 Annotated
AnnotatedType                               AnnotationInfo
AntiPolyType                                AppliedTypeTree
Apply                                       ApplyDynamic
ApproximateDependentMap                     ArrayAnnotArg
ArrayValue                                  Assign
AssignOrNamedArg                            Bind
Block                                       BooleanTag
BoundedWildcardType                         ByteTag
CaseDef                                     CharTag
ClassDef                                    ClassInfoType
ClassTag                                    CompoundTypeTree
ConsoleWriter                               Constant
ConstantType                                CyclicInheritance
CyclicReference                             DefDef
DocComment                                  DocDef
DoubleTag                                   EmptyScope
EmptyTree                                   EmptyTreeTypeSubstituter
EnumTag                                     ErroneousCollector
ErrorType                                   ExistentialType
ExistentialTypeTree                         FloatTag
Function                                    GlbFailure
Ident                                       IdentityTypeMap
If                                          Import
ImportSelector                              IntTag
IsDependentCollector                        JavaMethodType
LabelDef                                    LazyAnnotationInfo
Literal                                     LiteralAnnotArg
LongTag                                     LubGlbMargin
Match                                       MaxPhases
MethodType                                  Modifiers
ModuleDef                                   NamedType
NestedAnnotArg                              New
NoMods                                      NoPeriod
NoPosition                                  NoPrefix
NoRunId                                     NoSymbol
NoTag                                       NoType
NotNullType                                 NullTag
OverloadedType                              PackageDef
Parens                                      PolyType
RefinedType                                 Return
ScalaSigBytes                               Select
SelectFromArray                             SelectFromTypeTree
ShortTag                                    SingleType
SingletonTypeTree                           Star
StringTag                                   StripAnnotationsMap
Super                                       SuperType
Template                                    This
ThisType                                    Throw
Try                                         TypeApply
TypeBounds                                  TypeBoundsTree
TypeDef                                     TypeRef
TypeTree                                    TypeTreeWithDeferredRefCheck
TypeVar                                     Typed
UnApply                                     UnitTag
UseCase                                     ValDef
WildcardType                                abort
activeLocks                                 activeLocks_=
adaptAnnotations                            adaptBoundsToAnnotations
adaptToNewRunMap                            addAnnotationChecker
addAnnotations                              addMember
annotationsConform                          annotationsGlb
annotationsLub                              appliedType
asCompactString                             asInstanceOf
asString                                    atPhase
atPos                                       baseTypeSingletonSeq
beginsWithTypeVarOrIsRefined                buildCompilerFromPhasesSet
canAdaptAnnotations                         catchWith
checkKindBounds0                            chrs
chrs_=                                      classPath
classfileAnnotArgManifest                   cloneSymbols
commonOwnerMap                              compactify
compare                                     compoundBaseTypeSeq
computePluginPhases                         containsContravariantExistentialCollector
containsCovariantExistentialCollector       cookedDocComment
copyMethodType                              copyRefinedType
createJavadoc                               currentPeriod
currentRun                                  currentRunId
deAlias                                     debugString
definitions                                 differentOrNone
docComment                                  docCommentPos
docComments                                 dropSingletonType
emptySymbolArray                            emptyValDef
encode                                      ensureNonOverlapping
error                                       existentialAbstraction
expandVariables                             expandWiki
expandedDocComment                          explainTypes
forJVM                                      forMSIL
getFile                                     getSourceFile
glb                                         globalPhase
globalPhase_=                               infoTransformers
infoTransformers_=                          inform
informProgress                              informTime
instTypeVar                                 instantiatedBounds
intersectionType                            intersectionWitness
isConstantType                              isDifferentType
isDifferentTypeConstructor                  isErrorOrWildcard
isHKSubType0                                isInstanceOf
isNumericSubType                            isPopulated
isRaw                                       isRawType
isSameType                                  isSameType2
isSameTypes                                 isScriptRun
isSingleType                                isSubArgs
isSubType                                   isSubTypes
isValid                                     isValidForBaseClasses
isWeakSubType                               isWithinBounds
kindsConform                                loadPlugins
loadRoughPluginsList                        loaders
log                                         logError
lookupVariable                              lub
lubDepth                                    map2Conserve
matchesType                                 maxTostringRecursions
merge                                       mergePrefixAndArgs
missingAliasException                       mkTermName
mkTypeName                                  nameChars
nameDebug                                   needsOuterTest
newCompactTreePrinter                       newScope
newStandardTreePrinter                      newTermName
newTreePrinter                              newTypeName
nme                                         nodeToString
normalizePlus                               notifyImport
numericGlb                                  numericLub
objToAny                                    onlyPresentation
period                                      phase
phaseDescriptions                           phaseDescriptors
phaseId                                     phaseNames
phaseOf                                     phaseWithId
phase_=                                     platform
pluginDescriptions                          pluginOptionsHelp
plugins                                     polyType
posAssigner                                 printAllUnits
printTypings                                printTypings_=
rangePos                                    rawDocComment
rawToExistential                            refinedType
registerContext                             registerTopLevelSym
removeAllAnnotationCheckers                 reporter
reporter_=                                  resetAllAttrs
resetLocalAttrs                             resetPos
rootLoader                                  roughPluginsList
runId                                       sanitize
settings                                    settings_=
shorthands                                  showDef
showOuterTests                              signalDone
singleType                                  singletonBounds
skolemizationLevel                          skolemizationLevel_=
sn                                          solve
spanningTypes                               specializesSym
startRun                                    superComment
symbolCount                                 toJavaDoc
toString                                    trackSetInfo
treeBrowser                                 treeCopy
treeInfo                                    treePrinter
treeWrapper                                 tryWith
typeParamsToExistentials                    typeRef
typeVarToOriginMap                          undetBaseTypeSeq
undoLog                                     uniqueTypeCount
useCases                                    validatePositions
verifyAndPrioritize                         view
warning                                     weakGlb
weakLub                                     wildcardToTypeVarMap
withTypesExplained                          wrappingPos

replのメソッド↓

ComputedImports$module                               DBG
InterpreterEvalException                             InterpreterEvalException$module
ReqAndHandler$1                                      addWrapper$1
aliasForType                                         allBoundNames
allImplicits                                         allSeenTypes
allUsedNames                                         allValueGeneratingNames
asInstanceOf                                         beQuietDuring
bind                                                 bitmap$0
classLoader                                          clazzForIdent
close                                                compileAndSaveRun
compileSources                                       compileString
compiler                                             compilerClasspath
completionAware                                      completionAwareImplicit
equals                                               eval
evalError                                            evalExpr
extractionValueForIdent                              getClass
getClassObject                                       getInterpreterClassLoader
getSynthVarName                                      getVarName
hashCode                                             implicitFor
indentCode                                           indentString
initialize                                           interpret
interpretExpr                                        isCompletionDebug
isInstanceOf                                         isReplDebug
isettings                                            manifestFor
methodsOf                                            mostRecentVar
name2string                                          newCompiler
notify                                               notifyAll
parentClassLoader                                    power
power$module                                         printAllTypeOf
printResults                                         printResults_=
println                                              quietBind
recordRequest                                        reporter
reporter$module                                      reset
resetClassLoader                                     scala$tools$nsc$Interpreter$$ComputedImports
scala$tools$nsc$Interpreter$$_initialize             scala$tools$nsc$Interpreter$$asCompletionAwareCode
scala$tools$nsc$Interpreter$$bindLastException       scala$tools$nsc$Interpreter$$bindLastException_=
scala$tools$nsc$Interpreter$$boundNameMap            scala$tools$nsc$Interpreter$$chooseHandler
scala$tools$nsc$Interpreter$$clean                   scala$tools$nsc$Interpreter$$getOriginalName
scala$tools$nsc$Interpreter$$importsCode             scala$tools$nsc$Interpreter$$isGeneratedVarName
scala$tools$nsc$Interpreter$$isSynthVarName          scala$tools$nsc$Interpreter$$loadByName
scala$tools$nsc$Interpreter$$out                     scala$tools$nsc$Interpreter$$parse
scala$tools$nsc$Interpreter$$prevRequests            scala$tools$nsc$Interpreter$$spaces
scala$tools$nsc$Interpreter$$synthVarNameCreator     scala$tools$nsc$Interpreter$$usedNameMap
setContextClassLoader                                settings
stringToCompilerType                                 toString
typeForIdent                                         unleash
unqualifiedIds                                       virtualDirectory
wait                                                 wildcardImportedTypes
withoutBindingLastException

compileSourcesとか、classLoaderとか言う名前のメソッドがあって、面白そうですね(・∀・)
おそらく、scalaの言語自体の開発者向けとか、コンパイラプラグイン作成者のためにある機能なんですかね?

追記

やっぱりpowerモードは予想どうりコンパイラプラグインとか作る人向けっぽ
foursquareで働いてるらしい、scala-timeの作者の人のtweet ↓

Scala Protip: When writing a compiler plugin, the REPL's :power mode is your friend. This shit is like dark magic... (Thanks @extempore2!)less than a minute ago via Twitter for Mac

dark magic・・・(・ω・*) scalaちゃんは黒魔法 power を唱えた的な・・・

*1:なんか頑張ればできるかもしれませんが、詳しくは知りません

*2:scaladocもろくにないし、version変わったら変わるかも。あくまで、コンパイラ側で使う物っていう位置づけ

*3:頑張れば、コンパイラなので同じような仕組み、やり方は見つかるはずですが・・・

*4:というか非公式だからあまり使わないほうがいい?