6

Since Python uses tabs spacing to indicate scope (and as such, has no end of } symbols), does that limit the language in any way from having particular functionality?

Note: I'm not talking about personal preferences on coding-style, I'm talking about real language limitation as a direct result of not having an end statement?

For example, it appears by a post directly from Guido that the lack of multi-line lamba's due to Python not having a terminating end / } symbol?

If so, what other Python limations are there because of this language design decision to use indentation?


Update:

Please note this question is not about Lambda's and technically, not even Python per se. It's about programming language design ... and what limitations does a programming language have when it's designed to have indentation (as opposed to end statements) represent block scope.

3
  • stackoverflow.com/questions/1233448/… Commented Nov 12, 2012 at 14:12
  • 1
    In principle, a lambda can have an arbitrary long expression list, so I don't see why it is limiting.... Commented Nov 12, 2012 at 14:13
  • This question isn't about Lamba's, it's about "what python limitations are there because of the language design decision to use indentation" Commented Nov 12, 2012 at 14:18

4 Answers 4

13

There is no lack of end/ }: an end is represented by a "dedent" to the previous depth. So there is no limitation in any way.

Example:

x = 123
while x > 10:
    if x % 21:
        print("x")
    print("y")
print("z")

A "begin" corresponds to increasing of indentation level (after while, after if).

An "end" corresponds to decreasing of indentation level (after the respective print()s).

If you omit the print("y"), you have a "dedentation" to the topmost level, which corresponds to having two successive "end"s.

Sign up to request clarification or add additional context in comments.

12 Comments

There are some limitations, for example it must be a single expression and it can't contain any keywords.
@PaoloMoretti Playing devil's advocate - I think "can't contain any keywords" isn't quite the right phrasing... test = lambda L: 3 if L % 2 and L > 15 == 0 else 7...
@glglgl your 'answer' doesn't answer my question. Your speaking to Lamda's specifically and my question is 'what language limitations exists when a language is designed to use indentation to have block significance'
The limitation isn't a language limitation it's a lambda limitation.
@glgl I think the point is that, since Python uses physical indentation to determine the grouping of statements (instead of braces or begin/end keywords), it's basically impossible to find a Pythonic way to express multi-line (i.e. multi-statement) anonymous functions.
|
2

The answer to this question ranges somewhere between syntactic sugar and language style, i.e. how to phrase a problem elegant and compliant to language philosophy. Any turing-complete language, even assembly language and C - definitely lacking any lambda support - may solve any problem. Lambda allows just a different (arguably more elegant if looking from functional language viewpoint) phrasing of stuff also stateable using standard function definition. So I can't recognize a limitation here beyond having to code differently.

Comments

0

One of the biggest limitations (if you would call it that) is that you can not use tabs and spaces in the same program.

And you shouldn't. Ever.

There are no apparent structural limitations, except perhaps when parsing a python source file (parsing, not interpreting):

def foo(bar):
        # If bar contains multiple elements
    if len(bar) > 1:
            return bar

This is perfectly legal python code, however, when parsing the file, you may run into trouble trying to figure out which indentation level the comment belongs to.

Comments

0

What do you mean by "limitation"? Do you mean there are computations Python cannot perform that other languages can? In that case, the answer is definitely No. Python is turing complete.

Do you mean that the lack of end statements change how computations are expressed in Python? In that case, the answer is "mostly not". You must understand that Python's dedent is an end statement; it's a byte sequence that the interpreter recognizes as the end of a block.

However, as others have mentioned, the use of indentation to denote blocks is awkward when it comes to inline functions (Python's lambda). This means the style of Python programs might be slightly different than from JavaScript, for example (where it's common to write large inline functions).

That being said, many languages don't even have inline functions to begin with, so I wouldn't call this a limitation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.