wood burning stoves 2.0*
The moose likes Scala and the fly likes A question on nested functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "A question on nested functions" Watch "A question on nested functions" New topic
Author

A question on nested functions

Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
I am a Java developer, learning Scala and I have just begun to look into nested functions. Whilst I understand the concept, I am still confused as to how they actually work in the code. Take my following example:



When I run this, I get no output whatsoever. Shouldn't the String I pass to the top method call be processed by both functions, and hence print out? Am I missing the bigger picture here?


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

You have declared the private function- lg(). But you need to invoke it to get executed.


Mohamed Sanaulla | My Blog
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
mohamed sanaullah wrote:You have declared the private function- lg(). But you need to invoke it to get executed.


It works now, many thanks. I can grasp the need to provide a call to lg, though when you say it is a private function I am confused. I'ts a local function object to the outer function, and despite being inaccessible to outside code (as in java) does this make it private as in the meaning of the access modifier? , I was under the impression that non declared access is public by default in Scala. unless otherwise declared. Hence, getMyName is public and that lg() is a local variable to it (within the inner scope only) and is simply implicitly inaccessible to code outside the getMyName function but not "private" as I have not declared it expressly so.

My question is more semantics than anything else, but I would like to clarify the situation.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Sorry for wrong usage of terms By private I meant- Local to that function- Scope limited to that function. Something like local variables.
 
Don't get me started about those stupid light bulbs.
 
subject: A question on nested functions
 
Similar Threads
def vs val
Very basic question regarding example on p135/136 of the GIA book
How to parse column data using select??
Critique Please
How to parse column data using select??