Re: English-like Python



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, [] )



--
Steven
.



Relevant Pages

  • Re: Syntax checker wtf?
    ... Ruby would give you a syntax error on a multiline ... SyntaxError: compile error ...
    (comp.lang.ruby)
  • Re: Method annotation and anonymous functions
    ... anonymous functions and anonymous closures (so def and lambda could have ... the same syntax but lambda would create a closure, ... class Foo ...
    (comp.lang.ruby)
  • [9fans] Re: 9base ports to unix (flame of byrons rc)
    ... (sorry about the lack of unicode support thorugh this interace. ... -> syntax error ... paul haahr's rc's-lovechild-with-scheme shell es uses ... Byron's shell implements rc-inconform things like `foo as ...
    (comp.os.plan9)
  • Re: [9fans] 9base ports to unix
    ... > of plan9's rc to a staticially linked version of Byrons rc rewrite? ... is invalid syntax, only ... Byron's shell implements rc-inconform things like `foo as ...
    (comp.os.plan9)
  • some corrections Re: The Fundamental Problems of Lisp
    ... syntax, which can be used to comment out well-formed S-expressions ... M-expressions make an extensive appearance in John Allen's ...
    (comp.lang.lisp)