[scala] Named arguments separated by line-breaks?

View: New views
1 Messages — Rating Filter:   Alert me  

[scala] Named arguments separated by line-breaks?

by Sylvain HENRY-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I currently use this kind of code (for a raytracer):

val s = new Sphere {
    center = (20.0, 10.0, 0.0)
    radius = 5.0
    material = new MatteMaterial {
        color = Red
        diffuse = 1
        ambient = 1
     }
}

Where "center", "radius" and "material" are declared as vars in Sphere
class with default values. Same thing for "color", "diffuse" and
"ambient" in MatteMaterial.
With the coming named arguments, I thought I would replace these classes
by functions "sphere" and "matteMaterial" with appropriate named
arguments with default values. This way I could use vals instead of
vars, there would be no conflict between variables defined by users of
this ""DSL"" and internal vars/functions/... and I would have this syntax:

val s = sphere (
    center = (20.0, 10.0, 0.0),
    radius = 5.0,
    material = matteMaterial (
        color = Red,
        diffuse = 1,
        ambient = 1
     )
)

"new"s are dropped and this looks better. However, the question is:
would it be possible to drop ending commas by allowing named parameters
to be separated by a line break?
Or is there a better way to have a kind of POV-ray syntax?

Cheers,
Sylvain