Utterances of a Zimboe

Programming the Internet.

Unstable identifier

leave a comment »

In case you had missed this teeny bit of Scala spec [v2.6, 8.1.4 Stable Identifier Patterns]:

Example 8.1.2 Consider the following function definition:

def f(x: Int, y: Int) = x match {
case y => ...
}

Here, y is a variable pattern, which matches any value. If we wanted to turn the pattern into a stable identifier pattern, this can be achieved as follows:

def f(x: Int, y: Int) = x match {
case ‘y‘ => ...
}

Now, the pattern matches the y parameter of the enclosing function f. That is, the match succeeds only if the x argument and the y argument of f are equal.

And, a little earlier:

A variable pattern x is a simple identifier which starts with a lower case letter.

I was trying to match a type with a lowercase name and it took me a moment to figure out why it didn’t work.. :)

Btw., I don’t like this syntax-by-convention a bit, and it was a major surprise to bump into such here (with Scala, that is). I guess I need to question this at the forum.

Update (a better look): Ok, backquoting an id is an established syntax for denoting a stable identifier. Oh so novice for not knowing. But still, “identifier which starts with a lower case letter”.

Tags:

Advertisements

Written by Janne Savukoski

October 17, 2007 at 12:38 am

Posted in Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: