Guess a number between 1 and 100.
Last guess:
Guess:
You Win!!
You guessed after guesses.
The view code:

    <lift:surround with="default" at="content">
    <lift:snippet type="CountGame:run" form="POST">
      <choose:guess>
        Guess a number between 1 and 100.<br/>
        Last guess: <count:last/><br />
        Guess: <count:input/><br/>
        <input type="submit" value="Guess"/>
      </choose:guess>

      <choose:win>
        You Win!!<br />
        You guessed <count:number/> after <count:count/> guesses.<br/>
      </choose:win>
    </lift:snippet>
    </lift:surround>

The Snippet:

    class CountGame extends StatefulSnippet {
      val dispatch: DispatchIt = {
        case "run" if lastGuess == number =>
          xhtml => win(chooseTemplate("choose", "win", xhtml))

        case "run" =>
          xhtml => nextGuess(chooseTemplate("choose", "guess", xhtml))
      }

      def win(xhtml: NodeSeq) = bind("count", xhtml, "number" --> number,
                                     "count" --> count)

      def nextGuess(xhtml: NodeSeq) =  bind("count", xhtml,
                                            "input" --> text("", guess _),
                                            "last" -->
                                            lastGuess.map(v =>
                                              if (v < number) v+" is low"
                                              else v+" is high").
                                            openOr("Make first Guess"))

      private def guess(in: String) {
        count += 1
        lastGuess = Full(toInt(in))
      }

      private val number = 1 + randomInt(100)
      private var lastGuess: Can[Int] = Empty
      private var count = 0
    }