Syntax Collisions

The Scala icon-external-link-12x12 icon-search-12x12 programming language is filled with all kinds of syntax abbreviations that can do a lot to make code clean, concise, and explicit. Typically these are useful and intuitive for someone who is familiar with the core language, but there are some that could be called cryptic, and maybe even deceptive. The following example is provided by the book Programming in Scala icon-external-link-12x12 icon-search-12x12 during a lesson on Pattern Matching icon-external-link-12x12 icon-search-12x12, and the authors may have omitted necessary explanations in previous sections for the reader to make successful attempts at its interpretation:

val withDefault: Option[Int] => Int = {
  case Some( x ) => x
  case None => 0
}

At first glance, the code looks very much like a variable declaration that collided with a function definition resulting in a new combined entity and some shrapnel (appearing in the form of Int = ). This is actually a function that returns an instance of Int, which is confirmed by its behavior:

scala> withDefault( Some( 10 ) )
res28: Int = 10

scala> withDefault( None )
res29: Int = 0

So it’s clear that withDefault is the variable’s name, but is it somehow also the type Option[Int]? This cannot be, but it is way too close to a variable declaration for comfort. So what’s going on? And if pattern matching is occurring—which it is—where did the match statement go?

It turns out the above function literal is shorthand for the following:

val withDefault = ( argument: Option[Int] ) => argument match {
  case Some( x ) => x
  case None => 0
}

This is unambiguous, while the abbreviated version is not: argument is supplied to the function referenced by the withDefault variable and then matching attempts are made against the cases Some(x) and None with either x or 0 being returned, depending on the match that is made. It’s also not that much longer, which makes a person wonder why the shorthand version was included in the language at all.

As a final note, the abbreviated form behaves the same as the following function literal, which uses Scala’s Placeholder Syntax icon-external-link-12x12 icon-search-12x12 to unshroud the argument:

val withDefault: Option[Int] => Int = {
  _ match {
    case Some( x ) => x
    case None => 0
  }
}

So the mystery has been solved, and it’s probably safe to say that this is not one of Scala’s better syntax maneuvers. The piece of code shrapnel Int = is the only oddity that remains, and this is present because the compiler needs the return type to be specified. Why can’t it make this inference in the original function when it was able to do so in the second and more reasonable definition? Fuck if I know. Maybe the compiler needs a token to appear there so that nonsense like => = doesn’t ever have to be considered valid. Regardless, this sure seems like a lot of trouble to save the programmer from typing a few extra characters on the keyboard.

Ain’t No Big Deal

I Kissed a Girl icon-external-link-12x12 icon-search-12x12 (track 02 from the One of the Boys LP by Katy Perry icon-external-link-12x12 icon-search-12x12 )

This was never the way I planned, not my intention
I got so brave, drink in hand, lost my discretion
It’s not what I’m used to, just wanna try you on
I’m curious for you, caught my attention

I kissed a girl and I liked it, the taste of her cherry chapstick
I kissed a girl just to try it, I hope my boyfriend don’t mind it
It felt so wrong, it felt so right, don’t mean I’m in love tonight
I kissed a girl and I liked it

No, I don’t even know your name, it doesn’t matter
You’re my experimental game, just human nature
It’s not what good girls do, not how they should behave
My head gets so confused, hard to obey

I kissed a girl and I liked it, the taste of her cherry chapstick
I kissed a girl just to try it, I hope my boyfriend don’t mind it
It felt so wrong, it felt so right, don’t mean I’m in love tonight
I kissed a girl and I liked it

Us girls we are so magical
Soft skin, red lips, so kissable
Hard to resist, so touchable
Too good to deny it
Ain’t no big deal, it’s innocent

I kissed a girl and I liked it, the taste of her cherry chapstick
I kissed a girl just to try it, I hope my boyfriend don’t mind it
It felt so wrong, it felt so right, don’t mean I’m in love tonight
I kissed a girl and I liked it

Dead Mechanical Crypt Creatures

dead-mechanical-crypt-creatures--000000-formatted

« Playlist »

Never Dead icon-external-link-12x12 icon-search-12x12 (track 06 from the TH1RT3EN LP by Megadeth)
“Never Dead” Song Lyrics icon-external-link-12x12 icon-search-12x12
Snuff icon-external-link-12x12 icon-search-12x12 (track 03 from the World Painted Blood LP by Slayer)
“Snuff” Song Lyrics icon-external-link-12x12 icon-search-12x12
Demon Eyes icon-external-link-12x12 icon-search-12x12 (track 06 from the One Kill Wonder LP by The Haunted)
Cryptorchid icon-external-link-12x12 icon-search-12x12 (track 06 from the Antichrist Superstar LP by Marilyn Manson)
“Cryptorchid” Song Lyrics icon-external-link-12x12 icon-search-12x12
I Don’t Mind the Pain icon-external-link-12x12 icon-search-12x12 (track 10 from the Danzig 4 LP by Danzig)
“I Don’t Mind the Pain” Song Lyrics icon-external-link-12x12 icon-search-12x12
Mechanical Mind icon-external-link-12x12 icon-search-12x12 (track 04 from the Target Earth LP by Voivod)
“Mechanical Mind” Song Lyrics icon-external-link-12x12 icon-search-12x12
Creature Lives icon-external-link-12x12 icon-search-12x12 (track 10 from The Hunter LP by Mastodon)
“Creature Lives” Song Lyrics icon-external-link-12x12 icon-search-12x12
Hand of Doom icon-external-link-12x12 icon-search-12x12 (track 06 from the Paranoid LP by Black Sabbath)
“Hand of Doom” Song Lyrics icon-external-link-12x12 icon-search-12x12

Red-Painted Warrior Bars

Excerpt from the novel Never Deal with a Dragon icon-external-link-12x12 icon-search-12x12 by Robert N. Charrette icon-external-link-12x12 icon-search-12x12

     Dodger leaned on the fire escape railing and sighed. He didn’t need cybernetic ears or even his Elven hearing to catch the rhythmic sounds and breathy gasps coming from the squat through the open window. The two inside would know that he was waiting. Ghost Who Walks Inside’s auditory enhancements would have picked up Dodger mounting the ladder. The Elf suspected that the street samurai could also monitor the challenges of his tribe’s sentries at either end of the alley.
     The alley was typical of the Redmond Barrens—a malodorous, clogged byway set in a neighborhood of moldering urban blight. The grimy brick wall of the neighboring tenement and the refuse-strewn concrete were hardly fit for contemplation. Dodger turned his attention to the mouth of the alley, where the flickering glare of a neon sign cast mad rainbows over the three guards.
     Local residents must find the trio’s warpaint, feathers, and fringed synthleather garments a routine sight, for this turf belonged to the Full Moon Society. Like most of the gangs in the Barrens, they provided soldiers, protection, and what passed for law and order in this part of the corp-forsaken slum. Unlike other gangs and freelancers who affected Indian fashions, the Society members actually had Indian blood. The Full Moon Society was the physical muscle of Ghost Who Walks Inside’s urban tribe.
     The tribe had no name as far as Dodger knew, its members a mixture of heritages, from Salish to Blackfoot to Navajo. Most were young runaways from tribal lands, lured by the big city and fast life of the Whites and Yellows. Some were plex-born and bred, their ancestors having long since abandoned the bucolic dreams of the tribals who ran the Council Lands. Only a few were old enough to remember the concentration camps of the century’s earlier decades; and these were the source for the handful of ancient customs the tribe followed.
     Ghost’s people, like most tribals in North America, had lost much of their heritage. Under the guise of combatting a rebellious and dangerous terrorist element, the former U.S. government had tried to exterminate the Reds. It had condemned them to “re-education centers” intended to stamp out Indian culture and racial identity. The terror only ended when the leaders of tribal unification raised the rising tide of magic to smash the tyrant’s grip. The power of the Great Ghost Dance had won back liberty and land, as well as creating a new order in North America.
     But the tribal peoples had suffered more than physically. Much knowledge once painstakingly gathered by anthropologists and preserved by tribal historians perished in the purges. They were forced to rebuild their heritage from the memories and tales of the old folks. The urban tribes were a legacy of the loss.
     The city tribes were bound by skin color and outlook rather than the traditional affiliations, and dressed in a mixture of styles drawn from traditional garb, White clothing, mistaken reconstruction, and pure whimsy. They might be the new face of the Red man, as Ghost believed, or they might be a dead end, outcasts from the autonomous tribes of the Council lands. Whatever they were, this neighborhood was their home; they had made it relatively safe for their own members and any who acknowledged their dominance.
     Those three at the mouth of the alley were the muscle who ran the shadows and the spotters and scouts who blended in the bricks until their eyes seemed everywhere. They were good at what they did. They had to be. Their type was either good or dead.
     As though sensing Dodger’s gaze, the leader of the three turned slowly and glared up at the Elf. Dodger didn’t remember the kid’s name, but the hate on his face revealed how hard the street had been before the urban tribe took him in.
     Wanting the respect people gave to Ghost, known throughout the plex and beyond as a near-matchless warrior, this street warrior tried to emulate him by adopting the older Indian’s technocreed and cybering up. Already he wore the red-painted warrior bars on his arm as a badge of his lethal prowess in the turf wars that were the tribe’s battlefields. But the perfect vision of those chrome eyes couldn’t let him see that toughness and street smarts were not enough to make a leader. As long as he held to his hate, he would be a punk, blind to the wisdom that made Ghost Who Walks Inside the chief of his people.
     A hand on Dodger’s shoulder broke his reverie. Turning, he saw Ghost standing before him, sweaty and smelling of sex. The ragged denim cut-offs, beaded vest, and sheen of his perspiration set off the muscularity of his trim build. His curled fingers hid the faint etching of induction pads on his palms, but the absence of his habitual headband exposed the four studs along Ghost’s left temple. The apparent naturalness was a subtlety of style and strategy that the punk, with his chrome eyes and blatant bodyshop muscle implants, had missed.
     Ghost’s dark eyes sparkled, and he grinned, showing uneven teeth. “Practicing your chivalry, Elf?”
     “Discretion is ever advised in affairs concerning the fairer sex, O Samurai of the Streets.”
     “Give her a minute.”
     “Certes, Sir Razorguy.” It was not as though Dodger had never seen Sally naked before, but Ghost might not be aware of that fact. He waved a hand in the general direction of the sentries. “Your warriors passed me through without a word that you and Sally were occupied.”
     “Not their biz.”
     No, but they would have known. “Perhaps they thought to gain amusement at my expense, expecting you to react violently to an intrusion.”
     Ghost glanced down at his soldiers. “Hunh. Jason just might. He doesn’t know me half as well as he thinks. Let’s go inside.”
     Ghost led the way through the window, moving slowly, no doubt to block Dodger’s view until the Indian was certain Sally was decent. The Elf smiled at the Indian’s back and followed.
     Sally Tsung sat cross-legged on the foam pad that served as a bed. The University of Seattle T-shirt clung to her body, practically transparent in its contact with her damp skin. The shirt might have been more than long enough to cover a more modest lady, but Sally’s position had hiked it up over her hips to reveal dark blue panties. A lurid Dragon tattoo crawled down the length of her right arm to rest its chin on the back of the hand brushing back her blonde hair. She was disheveled and reeked as much as Ghost, but she was beautiful.
     “Dodger,” she said, her face lighting with a welcoming smile. “Ghost said it was you. Haven’t seen you in . . . how long has it been?”
     “Not long enough,” Ghost offered.
     Sally shot him a look of mock anger. “Too long. Been too busy to sprawl with old friends?”
     ” ‘Tis truth, Fair One, that I have been occupied.”
     “And now you’re loose.” She rolled to her feet. “That’s wiz! We heard a rumor that Concrete Dreams will show up to play at Club Penumbra tonight. It isn’t true, of course, but the crowd ought to be great. Figures that you’d show in time for a big street party.”
     Dodger was tempted, but he had other things on his mind. ” ‘Tis certain to be a full flash, Lady. A pity that I shall be elsewhere.”
     “Biz?” Sally asked with mild curiosity.
     “Does the name Samuel Verner call any memories to mind?”
     “Sure. That was the kid who tipped us to the scam when Seretech tried setting us up for murder in that Renraku run last year.” Sally’s laugh ended in a sly smile. “No, can’t recall a thing.”
     “I have heard from him recently,” Dodger said.
     “He survived going back to Raku?” Ghost asked. “He was one brave paleface to hold to his loyalty.”
     “Foolish, more like. If they didn’t dump him, they must of froze him solid. Junior salaryman without end, or hope. Amen.” Sally snatched a soy bar from the stool that served as a table. Around the mouthful she bit off, she added her evaluation, “What a dumb kid.”
     Dodger looked at Ghost to see how he took the remark. Ghost, who was younger than Sally, kept his expression rigidly neutral. Dodger knew this meant disagreement, but the Indian would not voice it. Some kind of Indian macho thing. Feeling uncharacteristically sorry for the samurai, Dodger said, “I believe that he is of an age with yourself, Lady Tsung.”
     “Let’s not get personal, Dodger,” she snapped.
     The Elf gave her his most disarming grin. “No offense intended, Fair One. I only meant to imply that first impressions can be deceiving.”
     “Are you saying there’s something we should know about him? Something about the Seretech run?”
     “Nay. That matter is long-buried. As to what you might want to know of him, I would not presume to say. You have ever been the best judge of what you needed, or wanted, to know of anyone.”
     “Dodger.” Sally’s voice held a warning note, but still remained light. Her tone said he had piqued her interest.
     “The word I bring is that he wishes to meet with those he ran with a year ago.”
     “Then it is biz!” Sally sat up, eyes widening as a new eagerness entered her face. “Has he changed his name to Johnson?”
     “Not exactly.”
     “Don’t be coy, Dodger.”
     “Far better, Fair One, that he explain it all to you himself.”