News for hackers. Stuff that matters.
Re:CoffeeScript, a little language that compiles to JavaScri... by jashkenas on Thursday December 24, 2009 @02:31PM (#1014265)
Yeah, the periods to end block scope are the part of the syntax I'm the least happy with. I couldn't think of anything nicer without resorting to significant whitespace (which I'd like to avoid).

I'd rather not add {/}, or begin/end, because it's easy to determine the beginning of the block, it's just closing it that we need a symbol for.

In terms of style, you can certainly indent the period on it's own line if you prefer:

    elements.each(el =>
      $(el).click(event =>
        if el.hidden
          el.highlight()
        .
      .)
    .)
But I'd love to hear more suggestions for alternatives.
Re:CoffeeScript, a little language that compiles to JavaScri... by tdavis on Thursday December 24, 2009 @03:26PM (#1014334)
Out of curiosity, what makes you want to avoid significant whitespace? I think it solves the issue quite nicely. For what it's worth, I used to think SW was completely absurd. Then I spent a few years actually writing Python and have no desire to ever go back.
Re:CoffeeScript, a little language that compiles to JavaScri... by j_baker on Thursday December 24, 2009 @03:41PM (#1014358)
Python's requirement of indentation is somewhat limiting in terms of what the language can do. For instance, that's partly the reason why Python doesn't allow more than a single expression in a lambda.
Re:CoffeeScript, a little language that compiles to JavaScri... by jashkenas on Thursday December 24, 2009 @04:00PM (#1014385)
It doesn't? Is there some kind of documentation about it we can look at?
Re:CoffeeScript, a little language that compiles to JavaScri... by DougBTX on Thursday December 24, 2009 @06:56PM (#1014555)
Try: http://docs.python.org/dev/3.0/glossary.html#term-lambda

Sounds good that you are going to give significant indentation a try.

Re:CoffeeScript, a little language that compiles to JavaScri... by jashkenas on Thursday December 24, 2009 @03:48PM (#1014370)
I like to have the flexibility to indent in whatever style the code calls for. That said, looking over the Python docs again, their implementation of significant whitespace is a lot more flexible than I remembered. I didn't realize you could do one-line method definitions, and that the whitespace only kicks in when you write a multi-line block.

Here's a question for you. In Python, if you have a couple of nested lambdas with multiline bodies, getting passed into each other as arguments, do you have to write the closing parenthesis on the correctly-indented line on the other side, or can it be tucked against the inner lambda?

In a hypothetical significant-whitespace CoffeeScript, I'm thinking of this:

    elements.each(el =>
      el.click(event =>
        el.show()))
Versus this:

    elements.each(el =>
      el.click(event =>
        el.show()
      )
    )
Is the second form required to make Python-style whitespace work?
Re:CoffeeScript, a little language that compiles to JavaScri... by scott_s on Thursday December 24, 2009 @07:19PM (#1014585)
Python does not have multiline lambdas. But Python only uses significant whitespace when it can't use other demarcations. For example, the following is legal:

  a = [
        1,
          2,
            3]
Re:CoffeeScript, a little language that compiles to JavaScri... by aaronsw on Thursday December 24, 2009 @03:53PM (#1014379)
No.
Re:CoffeeScript, a little language that compiles to JavaScri... by jashkenas on Thursday December 24, 2009 @04:07PM (#1014394)
Great. Then let's start a "whitespace" branch, and give it a go.

Edit: Alright, got a branch that starts with a little significant whitespace going here:

http://github.com/jashkenas/coffee-script/tree/whitespace

It can't handle the first of the two cases mentioned above just yet, but it compiles the second one correctly.

Re:CoffeeScript, a little language that compiles to JavaScri... by oliverkofoed on Thursday December 24, 2009 @07:14PM (#1014580)
I actually think that the period to end blocks syntax is one of the most interesting things about it. It's such a small thing, but i find it quite intriguing.
Re:CoffeeScript, a little language that compiles to JavaScri... by lucifer on Thursday December 24, 2009 @03:50PM (#1014372)
Its quite pleasing; well done!

My take on the blocks is that significant whitespace seems to be a natural expression of blocks for your language and fits quite nicely with the aesthetics of the other forms. (The terminal ... choo choo train is not a winning idea.)