File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on nested functions

 
Stephen Davies
Ranch Hand
Posts: 352
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have declared the private function- lg(). But you need to invoke it to get executed.
 
Stephen Davies
Ranch Hand
Posts: 352
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for wrong usage of terms By private I meant- Local to that function- Scope limited to that function. Something like local variables.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic