Is there a way to run CoffeeScript natively in a terminal?

Since we can run JavaScript using various interpreters, such as V8 or Rhino, I thought that there should be a way to run CoffeeScript code inside the terminal.

Technically, I can do this using Node.js while javascript is running, but I'm curious if there is a separate interpreter specifically designed for CoffeeScript.

+4
source share
6 answers

No. You can run the coffeescript file with coffee filename , but it just compiles the coffeescript file in RAM and runs it as javascript. Well, actually someone wrote an interpreter for coffeescript, but this interpreter is written in javascript or coffeescript or so, and therefore should work inside the JS engine. It is also slow as hell because it is an interpreter and not a JIT compiler.

As I said, just use the coffee command.

+5
source

What happened to the simple installation and launch of the interpreter that comes with CoffeeScript itself?

Read the manual part here: http://jashkenas.github.com/coffee-script/#installation

And then use it like this:

enter image description here

Or am I missing some dimension of your question?

+9
source

There is, as far as I know, only one CoffeeScript interpreter that does not compile it into JavaScript: Poetics .

It is written in pure Ruby and runs CoffeeScript code directly on the Rubinius VM. However, it has not been updated since May, and it does not coincide with the official implementation of CoffeeScript.

+4
source

If you do not want to run the script using the coffee command, you can always add a hash band at the beginning of the script:

 #!/usr/local/bin/coffee 

While the file is installed in the executable file ( chmod +x foo.coffee ), now you can run it without specifying the coffee command in your terminal:

 $ ./foo.coffee 
+2
source

You cannot use coffee as a script interpreter directly, because it already has a script. But you can fix this by writing a simple C shell:

 #include <unistd.h> int main(int argc, char *argv[]) { execvp("coffee", argv); } 

Compile this and put it in your PATH somewhere (I called it klatsh ) and then put #!/usr/bin/env klatsh (or whatever you called it) at the top of your scripts, and you're good to go.

+2
source

Yes, just use:

 $ coffee test.coffee Output from coffee! 
+1
source

Source: https://habr.com/ru/post/1382932/


All Articles