compiler stupidity [was Re: Interesting... AppleScript X ??]
compiler stupidity [was Re: Interesting... AppleScript X ??]
- Subject: compiler stupidity [was Re: Interesting... AppleScript X ??]
- From: has <email@hidden>
- Date: Thu, 26 Sep 2002 18:42:55 +0100
Hi,
>
>BTW, bizarrely, the compiler seems to trip up on the following syntax for
>
>no adequate reason:
>
>
>
> "abcde"'s count -- compiler error: "I am too stupid to understand this"
>
>
>
In reality it says 'expected expression but found command name', why do you
>
expect count to be a property of "abcde"? Because 'of' works? Count is a
>
procedure isn't it?
Count is a function or method. Every other language under the sun would
write it in such a way that it could never be confused with a property,
most commonly: 'count(foo)' [for function calls] or 'count() of foo' [for
method calls].
AS tries to make everything look English-like; unfortunately, this causes
both user and compiler some confusion over what 'count' actually is. The
difference is that we usually learn what it is after a while; the compiler,
however, isn't pre-programmed with this knowledge, nor is it able to pick
up and read a copy of the ASLG to learn it for itself.
Even then, there's no real reason why a distinction should be made: I'm
pretty sure it's an artificial one anyway, and that 'properties' in
native-grown AS objects actually exist under the surface as get() and set()
methods with the real state tucked safely away behind. (Hence you cannot
type stuff like: 'set length of str to 6', 'set size of file "foo" to 0',
or 'set name of file "foo" to false'.)
However, if the compiler isn't smart enough to sort out the kinds of messes
that are created by futzing the definition and/or appearance of language
structures, then it really isn't doing its job adequately. [No doubt this
is why most parser/compiler designers will prefer a tight, precise syntax
containing lots of unfriendly but easy-to-machine-read symbols and
structures.] AS is trying to do right by its audience, and I applaud it for
that, but really, what's a novice users supposed to make of the kinds of
cryptic error messages the AS compiler routinely throws up while tripping
over perfectly valid-looking code?
>
however...
>
>
count {"abcde"}'s every string
>
>
is quirky in some AS versions if I recall correctly.
Wouldn't surprise. This example should parse as:
count (strings of {"abcde"})
However, the count function does have an optional 'each' parameter - as in
'count str each foo' (or 'count each foo of str' if you want that to read
as remotely human-legible).The problem with the next example given seems to
be connected to AS's awareness/understanding/treatment of optional
parameters:
>
> if count "abcde" is 5 then beep
as something like:
ASCII number "a" is 97
has no problems compiling, and you'll note the compiler wraps parentheses
around the 'ASCII number "a"' bit automatically. So it obviously knows what
it's doing there [adding parentheses to the user's source is taking a bit
of a liberty, mind you, but probably an inevitable side-effect of turning
the compiled code back into pretty-printed text].
>
I don't find either of these examples bizarre, once you learn to
>
parenthesise a procedure so it's resolved first it becomes intuitive. If all
>
else fails use a variable.
*Key phrases* here: "once you learn to..." and "if all else fails...".
Honestly, with so many stupid syntactical caveats and gotchas, you have to
wonder who this language is designed for? People who enjoy the cryptic
crossword section in The Times, perhaps. AppleScript is supposed to be
SIMPLE.
My guess: the compiler authors most likely overreached themselves,
underestimating the amount of smarts the compiler would need to handle such
a malleable syntax, and the language designers maybe didn't consolidate the
underlying language structure as well as they could've [the excessive
distinction between method call and property reference]. I applaud them for
their decision to tackle this area at all when they might've just welched
and cooked up another simple-but-cryptic C-style syntax [light on the
machine, but hell on non-programmers], but I think there's a considerable
way to go before the language and its compiler live up to all their
promises.
Cheers,
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.