Pergunta

I read from this source that I am able to run the interactive environment using coffee -r ./prelude on my console. However, it is not working on my Linux Mint 15.

Yes, CoffeeScript is installed. I can enter a form of interactive mode by simply typing coffee on my console (albeit only one-liner expressions).

I received the following error and apparently option -r is not recognized.

/usr/lib/node_modules/coffee-script/lib/coffee-script/optparse.js:51
        throw new Error("unrecognized option: " + arg);
              ^
Error: unrecognized option: -r
    at OptionParser.exports.OptionParser.OptionParser.parse (/usr/lib/node_modules/coffee-script/lib/coffee-script/optparse.js:51:19)
    at parseOptions (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:464:29)
    at Object.exports.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:55:5)
    at Object.<anonymous> (/usr/lib/node_modules/coffee-script/bin/coffee:7:41)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Does coffee -r ./prelude give me another kind of interactive mode (multi-line expressions perhaps)? Is it possible that this is an OS problem?

Foi útil?

Solução

At first coffee -r / coffee --run was used to run scripts.

It got deprecated from 0.5.3 (issue / commit).


Then coffee -r / coffee --require was used to require modules.

It was removed since 1.5.0 (commit / issue).

@jashkenas said about that:

--require was originally for when we were encouraging folks to "extend" (read, monkey-patch) the compiler's inner classes to their own ends. It doesn't really work very well, so we removed it. Instead, you can just require() within your files as usual, if you're running them directly with coffee. If you're not running them directly with coffee, then it shouldn't matter.

As for now, Coffescript version is 1.6.3, This book was written when it was only 1.2.0.


I can recommend these online books:

Outras dicas

The `prelude/prelude.coffee' file starts with:

# Usage: require './prelude' or on commandline: coffee -r ./prelude
# This prelude is a learning environment for 'Smooth CoffeeScript'.

Evidently the -r option meant require. Whether that was a commandline option at an earlier time (smooth is several years old), or is part of a custom coffee, I don't know. In any case it isn't an option for the current coffee. Use coffee -h to see current usage.

So what you need to do is enter interactive coffee with coffee, and then require <the prelude.coffee location>. prelude does some tricks, and actually puts its functions in the global namespace. With it it will be easier to follow the examples in the book, but it shouldn't been used as a regular part of your coffee setup.

show the most common utility function that prelude defines. In many cases you can use console.log instead of it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top