This page is no longer maintained — Please continue to the home page at

Re: Disambiguating a parameter name

No replies
Ken Scambler
Joined: 2009-11-07,
User offline. Last seen 42 years 45 weeks ago.
Thanks Naftoli.  (back on list, oops) :)

Hmm, still seems awkward though, having to have a dodgy parameter name as a first class part of a class' API.  I suppose I can live with it though.


On 9 February 2012 14:04, Naftoli Gugenheim <naftoligug [at] gmail [dot] com> wrote:
You replied off list, but anyway I think there are two conventions used, to name the constructor parameter either _theRealName or theRealName0.

On Wednesday, February 8, 2012, Ken Scambler wrote:
Well, I was using by-name parameters and lazy vals to allow a bunch of immutable structures to bootstrap themselves in one pass.   This demonstrates the issue:

class MyClass(theFooby: => Something) {
  lazy val fooby: Something = theFooby

  // everything else can use fooby; theFooby should not be run more than once.


On 9 February 2012 13:51, Naftoli Gugenheim <naftoligug [at] gmail [dot] com> wrote:
What is the situation that involves a constructor?

On Wednesday, February 8, 2012, Ken Scambler wrote:
That's a good thought, thanks Naftoli.  It doesn't work (nicely) for constructor parameters though; the extra def or val would be a member rather than a temporary variable.

On 9 February 2012 10:52, Naftoli Gugenheim <naftoligug [at] gmail [dot] com> wrote:
What I've done sometimes is:
def createX(y: String): X = {  def tmp = y  new X {
    def y: String = tmp

On Tuesday, February 7, 2012, Ken Scambler wrote:
I often find myself with the problem of disambiguating a parameter name against a class member of the same name:

trait Foo { def bar: String }

def createFoo(theBar: String): Foo = new Foo {
  def bar: String = theName
Here I've added a meaningless syllable to the parameter name to make it unique.  However, since the "named parameters" feature makes parameter names part of the external API of a class, I really don't want to do this.   Also we're assuming here that we want to keep Foo as a trait, and not make it a class with a constructor.

Is there a way around this without picking silly names?  There seems no way to specify the parameter over the member.


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland