From: Tony Arcieri Date: 2009-05-20T07:23:20+09:00 Subject: Re: Pythonic indentation (or: beating a dead horse) --0016e6476e7692ca95046a4b5b1e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Let me get right to the heart of the issue here. It really comes down to this: On Tue, May 19, 2009 at 3:40 PM, J Haas wrote: > I think code blocks are cool, and I love Ruby's very flexible > expressiveness. I dig the way every statement is an expression These are both incompatible with a Python-style indentation sensitive syntax. You can have the Pythonic indent syntax or a purely expression based grammar with multi-line blocks. You can't have both. In Python, all indent blocks are statements. This is why Python can't have multi-line lambdas using Python's indent rules: lambdas are only useful as expressions, but all indent blocks in Python are statements. The same issue carries over to blocks, as a good deal of the time you want a method which takes a block to return a value (e.g. map, inject, filter, sort, grep) There's quite an interesting interplay of design decisions to make Python's indent-sensitive grammar work the way it does. Indent blocks in Python have no terminator token, whereas every expression in a Ruby-like grammar must be terminated with ";" or a newline. This works because Python's expressions are a subset of its statements, so it can have different rules for statements versus expressions. Implicit line joining works in Python because the only syntactic constructions which can exist surrounded in [...] (...) {...} tokens are expressions, so you can't put an indent block inside of these. If you have an indent-sensitive Ruby with implicit line joining, you limit the expressiveness of what you can do inside any syntactic constructs enclosed by these tokens. If you want to have indent blocks in a purely expression-based grammar, you need to use a syntax more like Haskell. I've seen a somewhat Python-looking language called Logix which uses Haskell's indent rules. It was created by Tom Locke, who has since gone on to author Hobo in Ruby, and for what it's worth now says he prefers Ruby's syntax. Go figure. P.S. I tried to make a Ruby-like language with an indentation-sensitive syntax. These are the lessons I learned. I gave up and added an "end" keyword. -- Tony Arcieri medioh.com --0016e6476e7692ca95046a4b5b1e--