Thanks, David, that is tremendously helpful. Clearly I was just
missing the object import.
While "Starting with Lift" shouldn't be a Scala tutorial, I think it
would be quite helpful in this case to mention which objects provide
these particular methods and maybe even mention the object import and
show the import SHtml._ line in the fragment.
-Antony
On Sat, Apr 11, 2009 at 9:40 AM, David Pollak
<[email protected]> wrote:
>
>
> On Sat, Apr 11, 2009 at 6:18 AM, Antony Courtney <[email protected]>
> wrote:
>>
>> I am an experienced Java / C++ / Haskell programmer, but new to Scala
>> and Lift. I've been learning Scala for a few weeks and am just
>> starting to learn about Lift. This question may show more about my
>> ignorance of Scala that anything else, but I suspect I'm not alone so
>> here goes...:
>>
>> In the code fragment for "Show" in "Starting with Lift" (as of March
>> 28, 2009; version 4?), section 2.6, bottom of page 14 on to page 15:
>> What exactly are the functions 'bind', 'text' and 'select' here?
>> Where are they defined and why are they in scope here? Where would I
>> look in the API documentation to see the type signatures or understand
>> in detail what these functions do? How would I be able to answer any
>> of these questions on my own just by reading this code fragment?
>
> In Scala, you can import an object (objects are singletons). Importing an
> object makes that object's methods available without specifying the object
> to which they are attached. This is similar to Java's static import. So:
>
> object Foo {
> def woof = "Woof Woof"
> }
>
> import Foo._
>
> class Bar {
> println("My dog says "+woof)
> }
>
> There are 3 main objects (singletons) that are used in Lift: S
> (net.liftweb.http.S), SHtml (net.liftweb.http.SHtml), and
> Helpers.(net.liftweb.util.Helpers). You will find almost all the methods in
> one of those places. S is everything (not really) that is stateful (I named
> it when I was using emacs and before I knew about importing objects and I
> wanted something short to type.) SHtml is also stateful and contains the
> HTML creation for stateful stuff. Helpers are a lot of methods that help
> with stuff. The methods text and select are in SHtml because they create
> HTML and are stateful (they update the state in your application by creating
> HTML elements that contain GUIDs that refer to functions on the server).
> The method bind is in Helpers. Is helps you to re-write the incoming
> XHTML.
> In IntelliJ, I could control-click through from these methods right into the
> Lift source for them. I could not do this in NetBeans.
> I hope this helps.
> Thanks,
> David
>
>
>>
>>
>> I suspect the answer may involve implicit conversions or some other
>> bits of Scala magic that I simply don't understand yet, so I beg your
>> patience. If possible, a few breadcrumbs to explain non-obvious bits
>> of Scala the first time they are used might be helpful for Scala
>> newcomers, even just as a footnote.
>>
>> Aside from all the meta-questions: are these functions part of Lift
>> or part of the Scala XML libs? It might be worth mentioning what
>> each of these functions do since they're pretty essential to
>> understanding this code fragment and I think this is the first
>> fragment in the doc that does something other than declare a class /
>> table or deal with config stuff.
>>
>> -Antony
>>
>>
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Git some: http://github.com/dpp
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---