Search code examples
rscalaread-eval-print-loop

Scala REPL equivalent for R ls( ) function


Is there any command in Scala REPL that will print out the objects already defined? For example, in R console, the function ls() prints all the defined objects in the current environment.


Solution

  • There is no simple function as ls() in R for Scala. But one can do similar things in the following way:

    val ls = $intp
    ls.allDefinedNames.foreach(println)
    

    ls.+tab will give the following options:

    scala> ls.
    SparkComputedImports        addImports                  addUrlsToClassPath          allDefinedNames             allImportedNames            asInstanceOf                
    beQuietDuring               beSilentDuring              bind                        classOfTerm                 classServerUri              classSymbols                
    clearExecutionWrapper       close                       compileSources              compileString               definedSymbolList           definedSymbols              
    definedTerms                definedTypes                definitionForName           directBind                  executionWrapper            fallback                    
    generatedName               getClassOutputDirectory     global                      implicitSymbols             implicitSymbolsBySource     importedSymbols             
    importedSymbolsBySource     importedTermNamed           importedTermSymbols         importedTerms               importedTypeSymbols         importedTypes               
    initializeSynchronous       interpret                   interpretSynthetic          isInstanceOf                isNoImports                 isNoPredef                  
    isReportingErrors           languageSymbols             languageWildcardHandlers    languageWildcardSyms        languageWildcards           lastWarnings                
    methodSymbols               mostRecentVar               namedDefinedTerms           out                         parse                       pathToName                  
    rebind                      requestForIdent             requestForName              requestForReqId             requestHistoryForName       reset                       
    runtimeClassAndTypeOfTerm   runtimeTypeOfTerm           sessionImportedSymbols      sessionWildcards            setExecutionWrapper         symbolOfLine                
    symbolOfTerm                toString                    treesForRequestId           typeOfExpression            typeOfTerm                  valueOfTerm                 
    visibleTermNames            wildcardTypes