read-eval-print-loop

Why Scala REPL shows tuple type for Map expression?

一曲冷凌霜 提交于 2019-12-11 05:34:31
问题 Scala REPL gives the same type for both expressions - (tuple? -- strange!). Yet ("a" ->1) which is a Map I can add to map and ("a", 1) can not. Why Scala REPL shows tuple type type for Map expression? scala> :t ("a" -> 1) (String, Int) scala> :t ("a",1) (String, Int) scala> val m = Map.empty[String, Int] m: scala.collection.immutable.Map[String,Int] = Map() scala> m + ("a",1) <console>:9: error: type mismatch; found : String("a") required: (String, ?) m + ("a",1) ^ scala> m + ("a" ->1) res19:

Mapping over HList raises AbstractMethodError

旧时模样 提交于 2019-12-11 04:38:26
问题 I am trying a shapeless example in REPL and getting a runtime error: scala> import shapeless._ import shapeless._ scala> import shapeless.poly._ import shapeless.poly._ scala> object choose extends (Set ~> Option) { | def apply[T](set: Set[T]) = set.headOption | } defined object choose scala> val sets = Set(1) :: Set(0) :: HNil sets: shapeless.::[scala.collection.immutable.Set[Int],shapeless.::[scala.collection.immutable.Set[Int],shapeless.HNil]] = Set(1) :: Set(0) :: HNil scala> sets map

No-argument constructor in Spark Shell / Scala REPL

我是研究僧i 提交于 2019-12-11 03:35:33
问题 In spark-shell (which uses scala-repl), it seems impossible to make a (case) class which has the default constructor (i.e. no-argument constructor): scala> case class Hello(i: Int) { | def this() = this(0) | } defined class Hello scala> classOf[Hello].getName res1: String = Hello scala> classOf[Hello].getConstructors() res2: Array[java.lang.reflect.Constructor[_]] = Array(public Hello($iw), public Hello($iw,int)) This makes Jackson fail to deserialize something into this class, because there

Methods containing bang doesn't work in REPL

岁酱吖の 提交于 2019-12-11 01:19:50
问题 I am running Scala 2.9.2 REPL and if I copy&paste following method: def isPrime(num: Int): Boolean = { val ceiling = math.sqrt(num.toDouble).toInt (2 to ceiling) forall (x => num % x != 0) } ..from the file with a source code (where it works well) to the Interactive Interpreter. I get this exception: java.lang.IllegalArgumentException: != 0): event not found at jline.console.ConsoleReader.expandEvents(ConsoleReader.java:426) ... The problem is the ! character (methods without exclamation mark

Why does deleting a global variable named __builtins__ prevent only the REPL from accessing builtins?

左心房为你撑大大i 提交于 2019-12-11 01:17:32
问题 I have a python script with the following contents: # foo.py __builtins__ = 3 del __builtins__ print(int) # <- this still works Curiously, executing this script with the -i flag prevents only the REPL from accessing builtins: aran-fey@starlight ~> python3 -i foo.py <class 'int'> >>> print(int) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'print' is not defined How come the script can access builtins, but the REPL can't? 回答1: CPython doesn't look up _

Ruby, pry: Can I add something to the command `pry example.rb` so pry automatically goes interactive when it finishes executing the script?

混江龙づ霸主 提交于 2019-12-11 00:47:45
问题 Pry goes into interactive mode if it encounters an exception (eg if you just put an undefined variable 'x' at the end of the script). (Also if, inside the script itself you require 'pry' and put binding.pry at the point you want to go interactive at.) But I'm wondering: Is there's some kind of flag/option/argument thingy that I can add to the pry example.rb command when I enter it at the command prompt, so it will go interactive when it reaches the end of executing any example.rb script,

Type mismatch with identical types in Spark-shell

Deadly 提交于 2019-12-10 21:23:52
问题 I have build a scripting workflow around the spark-shell but I'm often vexed by bizarre type mismatches (probably inherited from the scala repl) occuring with identical found and required types. The following example illustrates the problem. Executed in paste mode, no problem scala> :paste // Entering paste mode (ctrl-D to finish) import org.apache.spark.rdd.RDD case class C(S:String) def f(r:RDD[C]): String = "hello" val in = sc.parallelize(List(C("hi"))) f(in) // Exiting paste mode, now

Node JS REPL, Sockets, and Telnet - Tab Completion, Arrow Keys, etc

会有一股神秘感。 提交于 2019-12-10 20:24:31
问题 I have been playing around with Node's REPL. I thought it would be pretty cool to make it available via a Socket, connect to it via Telnet/puTTY/whatever, and debug my server on-the-fly. I used the example found here: http://nodejs.org/docs/latest/api/repl.html, which basically looks like this... net.createServer(function (socket) { var cmd = repl.start(">", socket); //... some other stuff here.... not important }).listen(5001); OK, great! Now I can connect to port 5001 with Telnet and

How to add imports to REPL from command line?

梦想与她 提交于 2019-12-10 19:38:25
问题 How can I make REPL to import packages given in commnad line? Sample: scala -someMagicHere "import sys.error" scala> :imports 1) import scala.Predef._ (162 terms, 78 are implicit) 2) import sys.error (2 terms) scala> _ PS: It is not a duplicate. I want automated solution, not manually pasting some code every time I run REPL. Also I don't want to use SBT just for running one command in REPL after its start. 回答1: Stick it in a file. apm@mara:~/tmp$ scala -i imports.script Loading imports.script

taskhandler that executes *before* the expr

╄→гoц情女王★ 提交于 2019-12-10 18:59:59
问题 Is there a callback for running code before a prompt-entered expr is evaluated? (A search through SO, CRAN, and some googling has turned up what I suspect the answer to be: not possible with the current REPL implementation. My apologies if I missed a similarly-detailed duplicate discussion.) I'm loosely familiar with addTaskCallback() and its family of functions. Reading the help and developer docs tells me that the mechanism only runs after an expression is evaluated. One eventual