tags:

views:

424

answers:

3

I'm trying to modify the boot.scala in lift and running into a funny error. This is what I currently have:

val entries = Menu(Loc("Home", List("index"), "Home")) ::
    Menu(Loc("StudentLogin", List("studentlogin"), "Student Login"))  ::
    Menu(Loc("ProviderLogin", List("providerlogin"), "Provider Login")) 

    LiftRules.setSiteMap(SiteMap(entries :_*))

I get this error:

Boot.scala:29: error: value :: is not a member of net.liftweb.sitemap.Menu Menu(Loc("StudentLogin", List("studentlogin"), "Student Login")) ::

any ideas about what I might be doing wrong?

Thanks.

+5  A: 

Looks like you're trying to build a list with cons without having an empty list at the end. Try this instead

val entries = Menu(Loc("Home", List("index"), "Home")) ::
Menu(Loc("StudentLogin", List("studentlogin"), "Student Login"))  ::
Menu(Loc("ProviderLogin", List("providerlogin"), "Provider Login")) :: 
Nil

LiftRules.setSiteMap(SiteMap(entries :_*))
Joe
Thanks Joe, just figured this out myself. If you have a sec, assuming you get it, could you explain why the Nil is necessary?Thanks.
The :: operator works on lists. Nil is an empty list
Willem
But why is the nil required to finish the list?
It's to do with the way that lists are theoretically represented. In functional languages such as Haskell, LISP and Scala, the List is a recursive data structure. It's formed with recursive applications of `cons` (in Scala it looks like `::`) which combines a single element (on the left hand side) with a list (on the right hand side) to give a list. There must be a list on the right hand side, that's just how `cons` works. `Nil` means 'empty list', and it's always required to terminate your list declaration. This is an important, fundamental aspect of FP and Scala which you should understand!
Joe
Thanks Joe. That makes a lot of sense.
in general, any operator that ends with colon (":") in Scala is right associative. So x + y is equivalent to x.+(Y), because "+" is left-associative, but x abc: y is equivalent to y.abc:(x) ....
LES2
+1  A: 

Not using the :: operator might be more readable:

val entries = List(Menu(Loc("Home", 
                        List("index"), "Home")),
                   Menu(Loc("StudentLogin", 
                        List("studentlogin"), "Student Login")),
                   Menu(Loc("ProviderLogin", 
                        List("providerlogin"), "Provider Login")))
Willem
Makes it less readable, even with the formatting. Had he formatted it better it would read better then yours.
Jim Barrows
+3  A: 

Please take a look at the SiteMap wiki page as well: http://liftweb.assembla.com/wiki/show/liftweb/SiteMap

The new and improved SiteMap syntax is:

def siteMap() = SiteMap(
  Menu(S ? "Home") / "index",
  Menu(S ? "About") / "about" / "index" submenus (
    Menu(S ? "Management") / "about" / "management",
    Menu(S ? "Goals") / "about" / "goals"),
  Menu("directions", S ? "Directions") / "directions" >> Hidden,
  Menu(S ? "Admin") / "admin" / "index" >> If(loggedIn_?, "You must be logged in"))
David Pollak