Array initialisation

J

Joshua Cranmer

Patricia said:
How do you define "near-numeric"? All values of BigDecimal are numbers,
but double has non-numeric values, so BigDecimal seems nearer to numeric
than double to me.

Near-numeric is a catch-all for anything that could subclass Number and
other non-mathematic types (matrices, rings, etc.)
Mixed type operations can create a lot of complications, so I would
rather favor no implicit conversion for the overloaded operators.

My personal opinion for how it could be done would be to have something
like this:

public interface Addable<Addend,Sum> {
public Sum add(Addend o);
}

This would, however, require reified generics to be able to inherent
from the same interface with different generic parameters.
Why not "%"?

Um... it slipped my mind.
 
L

Lars Enderin

Joshua Cranmer skrev:
It's a short, easy way to write code. It may be somewhat obfuscated, but
it is a shorthand for (presumably) common operations.

I can sort of see how '<<' works for output appending, and '+' for
string concatenation makes sense to me, except for the fact that it is
already heavily used (but I can't think of any other good operator to
use for that...)
That's why we decided to skip the operator when concatenating TEXT
expressions in Simula. We used juxtaposition, like
filepath := directory "/" file "." ext;
Simula, based on Algol 60, with classes and references, is one of the
first OO languages. It inspired Bjarne Stroustrup when he designed C++.
 
L

Lew

Alan said:
Java's + OTOH, bugs me. + is a very common operator and has a very
particular meaning and given Java's "operator overloading is bad, bad,
evil" stance it seems bizarre that they take a well known commutative
operator and give it a different, very common, usage that isn't commutative
and isn't visually distinct from the main one (plus the "auto convert
integers to strings unless they are the first item, in which case go
batshit" is annoying).

I suppose I get your objection to the overload of '+' for string catenation,
but it's so common and so well-established that I myself am not bothered by
it. What I do not understand is the "unless they are the first item, in which
case go batshit" reference. To what are you referring?
 
D

Daniel Pitts

Lew said:
I suppose I get your objection to the overload of '+' for string
catenation, but it's so common and so well-established that I myself am
not bothered by it. What I do not understand is the "unless they are
the first item, in which case go batshit" reference. To what are you
referring?
I think its "okay", but it would have been a better choice to introduce
a new operator. # comes to mind for some reason:

int fun = 3;
int guilt = 0;
String myString = fun # " times the fun. " # guilt # " times the guilt";
Now that I think about it, why hasn't # been used for any operator?
 
L

Lew

Daniel said:
I think its "okay", but it would have been a better choice to introduce
a new operator. # comes to mind for some reason:

int fun = 3;
int guilt = 0;
String myString = fun # " times the fun. " # guilt # " times the guilt";
Now that I think about it, why hasn't # been used for any operator?

But what is all this about "unless they are the first item ... batshit"?
 
M

Mike Schilling

Lew said:
But what is all this about "unless they are the first item ...
batshit"?

Perhaps that

2 + 4 + " is the answer"

works very differently from

"The answer is " + 2 + 4.

I like Daniels' suggestion;. It's very clear that both operands must be
converted to a string value (except for the ones that are already declared
as strings, of course.).
 
D

Daniel Pitts

Lew said:
But what is all this about "unless they are the first item ... batshit"?
I don't know, that wasn't me.

Although, I suspect the problem is in this case:
int foo = 1, bar = 2;
String s = foo + bar + "3";

The output is 33, where as using a different operator would prevent that
ambiguity.
String s = foo#bar#"3"; // 123
 
D

Daniel Pitts

Lew said:
But what is all this about "unless they are the first item ... batshit"?
I don't know, that wasn't me.

Although, I suspect the problem is in this case:
int foo = 1, bar = 2;
String s = foo + bar + "3";

The output is 33, where as using a different operator would prevent that
ambiguity.
String s = foo#bar#"3"; // 123
 
G

George Neuner

I think its "okay", but it would have been a better choice to introduce
a new operator. # comes to mind for some reason:

int fun = 3;
int guilt = 0;
String myString = fun # " times the fun. " # guilt # " times the guilt";
Now that I think about it, why hasn't # been used for any operator?

Because traditionally # and $ were used for substitution parameters in
scripting languages.

George
 
G

George Neuner

Because traditionally # and $ were used for substitution parameters in
scripting languages.

Forgot % and @ which are also used by scripting languages

George
 
J

John W. Kennedy

Lew said:
I suppose I get your objection to the overload of '+' for string
catenation, but it's so common and so well-established that I myself am
not bothered by it. What I do not understand is the "unless they are
the first item, in which case go batshit" reference. To what are you
referring?

The only language I can think of offhand with a completely unique
concatenation operator is PL/I, which uses "||" for concatenation and
nothing else.

--
John W. Kennedy
"Though a Rothschild you may be
In your own capacity,
As a Company you've come to utter sorrow--
But the Liquidators say,
'Never mind--you needn't pay,'
So you start another company to-morrow!"
-- Sir William S. Gilbert. "Utopia Limited"
 
L

Lew

John said:
The only language I can think of offhand with a completely unique
concatenation operator is PL/I, which uses "||" for concatenation and
nothing else.

There is a language that indicates concatenation by a lack of any operator -
simply separating terms by blanks imputes concatenation - SNOBOL.
 
W

Wayne

Lew said:
There is a language that indicates concatenation by a lack of any
operator - simply separating terms by blanks imputes concatenation -
SNOBOL.

*grin*

I was going to post that, I even found my old SNOBOL4 programming language
manual to check it. But I thought "who beside me has ever heard of
SNOBOL?" and canceled my post.

SNOBOL was fun, I miss it.

Modern C uses a restricted version of this, for string literals.

-Wayne
 
O

Owen Jacobson

The only language I can think of offhand with a completely unique
concatenation operator is PL/I, which uses "||" for concatenation and
nothing else.

SQL-as-specified has the same property, right down to the operator
chosen. Haskell also has a unique list concatenation operator, which
covers strings since they're lists too, but I believe you can provide
other meanings for ++ within modules, so it may not count.
-o
 
P

Patricia Shanahan

Wayne said:
*grin*

I was going to post that, I even found my old SNOBOL4 programming language
manual to check it. But I thought "who beside me has ever heard of
SNOBOL?" and canceled my post.

SNOBOL was fun, I miss it.

Same here.

Patricia
 
M

Martin Gregorie

Lew said:
There is a language that indicates concatenation by a lack of any
operator - simply separating terms by blanks imputes concatenation -
SNOBOL.
There's a current scripting language that does this: awk
 
C

Curt Welch

Wayne said:
*grin*

I was going to post that, I even found my old SNOBOL4 programming
language manual to check it. But I thought "who beside me has ever heard
of SNOBOL?" and canceled my post.

There are other old guys here. I was taught SNOBOL when I got my CS degree
back in the 70's. It was so long ago however and I remember so little of
it that I didn't even think about it while I was reading this thread.

+ for string concatenation is as old as the hills. I used it in a language
I created back in the late 70's. I can't remember were I first saw it. It
does create a bit of confusion in Java but it's minor and doesn't bother
me. If you wanted a different operator to overload I'd pick |. It would
create less confusion because the typical context in which you use OR is
different from the context in which you would use string concatenation.
Other options would be !, or @, or #. If you wanted to look at multiple
characters, .. would be a good one, as well as ,, or // or \\ or ><.
There's really no end to the options.
 
D

Daniel Pitts

George said:
Because traditionally # and $ were used for substitution parameters in
scripting languages.
What's that have to do with anything? # was used in C/C++ as a
preprocessor directive marker, and in BASH script to denote comments.
Why should the syntax of a language be restricted by the syntax of a
completely unrelated language?
 
D

Daniel Pitts

Lew said:
There is a language that indicates concatenation by a lack of any
operator - simply separating terms by blanks imputes concatenation -
SNOBOL.
PHP uses . for concatenation. I think perl does too, doesn't it?
 
J

John W. Kennedy

Lew said:
There is a language that indicates concatenation by a lack of any
operator - simply separating terms by blanks imputes concatenation -
SNOBOL.

REXX partially allows that.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,299
Latest member
JewelDeLaC

Latest Threads

Top