read-eval-print-loop

What really happens behind the Scala runtime/REPL when running a '.scala' program?

杀马特。学长 韩版系。学妹 提交于 2020-01-01 04:03:27
问题 When I run something like the following from the command line, what really happens? > scala hello.scala Is there a hello.class generated, executed, and then discarded? Or does Scala behave somehow like an interpreter in this case? I am just thinking that, of course, I cannot do the same for Java: > java hello.java 回答1: Yes, there is a hello.class generated. The compiler will wrap your code inside a Main object, compile it then execute Main.main , given hello.scala of println(args.mkString)

What really happens behind the Scala runtime/REPL when running a '.scala' program?

北慕城南 提交于 2020-01-01 04:03:08
问题 When I run something like the following from the command line, what really happens? > scala hello.scala Is there a hello.class generated, executed, and then discarded? Or does Scala behave somehow like an interpreter in this case? I am just thinking that, of course, I cannot do the same for Java: > java hello.java 回答1: Yes, there is a hello.class generated. The compiler will wrap your code inside a Main object, compile it then execute Main.main , given hello.scala of println(args.mkString)

is there a way to check if a bash script is complete or not?

喜你入骨 提交于 2020-01-01 03:58:08
问题 I'm trying to implement a REPL (read-eval-print loop) in bash. If such a thing already exists, please ignore the following and answer this question with a pointer to it. Let's use this script as an example (name it test.sh ): if true then echo a else echo b fi echo c What I want to do is to read this script line by line, check if what I have read so far is a complete bash expression; if it is complete, eval it; otherwise keep on reading the next line. The script below illustrates my idea

How to import package into Scala REPL?

六月ゝ 毕业季﹏ 提交于 2019-12-31 03:06:14
问题 How do I import a package into Scala's REPL? I am trying to import this package called funsets which has an object named "FunSets". I tried several variations of import funsets._ and import funsets._; etc but it is still not importing the functions and object in the package. 回答1: One way is to compile the "scala classes" and put those in classpath. Example, 1) Say you have a class funsets.FunSets.scala package funsets object FunSets { def fun = "very fun" } 2) Compile the class first using

Is it reasonable to use Scala's REPL for comparative performance benchmarks?

你。 提交于 2019-12-31 00:50:34
问题 Scala's REPL is a wonderful playground to interactively test certain pieces of code. Recently, I've been doing some performance comparisons using the REPL to repeatedly execute an operations and comparatively measure wall clock times. Here's such an example I recently created to help answering an SO question [1][2]: // Figure out the perfomance difference between direct method invocation and reflection-based method.invoke def invoke1[T,U](obj:Any, method:Method)(param:T):U = method.invoke(obj

Changing a program while it is running

寵の児 提交于 2019-12-30 12:25:13
问题 Not sure if this is an emacs-SLIME issue or a CL issue or SBCL issue. I've heard it said that the interactive nature of Lisp allows for changing a program while the program is running. Not knowing the specifics of what is meant by this, I tried the following, placing this in a separate file: (defparameter repl-test-var 5) (defun repl-test () (format t "repl-test-var is: ~a" repl-test-var) (fresh-line) (when (not (equal (read-line) "quit")) (repl-test))) Then I compile and run (repl-test) and

Changing a program while it is running

北慕城南 提交于 2019-12-30 12:24:03
问题 Not sure if this is an emacs-SLIME issue or a CL issue or SBCL issue. I've heard it said that the interactive nature of Lisp allows for changing a program while the program is running. Not knowing the specifics of what is meant by this, I tried the following, placing this in a separate file: (defparameter repl-test-var 5) (defun repl-test () (format t "repl-test-var is: ~a" repl-test-var) (fresh-line) (when (not (equal (read-line) "quit")) (repl-test))) Then I compile and run (repl-test) and

How to configure IPython to execute cell blocks the same way as a plain Python REPL does?

谁说胖子不能爱 提交于 2019-12-30 10:01:27
问题 Vanilla Python REPL: >>> 'na' 'na' >>> for i in range(4): ... f'{_+_}' ... else: ... 'batman' ... 'nana' 'nananana' 'nananananananana' 'nananananananananananananananana' 'batman' >>> IPython REPL with same interpreter: >>> 'na' 'na' >>> for i in range(4): ... f'{_+_}' ... else: ... 'batman' ... >>> _ 'na' This difference is apparently related to the mode in which IPython compiles code, and unrelated to the display hook. Is it possible to configure IPython to compile/exec cell blocks as a

REPL for interpreter using Flex/Bison

断了今生、忘了曾经 提交于 2019-12-30 03:11:46
问题 I've written an interpreter for a C-like language, using Flex and Bison for the scanner/parser. It's working fine when executing full program files. Now I'm trying implement a REPL in the interpreter for interactive use. I want it to work like the command line interpreters in Ruby or ML: Show a prompt Accept one or more statements on the line If the expression is incomplete display a continuation prompt allow the user to continue entering lines When the line ends with a complete expression

In the Node.js REPL, why does this happen?

戏子无情 提交于 2019-12-29 07:42:15
问题 So I was playing around with the Node.js REPL and the Underscore library when I noticed something very strange. If I require("underscore") , the variable _ is set globally (obviously). Then when I attempt to run a simple command like console.log(_.isEmpty) it prints [Function] (again, obviously). However, upon running console.log(_) right after, it prints [Function] because the variable _ was set to _.isEmpty . Why does this do this? If I run the same code from a js file this doesn't happen.