English-like Python

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Jan 22 09:17:17 CET 2009

On Wed, 21 Jan 2009 08:17:34 -0700, Joe Strout wrote:

> Steven D'Aprano wrote:
>> But even if RB doesn't have these things, I question that the syntax is
>> "beautiful". Consider some arbitrary method Foo. If you see this:
>>     Foo
>> Is that legal RB syntax?
> You betcha!  

How do you know? I haven't specified what Foo does. As you say a little 
later on:

>> Maybe yes, maybe no. It all depends on what Foo does. If it returns no
>> result, then it's legal. If it returns a result, it isn't.
> Right.  In other words, you can tell just by looking at the call that it
> doesn't return a result.  This is often handy.

You can't tell the difference between a syntax error and a valid call 
without knowing what Foo does. In Python, you can always recognise a 
syntax error without needing to worry about the semantics of the call. 
This is not the case with RealBasic.

> For example, the built-in method to play the standard
> system alert sound is:
>      Beep
> Doesn't get much more readable and syntax-free than that.

readable doesn't mean smallest amount of syntax possible sometimes syntax 
increases the readability of a text as you would see if we for example 
dropped all punctuation but you probably already knew that but perhaps 
you didnt draw the connection with programming language wink

> Suppose now
> that a beep isn't eloquent enough, and you want the computer to speak
> something out loud instead.  Also easy:

I've programmed in Hypertalk, which is full of constructs like:

get the value of field "Bar"
put it into x
put x+37 into x
ask "Eat " & x " pies?" with "Yes please", "No thanks"
if it is "Yes please" then go to card "PieCard"

so I understand the principle of leaving out parentheses to make things 
look kinda-sorta vaguely English-like. I actually do like Hypertalk, I 
think it is neat, but I can tell you that you get no respect from other 
programmers when you show them your code :)

>> So the question of whether syntax is legal depends, not on the
>> syntactic elements involved, but on the *semantics* of the method
>> (whether or not it returns a result).
> But of course.  Any method call is legal only if the form of the call
> matches the method prototype -- if you try to call a function that
> requires 4 parameters, and give it only 3, that's an error too.  I don't
> see how this is different in any important way.

But it isn't (presumably) a syntax error.

I accept that in practice, it isn't a big deal once you get used to the 
convention. But it's a special case -- why treat functions of zero 
arguments as a special case just to save two characters? It seems to me 
that the cost of this is that using functions as first-class objects 
takes a major usability hit. How would you write the equivalent of this 
in RealBasic?

def func(f, args):
    args = reversed(args)
    return f(*args)

x = func( lambda a, b, c: a+b*c, [1, 2, 3] )
y = func( lambda: 7, [] )


More information about the Python-list mailing list