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

Newbie for sure(1st day)

3 replies
BoxHead
Joined: 2012-01-06,
User offline. Last seen 43 weeks 3 days ago.

This is a 1st day question but I've wasted much to much time on it.

I can't use StringOps "product". I can use other "value members" like
indexOf. I can create my own product function. I just can't get
stringOps product to work. I've tried a dozen ways. Also, I can't find
1 example of the function in use.

Could someone provide a simple example that I can plug into the
Interpreter. Thanks in advance.

Tom Switzer
Joined: 2011-07-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Newbie for sure(1st day)
(sending again cause I forgot to cc list)
Product is analogous to sum, but for multiplication. It is actually not unique to StringOps, but is available on most collections. It doesn't make too much sense with Strings, but consider a list of Ints or a Set of Doubles.
scala> Seq(4,6,11).productres1: Int = 264
scala> 1.0 to 2.0 by 0.2 productres2: Double = 9.676799999999997

On Thu, Jan 5, 2012 at 11:04 PM, <sporter99 [at] msn [dot] com> wrote:
This is a 1st day question but I've wasted much to much time on it.

I can't use StringOps "product". I can use other "value members" like
indexOf. I can create my own product function. I just can't get
stringOps product to work. I've tried a dozen ways. Also, I can't find
1 example of the function in use.

Could someone provide a simple example that I can plug into the
Interpreter. Thanks in advance.

Tom Switzer
Joined: 2011-07-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Newbie for sure(1st day)

s/Set/Range/

On 2012-01-06 12:05 AM, "Tom Switzer" <thomas [dot] switzer [at] gmail [dot] com> wrote:
>
> (sending again cause I forgot to cc list)
>
> Product is analogous to sum, but for multiplication. It is actually not unique to StringOps, but is available on most collections. It doesn't make too much sense with Strings, but consider a list of Ints or a Set of Doubles.
>
> scala> Seq(4,6,11).product
> res1: Int = 264
>
> scala> 1.0 to 2.0 by 0.2 product
> res2: Double = 9.676799999999997
>
>
> On Thu, Jan 5, 2012 at 11:04 PM, <sporter99 [at] msn [dot] com> wrote:
>>
>> This is a 1st day question but I've wasted much to much time on it.
>>
>> I can't use StringOps "product". I can use other "value members" like
>> indexOf. I can create my own product function. I just can't get
>> stringOps product to work. I've tried a dozen ways. Also, I can't find
>> 1 example of the function in use.
>>
>> Could someone provide a simple example that I can plug into the
>> Interpreter. Thanks in advance.
>
>

Seth Tisue
Joined: 2008-12-16,
User offline. Last seen 34 weeks 3 days ago.
Re: Newbie for sure(1st day)

On Thu, Jan 5, 2012 at 11:04 PM, wrote:
> This is a 1st day question but I've wasted much to much time on it.
>
> I can't use StringOps "product". I can use other "value members" like
> indexOf. I can create my own product function. I just can't get
> stringOps product to work. I've tried a dozen ways. Also, I can't find
> 1 example of the function in use.
>
> Could someone provide a simple example that I can plug into the
> Interpreter. Thanks in advance.

What are you wanting product to do on a String?

It does do something, just a weird useless something:

scala> "abc".product
res0: Char = ?

scala> "abc".product.toInt
res1: Int = 23590

scala> (('a' * 'b').toChar * 'c').toChar
res3: Char = ?

scala> (('a' * 'b').toChar * 'c').toChar.toInt
res2: Int = 23590

It's an unfortunate consequence of Char being a numeric type, as in
Java and C tradition. So you can multiply two of them together.

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