4 ms·
In C, parentheses mean expression grouping, function invocation and cast... depending on context. In English, many words have different meanings depending on c
by 10ren 17y ago
In C, parentheses mean expression grouping, function invocation and cast... depending on context.
In English, many words have different meanings depending on context: e.g. not to be mean, but you know what I mean, right? Ordinary human speakers have no problem with this, even without theoretical linguistic training.
I'm not convinced that Larry Wall (a formally trained linguist) has chosen meanings and contexts that really do fit in with what human speakers intuitively expect. But it could well be that it is just that I am personally familiar with C-style grammar, and not with Perl's. If I "grew up" with Perl, perhaps it would seem natural?
Perhaps it's exactly the same as with human languages: that languages with very different grammars are not so easy to learn for most people. And... perhaps there is a linguistic window for learning programming languages, as there is for human languages (which is up to about 7yo)?
- masak 17y agoOh, believe me, constructs in Perl (both Perl 5 and Perl 6) mean different things depending on context, too. :) As a simple example, which you'll find in various languages, not just Perl: brackets ('[ ]') construct list objects when standing alone, but when they occur after something, they do array indexing into that thing. This all falls out naturally, and humans are very well equipped at switching between this type of contexts. The Perl 5 behaviour of overloading 'reverse' with double meaning could be said to be context-dependent in this way. But the flip/reverse/invert distinction goes in the other direction, saying "hey, maybe we do want to keep these three concepts separate rather than crowding them all into the same method". A similar thing has happened with 'length'. In Perl 5, 'length' always meant 'number of characters in the supplied string', but newbies kept expecting the function to work for lists too. It doesn't. In Perl 6, there's a method '.elems' for lists and '.chars' for strings. Neither of them are accessible as 'length'. In a lot of places where Perl 5 overloads words and depends on context for the right semantics, Perl 6 strives to make things consistent and eliminate mental lists of things you have to remember.
- tptacek 17y agoNo, they mean different things depending on syntax. (char *) is never a function invocation.
- 10ren 17y agoI was picturing an AST, with the parentheses in the context of that. However, you're quite right that context seems to have a specific technical meaning here, and not the general one I was using.