This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Syntax for Early Definitions

2 replies
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

On Wed, Dec 17, 2008 at 05:16:21PM +0100, Ingo Maier wrote:
> That means that t1*3 is evaluated some time after t1. Please, don't let
> this get into a discussion about trait parameters. That is a separate
> issue we will discuss when we are ready.

I asked because I don't see them as separate issues. The most natural (or maybe more realistically the
least misleading) syntax should be influenced by the semantics. Especially as complicated as scala has
already become, trying to make these decisions serially and in isolation from one another is unlikely to
yield optimal results.

Szymon Jachim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Fwd: Syntax for Early Definitions
Telepathy? I sent the same proposition as to Anders  few minutes earlier....  :-D

---------- Forwarded message ----------
From: Szymon Jachim <sjachim [at] gmail [dot] com>
Date: Wed, Dec 17, 2008 at 7:30 PM
Subject: Re: [scala-debate] Syntax for Early Definitions
To: Anders Bach Nielsen <andersbach [dot] nielsen [at] epfl [dot] ch>


How about abusing "with" keyword?


with { ... } new { ... }       // for anonymous


class NotAnonymous with {
  ...
} extends T

My another proposition of the keyword is "initialized"...

On Wed, Dec 17, 2008 at 4:39 PM, Anders Bach Nielsen <andersbach [dot] nielsen [at] epfl [dot] ch> wrote:
Hey All

We are currently at LAMP working on updating the definitions of early
initialisers. These are currently described in section 5.1.6 in the SLS,
however this update involves a lot of changes to the syntax and the
semantics of early initialization of members. The thing we what to put
to a debate is the syntax for this.

Currently the syntax is like:

trait T {
 val x:String
 val y = "bar" + x
}

class Foo extends {
 val x = "baz"
} with T

To be able to properly initialize the trait T the value of x in Foo has
to be evaluated before the template of T is evaluated. We would like to
get rid of this syntax for the following reasons:

- a class can occur after a "with" (imagine T was a class).
- one would usually expect a type after an "extends"
- it is only an early block if there is a "with" afterwards:

 class Foo extends { ... }

 is actually equivalent to

 class Foo { ... }


One proposed syntax is:

trait T {
 val x:String
 val y = "bar" + x
}

class Foo preInit {
 val x = "baz"
} extends T

Here we mark the early initializer block with the preInit keyword. We
are not happy with that for two reasons:

- we'd like to avoid camel case keywords (suggestions for other keywords?)
- consequently, anonymous class instantiations would look like this:
 preInit { ... } new T { ... }
 It would be better to have the "new" at the begnning.

There is one more thing to consider. We are going to add constructor
parameters for traits in the future, which will be implemented with the
new early initializers. Suppose we have:

trait T1(t1: Int)
trait T2(t2: Int)
class A(a: Int) extends T1(a*2) with T2(-a)

In short, the order of evaluation would be

1.) evaluate constructor arguments for A
2.) evaluate early initializers of A (not present above)
3.) evaluate trait arguments bottom-up in the class linearization, i.e.
right to left syntactically
4.) call super constructor
5.) evaluate templates of base traits top-down in class linearization.

The relevant parts are 1-3. It might be more natural to have the early
initializers after the trait list, or, close to the template body. This
led us to the following syntax:

trait T {
 val x:String
 val y = "baz" + x
}

class Foo extends T {
 val x = "baz"
 super
 // normal template statements
}

Here the early initializers and normal template statements are put
together in the same block and separated by the super keyword. This will
not introduce a new keyword, but there is still the issue that early
initializers are evaluated under different conditions than the other
template statements.

Considering the points above, does anyone have syntax suggestions for
the new early initializers?

Anders & Ingo

--
Anders Bach Nielsen            |   http://www.daimi.au.dk/~abachn/
University of Aarhus           |   andersbach [dot] nielsen [at] epfl [dot] ch
-
 I'm shaving!! I'M SHAVING!!


Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Syntax for Early Definitions
Must be a good idea then!

On Dec 17, 2008, at 2:47 PM, "Szymon Jachim" <sjachim [at] gmail [dot] com> wrote:

Telepathy? I sent the same proposition as to Anders  few minutes earlier....  :-D

---------- Forwarded message ----------
From: Szymon Jachim <sjachim [at] gmail [dot] com (sjachim [at] gmail [dot] com" rel="nofollow">sjachim [at] gmail [dot] com)>
Date: Wed, Dec 17, 2008 at 7:30 PM
Subject: Re: [scala-debate] Syntax for Early Definitions
To: Anders Bach Nielsen <andersbach [dot] nielsen [at] epfl [dot] ch>


How about abusing "with" keyword?


with { ... } new { ... }       // for anonymous


class NotAnonymous with {
  ...
} extends T

My another proposition of the keyword is "initialized"...

On Wed, Dec 17, 2008 at 4:39 PM, Anders Bach Nielsen <andersbach [dot] nielsen [at] epfl [dot] ch> wrote:
Hey All

We are currently at LAMP working on updating the definitions of early
initialisers. These are currently described in section 5.1.6 in the SLS,
however this update involves a lot of changes to the syntax and the
semantics of early initialization of members. The thing we what to put
to a debate is the syntax for this.

Currently the syntax is like:

trait T {
 val x:String
 val y = "bar" + x
}

class Foo extends {
 val x = "baz"
} with T

To be able to properly initialize the trait T the value of x in Foo has
to be evaluated before the template of T is evaluated. We would like to
get rid of this syntax for the following reasons:

- a class can occur after a "with" (imagine T was a class).
- one would usually expect a type after an "extends"
- it is only an early block if there is a "with" afterwards:

 class Foo extends { ... }

 is actually equivalent to

 class Foo { ... }


One proposed syntax is:

trait T {
 val x:String
 val y = "bar" + x
}

class Foo preInit {
 val x = "baz"
} extends T

Here we mark the early initializer block with the preInit keyword. We
are not happy with that for two reasons:

- we'd like to avoid camel case keywords (suggestions for other keywords?)
- consequently, anonymous class instantiations would look like this:
 preInit { ... } new T { ... }
 It would be better to have the "new" at the begnning.

There is one more thing to consider. We are going to add constructor
parameters for traits in the future, which will be implemented with the
new early initializers. Suppose we have:

trait T1(t1: Int)
trait T2(t2: Int)
class A(a: Int) extends T1(a*2) with T2(-a)

In short, the order of evaluation would be

1.) evaluate constructor arguments for A
2.) evaluate early initializers of A (not present above)
3.) evaluate trait arguments bottom-up in the class linearization, i.e.
right to left syntactically
4.) call super constructor
5.) evaluate templates of base traits top-down in class linearization.

The relevant parts are 1-3. It might be more natural to have the early
initializers after the trait list, or, close to the template body. This
led us to the following syntax:

trait T {
 val x:String
 val y = "baz" + x
}

class Foo extends T {
 val x = "baz"
 super
 // normal template statements
}

Here the early initializers and normal template statements are put
together in the same block and separated by the super keyword. This will
not introduce a new keyword, but there is still the issue that early
initializers are evaluated under different conditions than the other
template statements.

Considering the points above, does anyone have syntax suggestions for
the new early initializers?

Anders & Ingo

--
Anders Bach Nielsen            |   http://www.daimi.au.dk/~abachn/
University of Aarhus           |   andersbach [dot] nielsen [at] epfl [dot] ch (andersbach [dot] nielsen [at] epfl [dot] ch" rel="nofollow">andersbach [dot] nielsen [at] epfl [dot] ch)
-
 I'm shaving!! I'M SHAVING!!


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