2009-09-07

mordant

According to Merriam-Webster's Online Dictionary: “biting and caustic in thought, manner, or style : incisive <a mordant wit>”

2009-08-31

milksop

According to Dictionary.com: “a weak or ineffectual person.” According to The Oxford Dictionary of English Etymology: “milksop orig. SOP dipped in milk, (hence) one who is fed on such food, young infant, (transf.) effeminate fellow” Also: milquetoast

2009-08-24

horology

(No, I'm not going to give a hint for this one!) The science of measuring time.

2009-08-17

hondo

According to Wikipedia, “The lariat has a small reinforced loop at one end, called a honda or hondo, through which the rope passes to form a loop.”

2009-08-10

encomium

According to Merriam-Webster's Online Dictionary: “glowing and warmly enthusiastic praise ; also : an expression of this.” Definitely not to be confused with meconium!

2009-08-03

dysteleology

The doctrine of purposelessness in nature See also: Wikipedia.

2009-07-29

dubnium

HINT: It is not "former President George W. Bush's favorite element". One of the elements (Symbol Db; atomic number 105). See also: Wolfram|Alpha"

2009-07-20

docent

A teacher or lecturer at some universities who is not a regular faculty member.

2009-07-13

curtilage

The enclosed area immediately surrounding a house or dwelling. See also: Wikipedia

2009-07-06

2009-06-29

bavardage

Babble, jargon. According to Free online ditionary: ”Much talking; prattle; chatter.“

2009-06-22

2009-06-15

2009-05-25

ignis fatuus

A Will-o'-the-wisp. Recorded in English from the mid 16th century, the phrase is modern Latin, literally ‘foolish fire’ (because of its erratic movement).

2009-05-18

2009-02-11

Scala custom syntax: "after"

I've run into this pattern a few times where I want to return the value of some expression, but I also need to do some side-effect between evaluating the expression and returning its value. For example, putting the result into a cache. Or, setting some additional state in a constructed object. The normal way of doing this involves putting the value of the expression into a temporary variable, performing whatever other operations are needed and then returning the value of the temporary. That is fine but it turns into at least three lines of code and some cases are so simple you might wish you could do it all on one line and not bother naming a temporary.

I recently gave a presentation on "Sampling Scala" and ended up developing a Scala custom syntax addition to handle it. At the Scala BASE meeting at Googleplex last night, Jorge Ortiz was showing a Lift Chat server example and it had this piece of code:

  private val server = {
    val ret = ChatServer.server
    ret ! ChatServerAdd(this)
    ret
  }

Which demonstrates the situation. I'd much rather write that:

  private val server = ChatServer.server after { _ ! ChatServerAdd(this) }

Here's the way to implement after:

object After {
  implicit def any2After[A](value: A) = new After(value)

  class After[A](val value: A) {
    def after[B](f: A => B) : A = { f(value); value }
  }
}

And, here is another example of using it:

import collection.mutable.Map
import After._

val cache = Map[Int, Int]()
  
def foo(x : Int) : Int = {
  val y = // ...

  return y after { cache(x) = _ } // like finally, with an arg
}