Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:58:43+00:00 2026-06-13T21:58:43+00:00

In Scala (2.9.2) I am trying to create a function that provides some other

  • 0

In Scala (2.9.2) I am trying to create a function that provides some other value when accessed

() => Any

I thought I was successfully doing this via a by name / currying solution:

def byName(theValue : => Any)() : Any = theValue
val myHolder = byName(myValue)_

So my holder is of the correct type. However I find that in the course of creating this curried function the by name parameter is evaluated. If I do the following instead it works as intended:

def byName(theValue : => Any) : Any = () => theValue
val myHolder = byName(myValue)

I conclude some part of the currying process is referencing the first parameter list and triggering its evaluation. Can anybody confirm that and/or explain why or if there are any guidelines around using by name parameters with multiple parameter lists?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:58:46+00:00Added an answer on June 13, 2026 at 9:58 pm

    This seems like a bug to me. I could trigger this strange behaviour in scala 2.9.1, but not in scala 2.10 RC1 so I guess this was fixed at some point.

    In scala 2.9.1:

    Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_27).
    Type in expressions to have them evaluated.
    Type :help for more information.
    scala> def byName(theValue : => Any)() : Any = theValue
    byName: (theValue: => Any)()Any
    scala> def myValue: String = { println("Computing myValue"); "hello" }
    myValue: String
    scala> val myHolder = byName(myValue)_
    Computing myValue
    myHolder: () => Any = <function0>
    scala> myHolder()
    res0: Any = hello
    

    In scala 2.10-RC1:

    Welcome to Scala version 2.10.0-RC1 (Java HotSpot(TM) Client VM, Java 1.6.0_27).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> def byName(theValue : => Any)() : Any = theValue
    byName: (theValue: => Any)()Any
    scala> def myValue: String = { println("Computing myValue"); "hello" }
    myValue: String
    scala> val myHolder = byName(myValue)_
    myHolder: () => Any = <function0>
    scala> myHolder()
    Computing myValue
    res0: Any = hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get this working in Scala: class MyClass(some: Int, func: AnyRef*
I'm trying to create a class that has a map of keys -> function
I am trying to run some Scala code on my OSX machine and keep
I'm trying to write some convenience functions in Scala for reading in arrays of
I am trying to compile a Maven Java/Scala mixed project that has a Scala
I'm trying to create an instance of a trait using this method val inst
I'm trying to create a fly-by-seat-of-pants sparse vector library in scala and I'm hitting
I'm trying to build a function that takes a PHP image resource and places
I'm trying to generate some sql that is used to calculate some final scores
I'm trying to create a simple chart that allows zoom capability and the examples

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.