Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loop() not implemented? #16

Closed
skilfullycurled opened this issue May 22, 2013 · 8 comments
Closed

loop() not implemented? #16

skilfullycurled opened this issue May 22, 2013 · 8 comments
Labels

Comments

@skilfullycurled
Copy link

I was creating a simple on/off switch for a sketch using keyPressed() as I often do when debugging and println-ing lots of stuff. I was able to get the sketch to stop using noLoop(), however, when I added loop() the sketch won't even load. When I comment out Loop() the sketch works again.

onOff = true
i = 0;

setup: ->
    size 200, 200

draw: ->
    println i
    i++

keyPressed: ->
    if onOff
        println "turning off"
        noLoop()
    if not onOff
        println "turning on"
        loop()
    onOff = !onOff

I do not believe it is my code because the equivalent JS version works as expected. The following error prints in the IDE console. Firebug does not report anything.

<from source>
org.mozilla.javascript.JavaScriptException: Error: Parse error on line 20: Unexpected ')'
    at org.mozilla.javascript.gen.c246._c0(<CoffeeScriptModeProcessing>:0)
    at org.mozilla.javascript.gen.c246.call(<CoffeeScriptModeProcessing>)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
    at org.mozilla.javascript.gen.c246.call(<CoffeeScriptModeProcessing>)
    at org.mozilla.javascript.gen.c246.exec(<CoffeeScriptModeProcessing>)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
    at de.bezier.mode.coffeescript.compiler.CSCompiler.run(Unknown Source)
    at de.bezier.mode.coffeescript.compiler.CSCompiler.compile(Unknown Source)
    at de.bezier.mode.coffeescript.CoffeeScriptBuild.build(Unknown Source)
    at de.bezier.mode.coffeescript.CoffeeScriptBuild.export(Unknown Source)
    at de.bezier.mode.coffeescript.CoffeeScriptMode.handleExport(Unknown Source)
    at de.bezier.mode.coffeescript.CoffeeScriptEditor.handleExport(Unknown Source)
    at de.bezier.mode.coffeescript.CoffeeScriptEditor.serverStarted(Unknown Source)
    at de.bezier.mode.javascript.BasicServer.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:680)
@fjenett
Copy link
Owner

fjenett commented May 22, 2013

Yeah, i have that on my list ... not sure what's up.

@jashkenas
Copy link

Unfortunately. loop is a keyword in CoffeeScript. It loops the block of code until you break out of it.

loop
  print '.'
  break if finished

... so you'll have to figure something out.

@fjenett
Copy link
Owner

fjenett commented May 24, 2013

Aha, i speculated about that as being the problem but could not find anything in the CS docs right away. Is there a structured documentation that let's me see these things easily? CoffeeScript.org does not list the keywords for example ..

Thanks!

@jashkenas
Copy link

Just this sentence:

For readability, the "until" keyword is equivalent to while not, and the "loop" keyword is equivalent to while true.

And the actual list of keywords in the Lexer: http://coffeescript.org/documentation/docs/lexer.html#section-60

@fjenett
Copy link
Owner

fjenett commented May 24, 2013

K, thanks. I'll fix this later today.

@skilfullycurled
Copy link
Author

Not a permanent solution per se but I had started a thread on the Processing forums to confirm that there was a problem with loop() before posting an issue. After incorporating the feedback received here, a user aptly named "GoToLoop" stumbled upon a work around which is to use CS's ability to insert raw JS through backticks. Sure enough, using

`loop()` 

will cause loop() to work as expected:

http://forum.processing.org/topic/loop-not-implemented-in-coffeescript-mode#25080000002152759

By the way, does CS mode allow one to access PJS's internal variables?

@fjenett
Copy link
Owner

fjenett commented May 24, 2013

I added "doLoop" as replacement for "loop" and added a check/warning to the compiler. Plus, there is an example showing the use of both the loop control structure and the noLoop() / doLoop() combo.

Should be closed by commit aca5315 please update your mode using the mode manager.

@fjenett fjenett closed this as completed May 24, 2013
@skilfullycurled
Copy link
Author

sweet! thank you my friend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants