- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: exponentiation operator
Thu, 2009-02-05, 21:24
Er, whoops, Haskell provides it.
2009/2/5 Ricky Clarkson <ricky.clarkson@gmail.com>
2009/2/5 Ricky Clarkson <ricky.clarkson@gmail.com>
Is that fact clearly explained in C, C++, Java, C#, Pascal, JavaScript, Haskell, etc., all of which don't provide it?
2009/2/5 Russ Paielli <russ.paielli@gmail.com>
The main problem with not having a standard exponentiation operator is that people just learning the language are confused. Since the ** operator is a de facto standard in many other languages, the lack of such an operator in Scala should be clearly explained in books and other reference material.
Now that I think about it, I realize that something like 99% of the time I raise a value to a power, the power is two. Squaring is by far the most common use of powers. Given that fact, I will just define a function for squaring. I'll call it "sqr," and I'll even suggest that it be added to the standard library. Well, maybe that could be mistaken for sqare root, so maybe it should be "square." I don't know.
A squaring function may actually be preferable to the pow function when the power is two, because it can just multiply rather than taking logs and antilogs. I don't know if pow is "smart" enough to just multiply when the power is two.
--Russ
On Thu, Feb 5, 2009 at 11:25 AM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
It would dramatically complicate parsing to do that.
2009/2/5 Russ Paielli <russ.paielli@gmail.com>I tried ~, and it doesn't work. I think the best choices are ~~, ~^, or #^. I agree, however, that none of these belong in the standard library.
Scala is very flexible and adaptable, but (as others have said) it would be nice if an operator's precedence could somehow be specified at the point of creation. I'll leave it to smarter people than me to decide if that is feasible and wise.
--Russ
On Thu, Feb 5, 2009 at 10:55 AM, Jon Pretty <jon.pretty@sygneca.com> wrote:
Colin Bullock wrote:
> Perhaps at this point (barring some mechanism for controlling
> precedence) the standard library should just stick with pow() and leave
> any special symbol up to users who deem them necessary/useful?
You're right. (And James Iry is especially right.) But what do we
normally do with stuff like this? Answer: stick it in a library and let
users import it if and only if they want to use it.
Not wishing to drag this out longer than it deserves (bit late for that,
maybe...), I'm personally still in favour of using ~ for exponentiation,
even if it does have another (quite different) meaning. Is there any
real problem overloading it (especially if it is only applicable within
the scope of the import).
Jon
--
Jon Pretty | Sygneca Ltd.
--
http://RussP.us
--
http://RussP.us
Fri, 2009-02-06, 00:37
#2
Re: exponentiation operator
>>>>> "Russ" == Russ Paielli writes:
>> FWIW I prefer /\ and \/ as per scalaz.BooleanW
Russ> No thanks. Too cryptic and not ASCII characters.
Let's change the subject. How are you liking the aspects of Scala that
are actually of any importance...?
Mon, 2009-02-09, 10:17
#3
RE: exponentiation operator
Sorry, was my fault. Should have avoided to reply to this
specific topic right in the beginning.
I understand that some repetitive discussions are annoying,
(like the one about the mail list configuration here, and
why I'm getting your answer to my mail twice ...).
BTW: Repetitive discussion about why repetitive discussion
is bad, thus keeping e.g. this thread alive but far more away
from topic is in no way better ...
I'll keep quiet now...
> -----Original Message-----
> From: Josh Suereth [mailto:joshua.suereth@gmail.com]
> Sent: Friday, February 06, 2009 8:04 PM
> To: David MacIver
> Cc: Detering Dirk; scala-user@listes.epfl.ch
> Subject: Re: [scala-user] exponentiation operator
>
> I think we should also reserve the "letmegooglethatforyou"
> website for incredibly silly questions or scala-debate (where
> it is ok to insult each other, as long as you add some smiley
> emoticons afterwards ).
>
>
> On Fri, Feb 6, 2009 at 12:23 PM, David MacIver
> wrote:
>
>
> Can you guys take this to scala-debate? It's best to
> confine annoying repetitive conversations about mathematical
> notation vs. natural language to there.
>
> Particularly after the first hundred or so times the
> damn argument has broken out.
>
>
>
>
Mon, 2009-02-09, 10:27
#4
Re: exponentiation operator
Yeah. Repetitive conversations happen on internet in people are human shocker.
Perhaps some of these conversations prevent repeated mistakes in language/library design.
2009/2/9 Detering Dirk <Dirk.Detering@bitmarck.de>
Perhaps some of these conversations prevent repeated mistakes in language/library design.
2009/2/9 Detering Dirk <Dirk.Detering@bitmarck.de>
Sorry, was my fault. Should have avoided to reply to this
specific topic right in the beginning.
I understand that some repetitive discussions are annoying,
(like the one about the mail list configuration here, and
why I'm getting your answer to my mail twice ...).
BTW: Repetitive discussion about why repetitive discussion
is bad, thus keeping e.g. this thread alive but far more away
from topic is in no way better ...
I'll keep quiet now...
> -----Original Message-----
> From: Josh Suereth [mailto:joshua.suereth@gmail.com]
> Sent: Friday, February 06, 2009 8:04 PM
> To: David MacIver
> Cc: Detering Dirk; scala-user@listes.epfl.ch
> Subject: Re: [scala-user] exponentiation operator
>
> I think we should also reserve the "letmegooglethatforyou"
> website for incredibly silly questions or scala-debate (where
> it is ok to insult each other, as long as you add some smiley
> emoticons afterwards ).
>
>
> On Fri, Feb 6, 2009 at 12:23 PM, David MacIver
> <david.maciver@gmail.com> wrote:
>
>
> Can you guys take this to scala-debate? It's best to
> confine annoying repetitive conversations about mathematical
> notation vs. natural language to there.
>
> Particularly after the first hundred or so times the
> damn argument has broken out.
>
>
>
>
I think you mistakenly addressed that to me instead of to the list. Unlike well-configured mailing list servers, Scala's doesn't set the reply-to address to be the mailing list[1].
Consider that you have written f(x) and realise that you want to square the result. Appending *f(x) might cause other results in an impure language, and is obviously a repetition. We can't fix it without going back to the f and typing "Math.pow(" and going to the end and adding ", 2)". It would be much less irritating to write and to read to have f(x) ^ 2, f(x).square, or f(x).pow(2).
Generally, the more nesting the reader has to keep in their head the harder the code is to understand.
[1] I will aggressively delete emails telling me how wrong I am on this. Computers should do stuff for me, not make me have to remember which of two very similar-looking buttons to press.
2009/2/5 Robert Fischer <robert.fischer@smokejumperit.com>