Thankyou all for your posts, I now understand whats going on !
Victor : Thanks for the great examples of how to pass functions into
other functions - a very illuminating example, I'm sitting here
thinking about how much that will make a difference to code
conciseness compared with Java !
David :
I think the difference is only true in a class body. Inside a code block I
think the def is syntactic sugar for the other syntax.
-
Viktor Klang wrote:
On Thu, Jul 30, 2009 at 11:02 PM, DFectuoso wrote:
>
> Viktor, that was a great explanation, im sure ben
On Thu, Jul 30, 2009 at 2:02 PM, DFectuoso wrote:
>
> Viktor, that was a great explanation, im sure ben will apraciate that
> kind of teaching =)
>
> A follow up question that just made me wonder, what is the diference
> between
>
> val square = (x : Int) => x * x
> and
> def square(x:Int):Int =
On Thu, Jul 30, 2009 at 12:37 PM, ben wrote:
>
> Hi,
>
> I feel I must apologise for this post ... I've only been doing scala
> for a week, and lift for 3 days, but I'm stuck.
> I'm coming from an experienced java background, just struggling with
> some scala constructs.
>
> I feel I understand
But you can also create and pass a function inline:
scala> doMath(1,2,(a : Int, b : Int) => a ^ b)
res5: Int = 3
On Thu, Jul 30, 2009 at 11:43 PM, Viktor Klang wrote:
> Here's a short example:
>
> val add = (a : Int, b : Int) => a + b
> val sub = (a : Int, b : Int) => a - b
> val div = (a : Int
Here's a short example:
val add = (a : Int, b : Int) => a + b
val sub = (a : Int, b : Int) => a - b
val div = (a : Int, b : Int) => a / b
val mul = (a : Int, b : Int) => a * b
//This is a method that takes an Int a, an Int b and a function that takes 2
Ints and produces an Int
def doMath(a : Int,
Hi,
Thanks for patience (and for the interesting subpost on the diff
between val & def) !
OK, the callback thing you suggested is starting to clear the mist ...
I found this article :
http://www.ibm.com/developerworks/java/library/j-scala01228.html
I've not had time to read it fully yet, as its
(If I've understood your question correctly)
the definition of ajaxText is as follows:
def ajaxText(value: String, func: String => JsCmd): Elem =
ajaxText_*(value, Empty, SFuncHolder(func))
So what you're doing is that you're sending a callback function to ajaxText,
and it will be called with
Hi Viktor,
Thanks for your reply.
I do understand the simple examples, like the one you were kind enough
to post.
My problem is that I just can't seem to break through from the simple
examples to the code in the "Getting Started" tutorial
To elaborate, given the following in a scala conso
On Thu, Jul 30, 2009 at 11:02 PM, DFectuoso wrote:
>
> Viktor, that was a great explanation, im sure ben will apraciate that
> kind of teaching =)
Well, thank you.
>
>
> A follow up question that just made me wonder, what is the diference
> between
>
> val square = (x : Int) => x * x
>
This
Viktor, that was a great explanation, im sure ben will apraciate that
kind of teaching =)
A follow up question that just made me wonder, what is the diference
between
val square = (x : Int) => x * x
and
def square(x:Int):Int = x * x
?
On Jul 30, 1:49 pm, Viktor Klang wrote:
> Hello Ben!
>
>
Hello Ben!
the following:
val square = (x:Int) => x * x
"val square" is the equivalent of a "final" reference in Java.
(x : Int) => x * x
This constructs a Function instance that takes an Int and returns that Int
squared.
The equivalent Java code would be something like:
interface Function /
12 matches
Mail list logo