sean.mcdirmid | 1 Jan 2008 01:17
Picon
Picon
Favicon

Re: Testing strings for equality

I think the reverse result is a projection, not a rich
string. Projections are efficient to compute (reverse
of a string is O(1)), but their methods only support
sequence equality. Because == is basically untyped, 
there is no way to trigger an implicit coercion that
would raise the other string to a rich string, and
cause the equality to be true.

Your solution works, 

"lava".reverse == ("laval" : RichString)

would also probably work. 

This is a fundamental limitation of using 
implicit coercions to extend existing 
classes with new functionality.

Sean

Quoting Oscar Picasso <oscarpicasso <at> gmail.com>:

> Hi,
> 
> I'm trying to find out to test the following for equality:
> "laval"
> and
> "laval".reverse
> 
> It should return true. However if test:
(Continue reading)

Andrew Foggin | 1 Jan 2008 16:56

Encoding properties and more

Happy New Year Scalars!

Consider the following trait:

  trait Property[T] {
    protected var _value : T = _

    implicit def value : T = _value

    implicit def value_=(newValue : T) {
      _value = newValue
    }
  }

If a definition like this:

  class Foo {
    object Bar extends Property[String]
  }

could be expanded by automatically adding methods that corresponded to 
the object name like this:

  class Foo {
    object Bar extends Property[String]
    def bar : String = Bar.value
    def bar_=(newValue : String) = Bar.value_=(newValue)
  }

then we might have a workable syntax for properties and maybe other 
(Continue reading)

Viktor Klang | 1 Jan 2008 19:57
Picon

Re: Encoding properties and more

Hey Andrew,

checked it out a bit and I have some questions.

1) How does one iterate over all properties contained withing type X?
2) How does one set the value of Property Y when passed a reference to property Y and a reference to type X (which is the enclosing type of Y)?
3) What is the actual type of a property? I.e. considering:

class Foo
{
    object Bar extends Property[String]
}

Is Bar a Property[Foo,String]?
Or a FooProperty[String]?

(This question arises if someone wants to create a method/function that only accepts Properties on Foos)

And I think we'd need syntactic sugar for this.
It's _not_ Beginner friendly to define a property as an object.
A property is a property and should be declared as one.

class Foo
{
   property Name : String // == object Name extends Property[Foo,String] + the probably needed getter/setter methods
}

Feedback?

Cheers,
Viktor

On Jan 1, 2008 4:56 PM, Andrew Foggin <andy <at> foggin.net> wrote:
Happy New Year Scalars!

Consider the following trait:

 trait Property[T] {
   protected var _value : T = _

   implicit def value : T = _value

   implicit def value_=(newValue : T) {
     _value = newValue
   }
 }

If a definition like this:

 class Foo {
   object Bar extends Property[String]
 }

could be expanded by automatically adding methods that corresponded to
the object name like this:

 class Foo {
   object Bar extends Property[String]
   def bar : String = Bar.value
   def bar_=(newValue : String) = Bar.value_=(newValue)
 }

then we might have a workable syntax for properties and maybe other
things too.  Here's the same example with a default value and an
overridden setter:

 class Foo {
   object Bar extends Property[String] {
     value = "Hello World!"

     override def value_=(newValue : String) {
        super.value = newValue
        println("Value changed to " + newValue)
     }
   }
 }


Fatally flawed or worth further consideration?

Regards,

Andrew Foggin



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/
Oscar Picasso | 1 Jan 2008 20:49
Picon

Stackoverflow

Hi,

The following works fine:
(for(x <- 100 to 999; y <- x to 999) yield x * y).filter(_ % 2 == 0)

But this throws a StackOverflowError:
 (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) => a.toString.reverse.mkString == a.toString)

Why?

Daniel Green | 1 Jan 2008 20:55
Picon
Gravatar

Re: Stackoverflow

Works for me:

daniel <at> octobertop:~$ uname -a
Linux octobertop 2.6.20-16-generic #2 SMP Sun Sep 23 18:31:23 UTC 2007
x86_64 GNU/Linux
daniel <at> octobertop:~$ scala
Welcome to Scala version 2.6.0-final.
....
scala> (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
a.toString.reverse.mkString == a.toString)
res0: Seq.Projection[Int] = RangeGF(10201, 11211, 12221, 13231, 14241,
15251, 16261, 17271, 18281, 19291, 20402, 21412, 22422, 23432, 24442,
25452, 26462, 27472, 28482, 29492, 30603, 31613, 32623, 33633, 34643,
35653, 36663, 37673, 38683, 39693, 40804, 41814, 42824, 43834, 44844,
45854, 46864, 47874, 48884, 49894, 20502, 21012, 41514, 42024, 62526,
63036, 83538, 84048, 21012, 26162, 4...

On Jan 1, 2008 2:49 PM, Oscar Picasso <oscarpicasso <at> gmail.com> wrote:
> Hi,
>
> The following works fine:
> (for(x <- 100 to 999; y <- x to 999) yield x * y).filter(_ % 2 == 0)
>
> But this throws a StackOverflowError:
>  (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
> a.toString.reverse.mkString == a.toString)
>
> Why?
>

Viktor Klang | 1 Jan 2008 21:40
Picon

Re: Encoding properties and more

Addendum:

3) And how do they interact with constructors?

i:e

class Foo
{
    property Bar : String
    property Baz : Int
}

val f : Foo = new Foo(Bar = "wawawowa", Baz = "Yeehaw") ?

Cheers,
-Viktor

On Jan 1, 2008 7:57 PM, Viktor Klang <viktor.klang <at> gmail.com> wrote:
Hey Andrew,

checked it out a bit and I have some questions.

1) How does one iterate over all properties contained withing type X?
2) How does one set the value of Property Y when passed a reference to property Y and a reference to type X (which is the enclosing type of Y)?
3) What is the actual type of a property? I.e. considering:


class Foo
{
    object Bar extends Property[String]
}

Is Bar a Property[Foo,String]?
Or a FooProperty[String]?

(This question arises if someone wants to create a method/function that only accepts Properties on Foos)

And I think we'd need syntactic sugar for this.
It's _not_ Beginner friendly to define a property as an object.
A property is a property and should be declared as one.

class Foo
{
   property Name : String // == object Name extends Property[Foo,String] + the probably needed getter/setter methods
}

Feedback?

Cheers,
Viktor


On Jan 1, 2008 4:56 PM, Andrew Foggin <andy <at> foggin.net > wrote:
Happy New Year Scalars!

Consider the following trait:

 trait Property[T] {
   protected var _value : T = _

   implicit def value : T = _value

   implicit def value_=(newValue : T) {
     _value = newValue
   }
 }

If a definition like this:

 class Foo {
   object Bar extends Property[String]
 }

could be expanded by automatically adding methods that corresponded to
the object name like this:

 class Foo {
   object Bar extends Property[String]
   def bar : String = Bar.value
   def bar_=(newValue : String) = Bar.value_=(newValue)
 }

then we might have a workable syntax for properties and maybe other
things too.  Here's the same example with a default value and an
overridden setter:

 class Foo {
   object Bar extends Property[String] {
     value = "Hello World!"

     override def value_=(newValue : String) {
        super.value = newValue
        println("Value changed to " + newValue)
     }
   }
 }


Fatally flawed or worth further consideration?

Regards,

Andrew Foggin



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/
Daniel Green | 1 Jan 2008 21:46
Picon
Gravatar

Re: Stackoverflow

daniel <at> octobertop:~$ java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)

Although I'm not sure if Scala is using it or not....

On Jan 1, 2008 3:34 PM, Oscar Picasso <oscarpicasso <at> gmail.com> wrote:
> I found the problem. I used java 1.6.
>
> It works fine with java 1.5.
>
> Is scala supposed to support java 1.6?
>
>
>
> On Jan 1, 2008 2:55 PM, Daniel Green < octoberdan <at> gmail.com> wrote:
> > Works for me:
> >
> > daniel <at> octobertop:~$ uname -a
> > Linux octobertop 2.6.20-16-generic #2 SMP Sun Sep 23 18:31:23 UTC 2007
> > x86_64 GNU/Linux
> > daniel <at> octobertop:~$ scala
> > Welcome to Scala version 2.6.0-final.
> > ....
> > scala> (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
> >
> > a.toString.reverse.mkString == a.toString)
> > res0: Seq.Projection[Int] = RangeGF(10201, 11211, 12221, 13231, 14241,
> > 15251, 16261, 17271, 18281, 19291, 20402, 21412, 22422, 23432, 24442,
> > 25452, 26462, 27472, 28482, 29492, 30603, 31613, 32623, 33633, 34643,
> > 35653, 36663, 37673, 38683, 39693, 40804, 41814, 42824, 43834, 44844,
> > 45854, 46864, 47874, 48884, 49894, 20502, 21012, 41514, 42024, 62526,
> > 63036, 83538, 84048, 21012, 26162, 4...
> >
> >
> >
> >
> > On Jan 1, 2008 2:49 PM, Oscar Picasso <oscarpicasso <at> gmail.com> wrote:
> > > Hi,
> > >
> > > The following works fine:
> > > (for(x <- 100 to 999; y <- x to 999) yield x * y).filter(_ % 2 == 0)
> > >
> > > But this throws a StackOverflowError:
> > >  (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
> > > a.toString.reverse.mkString == a.toString)
> > >
> > > Why?
> > >
> >
>
>

Viktor Klang | 1 Jan 2008 21:47
Picon

Re: Encoding properties and more

Addendum 2:

So I guess this boils it down to my feature list for properties:

1) Intuitive syntax: i.e "property X of type Y"
2) instance-access: i.e. (new Foo).name
3) static-access: i.e. Foo.Name or Foo.name
4) instance-read: i.e. val s = (new Foo).name
5) static-read: i.e. Foo.Name or Foo.name.get(new Foo)
6) instance-write: i.e. (new Foo).name = "wawawowa"
7) static-write: i.e. Foo.Name.set(new Foo, "wawawowa")
8) instance-enumeration: (new Foo).properties
9) static-enumeration: Foo.properties
10) seamless integration with constructors: i.e. new Foo(Name = "wawawowa", Bar = "Yeehaw")
11) ability to extrapolate information from properties like the type of the value that it holds, it's name, it's validator etc
12) ability to tie metadata to properties, iether though annotations or other means (mixins etc)

I've probably forgot something here so I'll reserve the rights to go back and add stuff here. :)

Discuss!

Cheers,
Viktor

On Jan 1, 2008 9:40 PM, Viktor Klang < viktor.klang <at> gmail.com> wrote:
Addendum:

3) And how do they interact with constructors?

i:e

class Foo
{
    property Bar : String
    property Baz : Int
}

val f : Foo = new Foo(Bar = "wawawowa", Baz = "Yeehaw") ?

Cheers,
-Viktor


On Jan 1, 2008 7:57 PM, Viktor Klang < viktor.klang <at> gmail.com> wrote:
Hey Andrew,

checked it out a bit and I have some questions.

1) How does one iterate over all properties contained withing type X?
2) How does one set the value of Property Y when passed a reference to property Y and a reference to type X (which is the enclosing type of Y)?
3) What is the actual type of a property? I.e. considering:


class Foo
{
    object Bar extends Property[String]
}

Is Bar a Property[Foo,String]?
Or a FooProperty[String]?

(This question arises if someone wants to create a method/function that only accepts Properties on Foos)

And I think we'd need syntactic sugar for this.
It's _not_ Beginner friendly to define a property as an object.
A property is a property and should be declared as one.

class Foo
{
   property Name : String // == object Name extends Property[Foo,String] + the probably needed getter/setter methods
}

Feedback?

Cheers,
Viktor


On Jan 1, 2008 4:56 PM, Andrew Foggin <andy <at> foggin.net > wrote:
Happy New Year Scalars!

Consider the following trait:

 trait Property[T] {
   protected var _value : T = _

   implicit def value : T = _value

   implicit def value_=(newValue : T) {
     _value = newValue
   }
 }

If a definition like this:

 class Foo {
   object Bar extends Property[String]
 }

could be expanded by automatically adding methods that corresponded to
the object name like this:

 class Foo {
   object Bar extends Property[String]
   def bar : String = Bar.value
   def bar_=(newValue : String) = Bar.value_=(newValue)
 }

then we might have a workable syntax for properties and maybe other
things too.  Here's the same example with a default value and an
overridden setter:

 class Foo {
   object Bar extends Property[String] {
     value = "Hello World!"

     override def value_=(newValue : String) {
        super.value = newValue
        println("Value changed to " + newValue)
     }
   }
 }


Fatally flawed or worth further consideration?

Regards,

Andrew Foggin



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/
Daniel Green | 1 Jan 2008 22:18
Picon
Gravatar

Re: Stackoverflow

By the way, really cool code.

On Jan 1, 2008 3:46 PM, Daniel Green <octoberdan <at> gmail.com> wrote:
> daniel <at> octobertop:~$ java -version
> java version "1.6.0_03"
> Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)
>
> Although I'm not sure if Scala is using it or not....
>
>
> On Jan 1, 2008 3:34 PM, Oscar Picasso <oscarpicasso <at> gmail.com> wrote:
> > I found the problem. I used java 1.6.
> >
> > It works fine with java 1.5.
> >
> > Is scala supposed to support java 1.6?
> >
> >
> >
> > On Jan 1, 2008 2:55 PM, Daniel Green < octoberdan <at> gmail.com> wrote:
> > > Works for me:
> > >
> > > daniel <at> octobertop:~$ uname -a
> > > Linux octobertop 2.6.20-16-generic #2 SMP Sun Sep 23 18:31:23 UTC 2007
> > > x86_64 GNU/Linux
> > > daniel <at> octobertop:~$ scala
> > > Welcome to Scala version 2.6.0-final.
> > > ....
> > > scala> (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
> > >
> > > a.toString.reverse.mkString == a.toString)
> > > res0: Seq.Projection[Int] = RangeGF(10201, 11211, 12221, 13231, 14241,
> > > 15251, 16261, 17271, 18281, 19291, 20402, 21412, 22422, 23432, 24442,
> > > 25452, 26462, 27472, 28482, 29492, 30603, 31613, 32623, 33633, 34643,
> > > 35653, 36663, 37673, 38683, 39693, 40804, 41814, 42824, 43834, 44844,
> > > 45854, 46864, 47874, 48884, 49894, 20502, 21012, 41514, 42024, 62526,
> > > 63036, 83538, 84048, 21012, 26162, 4...
> > >
> > >
> > >
> > >
> > > On Jan 1, 2008 2:49 PM, Oscar Picasso <oscarpicasso <at> gmail.com> wrote:
> > > > Hi,
> > > >
> > > > The following works fine:
> > > > (for(x <- 100 to 999; y <- x to 999) yield x * y).filter(_ % 2 == 0)
> > > >
> > > > But this throws a StackOverflowError:
> > > >  (for(x <- 100 to 999; y <- x to 999) yield x * y).filter((a) =>
> > > > a.toString.reverse.mkString == a.toString)
> > > >
> > > > Why?
> > > >
> > >
> >
> >
>

Carsten Saager | 1 Jan 2008 22:26
Picon

Re: Encoding properties and more

If Property is an inner trait  of  a trait Properties which has to be extended by the "bean" it is possible to enumerate the properties of an object. The Properties trait is anyway useful to hold the interface for the listener on the properties.

Looking at your feature list I wonder if such a large extension to the language is really the right way to do it. Instead of forcing Scala to be something it isn't, it might be reasonable to ask if there is another programming model that doesn't need the notion of properties - not that I have a compelling idea already - it is just a feeling.

As well the Victor-properties are missing the notification facilities which are very important for the JavaBean folks. And the static access - even after looking at it for some days now, it is still weird, but this is perhaps just me.

One thing I find very important with properties is "fidelity":
synchronized {
  x.name="Hallo"
  assert("Hallo"==x.name)
}

The main criticism in simple assignment syntax is always that the user can't know if name_= might modify the value before doing the actual assingment.

On Jan 1, 2008 9:47 PM, Viktor Klang <viktor.klang <at> gmail.com> wrote:
Addendum 2:

So I guess this boils it down to my feature list for properties:

1) Intuitive syntax: i.e "property X of type Y"
2) instance-access: i.e. (new Foo).name
3) static-access: i.e. Foo.Name or Foo.name
4) instance-read: i.e. val s = (new Foo).name
5) static-read: i.e. Foo.Name or Foo.name.get(new Foo)
6) instance-write: i.e. (new Foo).name = "wawawowa"
7) static-write: i.e. Foo.Name.set(new Foo, "wawawowa")
8) instance-enumeration: (new Foo).properties
9) static-enumeration: Foo.properties
10) seamless integration with constructors: i.e. new Foo(Name = "wawawowa", Bar = "Yeehaw")
11) ability to extrapolate information from properties like the type of the value that it holds, it's name, it's validator etc
12) ability to tie metadata to properties, iether though annotations or other means (mixins etc)

I've probably forgot something here so I'll reserve the rights to go back and add stuff here. :)

Discuss!

Cheers,
Viktor


On Jan 1, 2008 9:40 PM, Viktor Klang < viktor.klang <at> gmail.com> wrote:
Addendum:

3) And how do they interact with constructors?

i:e

class Foo
{
    property Bar : String
    property Baz : Int
}

val f : Foo = new Foo(Bar = "wawawowa", Baz = "Yeehaw") ?

Cheers,
-Viktor


On Jan 1, 2008 7:57 PM, Viktor Klang < viktor.klang <at> gmail.com> wrote:
Hey Andrew,

checked it out a bit and I have some questions.

1) How does one iterate over all properties contained withing type X?
2) How does one set the value of Property Y when passed a reference to property Y and a reference to type X (which is the enclosing type of Y)?
3) What is the actual type of a property? I.e. considering:


class Foo
{
    object Bar extends Property[String]
}

Is Bar a Property[Foo,String]?
Or a FooProperty[String]?

(This question arises if someone wants to create a method/function that only accepts Properties on Foos)

And I think we'd need syntactic sugar for this.
It's _not_ Beginner friendly to define a property as an object.
A property is a property and should be declared as one.

class Foo
{
   property Name : String // == object Name extends Property[Foo,String] + the probably needed getter/setter methods
}

Feedback?

Cheers,
Viktor


On Jan 1, 2008 4:56 PM, Andrew Foggin <andy <at> foggin.net > wrote:
Happy New Year Scalars!

Consider the following trait:

 trait Property[T] {
   protected var _value : T = _

   implicit def value : T = _value

   implicit def value_=(newValue : T) {
     _value = newValue
   }
 }

If a definition like this:

 class Foo {
   object Bar extends Property[String]
 }

could be expanded by automatically adding methods that corresponded to
the object name like this:

 class Foo {
   object Bar extends Property[String]
   def bar : String = Bar.value
   def bar_=(newValue : String) = Bar.value_=(newValue)
 }

then we might have a workable syntax for properties and maybe other
things too.  Here's the same example with a default value and an
overridden setter:

 class Foo {
   object Bar extends Property[String] {
     value = "Hello World!"

     override def value_=(newValue : String) {
        super.value = newValue
        println("Value changed to " + newValue)
     }
   }
 }


Fatally flawed or worth further consideration?

Regards,

Andrew Foggin



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



--
_____________________________________
/                                                                 \
       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



--
_____________________________________
/                                                                 \

       /lift/ committer ( www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/



Gmane