www.digitalmars.com         C & C++   DMDScript  

D - New Operator Idea: *== (array value comparison operator)

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I've been thinking of how we could easily (with an operator) compare
strings.

As Walter pointed out, == is problematic because you might want to
compare the address of the arrays or you might want to compare the
values in them.  Even if we came up with an elegant balance for that,
what happens if you want to compare arrays of arrays?  Or what if you
want to compare arrays of non-char types?

char a[][];
char b[][];
....
if( /* the array of strings in a */
    /* is the same as */
    /* the array of strings in b */ )

I just thought of a new operator: the array value comparison
operator,    *= =.  The idea is to imply a "dereferencing compare."  It
is only valid between two arrays of the same type, and it returns true
if and only if they are the same length and contain idential elements.
For multidimensional arrays, you could use as many leading stars as
needed:

char a[];
char b[];
char x[][];
char y[][];

if( a == b )
    // if a and b are the exact same array in memory
if( a *== b )
    // if a and b are equivalent strings
if( x == y )
    // if x and y are the exact same array
if( x *== y )
    // if x and y are the same length, and for all  i<x.length,   x[i]
== y[i].
    // that is, x and y are different arrays, but all their elements
point to
    // exactly the same arrays in memory
if( x **== y )
    // if x and y are the same length, and for all i<x.legth,   x[i]
*==  y[i].
    // that is, x and y are different arrays, and all of their elements
might
    // point to different strings, but the strings are equivalent.

This could go on to ***== and so on.  No need to put an arbitrary
limitation on it.

Of course, you would also implement matching routines for the other
comparators:
*!=
*<
*>
*<=
*>=
**!=
**<
and so on.

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]
Dec 24 2001
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3C281D5C.1E8E1C1B deming-os.org...

 I just thought of a new operator: the array value comparison
 operator,    *= =.  The idea is to imply a "dereferencing compare."  It
 is only valid between two arrays of the same type, and it returns true
 if and only if they are the same length and contain idential elements.

Why not use the "array contents" operator for this? if (a == b) ... // compare pointers if (a[] == b[]) ... // compare arrays
Dec 25 2001
next sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Pavel Minayev wrote:

 Why not use the "array contents" operator for this?

     if (a == b) ...        // compare pointers
     if (a[] == b[]) ...    // compare arrays

Might work... -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Dec 25 2001
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a09eq6$1vrn$1 digitaldaemon.com...
 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3C281D5C.1E8E1C1B deming-os.org...
 I just thought of a new operator: the array value comparison
 operator,    *= =.  The idea is to imply a "dereferencing compare."  It
 is only valid between two arrays of the same type, and it returns true
 if and only if they are the same length and contain idential elements.

if (a == b) ... // compare pointers if (a[] == b[]) ... // compare arrays

I thought of that, but unfortunately then the slicing operator becomes semantically ambiguous. The only way the contents operator works is by it having special meaning *only* when used as an lvalue. Sigh.
Dec 25 2001
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a0btal$c56$1 digitaldaemon.com...

 I thought of that, but unfortunately then the slicing operator becomes
 semantically ambiguous. The only way the contents operator works is by it
 having special meaning *only* when used as an lvalue. Sigh.

Hmmm... I can't understand what you mean. Could you please post an example of such ambiguity?
Dec 26 2001
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a0cbf7$ljq$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a0btal$c56$1 digitaldaemon.com...
 I thought of that, but unfortunately then the slicing operator becomes
 semantically ambiguous. The only way the contents operator works is by


 having special meaning *only* when used as an lvalue. Sigh.

an example of such ambiguity?

a[] is a synonym for a[0..a.length]. If I write: foo[3..5] do I mean the array, or the contents of the array? If the latter, then much of the uses of slicing are obviated. If the former, then I can't assign a special meaning to [].
Dec 26 2001
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a0d1va$13o1$2 digitaldaemon.com...

 do I mean the array, or the contents of the array? If the latter, then

 of the uses of slicing are obviated. If the former, then I can't assign a
 special meaning to [].

Whichever the case, what's the problem? Comparison operators don't modify their operands, so whether slice is part of array or a brand new one doesn't matter, right? In fact D already defines == and friends on arrays and slices (AFAIK) so it is legal to write: if (a[] == b[]) ... But it is only legal if both arrays are of the same size. Making it work on differently sized arrays would give us pretty much everything we need.
Dec 26 2001
parent "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a0d2h6$142m$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a0d1va$13o1$2 digitaldaemon.com...

 do I mean the array, or the contents of the array? If the latter, then

 of the uses of slicing are obviated. If the former, then I can't assign


 special meaning to [].

Whichever the case, what's the problem? Comparison operators don't modify their operands, so whether slice is part of array or a brand new one doesn't matter, right? In fact D already defines == and friends on arrays and slices (AFAIK) so it is legal to write: if (a[] == b[]) ... But it is only legal if both arrays are of the same size. Making it work on differently sized arrays would give us pretty much everything we need.

I'm going to have to revisit the a[] op b[] syntax, as I don't think it is going to work.
Dec 27 2001
prev sibling parent reply Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:


 a[] is a synonym for a[0..a.length]. If I write:
     foo[3..5]
 do I mean the array, or the contents of the array? If the latter, then much
 of the uses of slicing are obviated. If the former, then I can't assign a
 special meaning to [].

Do you anticipate wanting to compare slices for reference identity rather than for content identity? It's a little perlesque/DWIMy, but could you treat slice syntax differently in comparison expressions than in assignment or other expressions? -RB
Dec 26 2001
parent reply "Walter" <walter digitalmars.com> writes:
"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3C2A1913.9050303 estarcion.com...
 Walter wrote:
 a[] is a synonym for a[0..a.length]. If I write:
     foo[3..5]
 do I mean the array, or the contents of the array? If the latter, then


 of the uses of slicing are obviated. If the former, then I can't assign


 special meaning to [].

identity rather than for content identity?

Yes.
 It's a little
 perlesque/DWIMy, but could you treat slice syntax differently
 in comparison expressions than in assignment or other
 expressions?

Each special case adds complexity, that doesn't mean it is not worth doing, the case just has to be fairly compelling.
Dec 27 2001
parent reply Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:

 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3C2A1913.9050303 estarcion.com...
Do you anticipate wanting to compare slices for reference
identity rather than for content identity?

Yes.
It's a little
perlesque/DWIMy, but could you treat slice syntax differently
in comparison expressions than in assignment or other
expressions?

Each special case adds complexity, that doesn't mean it is not worth doing, the case just has to be fairly compelling.

Okay, well, then, let's get back to thinking of a good operator to use for array content comparison. if (a $= b) // "string equal" to speakers of BASIC if (a []= b) // "array equal" if (a === b) // because = and == aren't confusing enuf -RB
Dec 27 2001
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3C2B67E5.20207 estarcion.com...
 Walter wrote:

 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3C2A1913.9050303 estarcion.com...
Do you anticipate wanting to compare slices for reference
identity rather than for content identity?

Yes.
It's a little
perlesque/DWIMy, but could you treat slice syntax differently
in comparison expressions than in assignment or other
expressions?

Each special case adds complexity, that doesn't mean it is not worth


 the case just has to be fairly compelling.

Okay, well, then, let's get back to thinking of a good operator to use for array content comparison. if (a $= b) // "string equal" to speakers of BASIC if (a []= b) // "array equal" if (a === b) // because = and == aren't confusing enuf

The idea: a [==] b a [<] b a [>=] b is sort of appealing <g>.
Dec 27 2001
next sibling parent Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:

 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3C2B67E5.20207 estarcion.com...
Okay, well, then, let's get back to thinking of a good operator to
use for array content comparison.

    if (a $= b)     // "string equal" to speakers of BASIC
    if (a []= b)    // "array equal"
    if (a === b)    // because = and == aren't confusing enuf

The idea: a [==] b a [<] b a [>=] b is sort of appealing <g>.

Works for me, but then, I'm twisted. -R
Dec 27 2001
prev sibling parent "Pavel Minayev" <evilone omen.ru> writes:
Or maybe this?

    if (a ~~ b) ...
    if (a !~ b) ...
Dec 27 2001
prev sibling next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3C2B67E5.20207 estarcion.com...

 Okay, well, then, let's get back to thinking of a good operator to
 use for array content comparison.

     if (a $= b)     // "string equal" to speakers of BASIC

I'm a BASIC geek myself and would never ever consider $= "string equality"...
Dec 27 2001
prev sibling next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
Perl maybe?

    if (a eq b) ...
    if (a !eq b) ...
Dec 27 2001
next sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Pavel Minayev wrote:

 Perl maybe?

     if (a eq b) ...
     if (a !eq b) ...

No, not this. We want something that will work with comparing multidimensional arrays to an arbitrary depth, IMHO. So I think it should be == with some sort of qualifier, such as *==, []==, or [==] -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Dec 27 2001
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3C2BA7D3.7D2ED7A deming-os.org...
 Pavel Minayev wrote:

 Perl maybe?

     if (a eq b) ...
     if (a !eq b) ...

No, not this. We want something that will work with comparing multidimensional arrays to an arbitrary depth, IMHO. So I think it should be == with some sort of qualifier, such as *==, []==, or [==]

Too long to type. I'd prefer something not longer than 2 chars (since string comparison is a frequent operation).
Dec 28 2001
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I was about to suggest *=, but then it's got an overloaded meaning between
multiplication-in-place and comparision, which I don't think is good:

char a[];
char b[];
int c;
a *= c;   // multiples each element by c
a *= b;   // string compares a and b

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]
Dec 28 2001
parent "Pavel Minayev" <evilone omen.ru> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3C2CDA64.B13E6C78 deming-os.org...
 I was about to suggest *=, but then it's got an overloaded meaning between
 multiplication-in-place and comparision, which I don't think is good:

 char a[];
 char b[];
 int c;
 a *= c;   // multiples each element by c
 a *= b;   // string compares a and b

Definitely. For same reason I didn't suggest ~=. For now I tend to like that ~~ thingie I proposed not long ago. It's fast to type, consists of one character repeated twice like ==, and associates with ~ which concats _arrays_ in contrast to + which sums their _contents_. It also makes possible to define a whole set of comparison ops for arrays: ~~ equal !~ not equal ~> greater than ~< less than ~>= greater than or equal ~<= less than or equal
Dec 28 2001
prev sibling parent reply la7y6nvo shamko.com writes:
"Pavel Minayev" <evilone omen.ru> writes:

 Perl maybe?
 
     if (a eq b) ...
     if (a !eq b) ...

Gosh, why not this: if (a .EQ. b) ... if (a .NE. b) ... :=|
Jan 01 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
<la7y6nvo shamko.com> wrote in message
news:s7citam5pgo.fsf michael.shamko.com...

 Gosh, why not this:

     if (a .EQ. b) ...
     if (a .NE. b) ...

1) too long 2) all keywords should be lowercase
Jan 01 2002
parent reply la7y6nvo shamko.com writes:
"Pavel Minayev" <evilone omen.ru> writes:

 <la7y6nvo shamko.com> wrote in message
 news:s7citam5pgo.fsf michael.shamko.com...
 
 Gosh, why not this:

     if (a .EQ. b) ...
     if (a .NE. b) ...

1) too long 2) all keywords should be lowercase

Sorry... I guess the meaning of the :=| emoticon didn't get through. It wasn't a serious suggestion. My point was, using operators used by Perl doesn't seem any better to me than using operators used by FORTRAN. Cribbing features used in other, dissimilar languages seems like a bad idea in general.
Jan 01 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
<la7y6nvo shamko.com> wrote in message
news:s7cd70t6anm.fsf michael.shamko.com...

 It wasn't a serious suggestion.  My point was, using operators
 used by Perl doesn't seem any better to me than using operators
 used by FORTRAN.  Cribbing features used in other, dissimilar
 languages seems like a bad idea in general.

The problem is, there is nothing even close in C/C++. So we have to invent it or steal from somebody.
Jan 01 2002
parent reply la7y6nvo shamko.com writes:
"Pavel Minayev" <evilone omen.ru> writes:

 <la7y6nvo shamko.com> wrote in message
 news:s7cd70t6anm.fsf michael.shamko.com...
 
 It wasn't a serious suggestion.  My point was, using operators
 used by Perl doesn't seem any better to me than using operators
 used by FORTRAN.  Cribbing features used in other, dissimilar
 languages seems like a bad idea in general.

The problem is, there is nothing even close in C/C++. So we have to invent it or steal from somebody.

Quote from Butler Lampson: "We already have a way to extend programming languages. It's called 'procedures'. They work great!" I see no reason to have special purpose operators solely for string comparison, especially since the semantics of such operations is not a settled question (should they be case sensitive or not, for example?). Now, if you want to talk about generalizing the language so that the regular comparison operators can be used for user defined datatypes, that's a different topic entirely.
Jan 01 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
<la7y6nvo shamko.com> wrote in message
news:s7c666l696j.fsf michael.shamko.com...
 "Pavel Minayev" <evilone omen.ru> writes:

 I see no reason to have special purpose operators solely for string
 comparison, especially since the semantics of such operations is not a
 settled question (should they be case sensitive or not, for example?).

First of all, we are not talking of string comparison here. We are talking about comparing arrays, strings are just a subset... Second (actually, first), strings are just TOO important and frequently used to handle them with procedures. It was so in C, all those strcmp and strcpy, which I just hated, while most other languages - BASIC, Pascal, and now Java - offer convenient string handling... Then came C++, STL and std::string (the latter is by the way the reason why I always prefer C++ over C, even when there are no other advantages). D states itself as the "practical language", which I personally understand as making it convenient for programmers and common-day tasks rather than centering around some "common idea" (a major flaw of Java IMO). It's so frequent you have to compare two strings for equality, the language should provide a convenient way for this. If it works on arrays of any kinds, that's even better! Now concerning "unsettled" semantics. The answer is simple: do it like everybody does! For example, comparison should be case sensitive since all other languages consider this the default. Additional case insensitive comparison operators would be cool but not so necessary since they aren't used that often.
Jan 01 2002
prev sibling parent reply Charles Hixson <charleshixsn earthlink.net> writes:
Russell Borogove wrote:

...
 
    if (a $= b)     // "string equal" to speakers of BASIC
    if (a []= b)    // "array equal"
    if (a === b)    // because = and == aren't confusing enuf
 
 -RB

This doesn't directly address the problem of basic operators (how about "=?" as a choice), but to me it feels related. There needs to be ways to limit the number of basic operators required. Perhaps it's time to think again about making string a class (or at least having a String class that can be used as if "anything" were an instance of it. That way the needed operations could be defined. The problem is that there needs to be a way to allow the class to be extended differently by different people. So someone would be able to define it such that: "able was I ere I saw elba".capitalize.split_at("Ere") == "Able Was I" even though capitalize was not a method defined for string by the language+libs. Note that the problem here is that the method is being invoked off of the constant string. A cast could be used to solve this, but such an approach is cumbersome. Ditto for the creation of a temporary object. So perhaps what is needed is the ability to declare an object that is a parent of a defined class? A descendant doesn't solve this problem. Of course what is really being requested is the ability to extend an existing class that has been compiled, and (perhaps) is only available in binary. The exact details aren't too important to the solution of the problem (Python, Ruby, Sather, Smalltalk, etc. each solve this problem, but they use different ways to solve it). But solving it in a compiled language may be more difficult. (C, C++, Eiffel, and Java don't seem to have any solution.) But one of the things that I frequently find myself wanting to do is define methods (and operators) on String that don't exist in the pre-defined system classes. Presumably similar problems exist for other people, possibly with respect to different classes. (Do you need to define a new operation on Complex numbers?) But the case for String is particularly clear, because the language comes with significant support for string constants. If one already had to write String('a', 'b', 'l', 'e', ' ', ... 'E', 'l', 'b', 'a') then the additional effort used in typeing MyString instead of String would be insignificant.
Jan 02 2002
next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Charles Hixson" <charleshixsn earthlink.net> wrote in message
news:3C33630F.4010005 earthlink.net...

 required.  Perhaps it's time to think again about making string
 a class (or at least having a String class that can be used as
 if "anything" were an instance of it.  That way the needed
 operations could be defined.  The problem is that there needs to

Don't forget that D doesn't support operator overloading. So be string a class, it would be a method cmp() rather than function, and no other differences.
Jan 02 2002
prev sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Charles Hixson wrote:

 "able was I ere I saw elba".capitalize.split_at("Ere") == "Able
 Was I"

You can already implement such things in D, if you just declare global functions instead of requiring member functions: char[] Capitalize(char[]); char[] SplitAt(char[],char[]); ... if(SplitAt(Capitalize("able was I ere I saw elba"),"Ere") == "Able Was I") ... -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Jan 03 2002
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
It'd be really handy to be able to decorate an existing class with extra
(non-virtual) member functions.  Access would probably be restricted to
public interface.

It'd really be syntactic sugar for global functions to masquerade themselves
as member functions of some other class.  But sometimes you just want
everything to be consistent from the user's point of view.

Maybe operator overloading could be done this way as well.  You could
declare the operators (in terms of other normal member functions) at the
scope in which they will be used.  Then nobody else has to deal with them.

Sean

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3C342D92.39417435 deming-os.org...
 Charles Hixson wrote:

 "able was I ere I saw elba".capitalize.split_at("Ere") == "Able
 Was I"

You can already implement such things in D, if you just declare global functions instead of requiring member functions: char[] Capitalize(char[]); char[] SplitAt(char[],char[]); ... if(SplitAt(Capitalize("able was I ere I saw elba"),"Ere") == "Able Was I") ...

Jan 03 2002
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
"Sean L. Palmer" wrote:

 It'd be really handy to be able to decorate an existing class with extra
 (non-virtual) member functions.  Access would probably be restricted to
 public interface.

Good idea! It might not sit well with all of the OOP purists, but very practical! -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Jan 03 2002
parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> ha scritto nel messaggio
news:3C34B440.C88029A8 deming-os.org...
 "Sean L. Palmer" wrote:

 It'd be really handy to be able to decorate an existing class with extra
 (non-virtual) member functions.  Access would probably be restricted to
 public interface.

Good idea! It might not sit well with all of the OOP purists, but very practical!

I like it in the form of static faunctions. For example I like the Java way of declaring static functions in classes: double base = Math.tan(x); // angle tangent double base = Finance.tan(x, y, z); // annual rate So you'll see: if (String.cat(a, b) == c) ... instead of: if (strct(a, b) = c) ... I know, I'm prolix. Ciao
Jan 07 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a1c86m$131n$1 digitaldaemon.com...

 I like it in the form of static faunctions. For example I like the Java

 of declaring
 static functions in classes:

   double base = Math.tan(x); // angle tangent
   double base = Finance.tan(x, y, z); // annual rate

 So you'll see:

   if (String.cat(a, b) == c) ...

 instead of:

  if (strct(a, b) = c) ...

 I know, I'm prolix.

D offers an alternative of modules. Just write a "string" module (in fact, it's already there =)), and call it in the same way: if (string.cmp(a, b) == c) ... But for us C freaks, simple cmp() without any strings is there =)
Jan 07 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
Oh, btw... so what about string (array) comparison op?
Jan 07 2002
prev sibling parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> ha scritto nel messaggio
news:3C281D5C.1E8E1C1B deming-os.org...
 I've been thinking of how we could easily (with an operator) compare
 strings.

 As Walter pointed out, == is problematic because you might want to
 compare the address of the arrays or you might want to compare the
 values in them.

This reminds me of my college times, when using Simula there were two assignment operators: one to assign the object reference, and one to copy the object value(s). int a[]; int b[]; a = ... something ... b = a; // the reference or the value? b = ... something ... // change b only or both a and b? The same problem here arise for comparisions: if (a == b) // the reference or the value? If there where two assignement and comparison operators: Foo a; Foo b; a = b; // assign the reference a := b; // copy the value if (a == b) // they are the same object if (a :== b) // the have equivalent value This would be a BIG change in the language. P.S: please, don't use ~ for anything. In international keyboards there is no '~'. I have to press Alt-126 to get this weird char! Ciao
Jan 07 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a1c8m7$13dj$1 digitaldaemon.com...

 If there where two assignement and comparison operators:
 This would be a BIG change in the language.

Let's start a petition? =)
 P.S: please, don't use ~ for anything. In international keyboards there is
 no '~'. I have
        to press Alt-126 to get this weird char!

Hmmm... there is ~ on my Russian keyboard. Also, unary ~ is already used in C and C++ (and thus, in D).
Jan 07 2002
parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Pavel Minayev" <evilone omen.ru> ha scritto nel messaggio
news:a1cajj$14q1$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a1c8m7$13dj$1 digitaldaemon.com...

 If there where two assignement and comparison operators:
 This would be a BIG change in the language.

Let's start a petition? =)
 P.S: please, don't use ~ for anything. In international keyboards there


 no '~'. I have
        to press Alt-126 to get this weird char!

Hmmm... there is ~ on my Russian keyboard. Also, unary ~ is already used in C and C++ (and thus, in D).

Yes, but it's rarely used. Unary bit not is an operation that you'll use less frequently than string comparison. In italian keyboards, there are no {}~. But while braces can be achieved with the undocumented Shift-AltGr-[] combination under Windows, ~ can be achieved only with Alt-126. :-( Ciao.
Jan 07 2002
next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a1cj89$1a1u$1 digitaldaemon.com...

 Yes, but it's rarely used. Unary bit not is an operation that you'll use
 less
 frequently than string comparison.

~ is also used for array concatenation already.
Jan 07 2002
prev sibling parent reply "Juarez Rudsatz" <juarez correio.com> writes:
I don't understand yet the difference between '~' and '!'.
If they have same meaning, why not remove '~' from D spec ?
The concatenation could use another symbol. There are no tradition on '~=' .

[s]


"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a1cj89$1a1u$1 digitaldaemon.com...

"Pavel Minayev" <evilone omen.ru> ha scritto nel messaggio
news:a1cajj$14q1$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a1c8m7$13dj$1 digitaldaemon.com...

 If there where two assignement and comparison operators:
 This would be a BIG change in the language.

Let's start a petition? =)
 P.S: please, don't use ~ for anything. In international keyboards there


 no '~'. I have
        to press Alt-126 to get this weird char!

Hmmm... there is ~ on my Russian keyboard. Also, unary ~ is already used in C and C++ (and thus, in D).

Yes, but it's rarely used. Unary bit not is an operation that you'll use less frequently than string comparison. In italian keyboards, there are no {}~. But while braces can be achieved with the undocumented Shift-AltGr-[] combination under Windows, ~ can be achieved only with Alt-126. :-( Ciao.
Jan 09 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:a1ho6p$1erl$1 digitaldaemon.com...

 I don't understand yet the difference between '~' and '!'.

uint a = 1; ~a == 0b11111111111111111111111111111110; !a == 0;
 The concatenation could use another symbol. There are no tradition on '~='

Concatenation is already defined by ~. Large amount of code has already being written using this style. Also, Walter seems to like his invention - personally, me too, now - and won't give up so easy. =) We tried to convince him to change it already once, but... well you can see the results =)
Jan 09 2002
parent reply "Juarez Rudsatz" <juarez correio.com> writes:
 give up so easy. =) We tried to convince him to change it
 already once, but... well you can see the results =)

I will try to convince his with filosophy. If Hegel could write a compiler they could say : write a efficient, simple and correct version of what already is good ? And now look at this sequence : & -> && : For and bitwise you have similar and logical | -> || : For or bitwise you have similar or logical ! -> !! : For not bitwise you have similar not logical And "bingo" the "~" will &*$ %%▀¤. The question here is good have less characters as part of language. The first example is the italians and russians keyboards. And this character change position in any different keyboard and his position is not so good...
 Concatenation is already defined by ~. Large amount of code has
 already being written using this style. Also, Walter seems

Sed or M4 this problem nicely "Pavel Minayev" <evilone omen.ru> escreveu na mensagem news:a1hqg6$1g9h$1 digitaldaemon.com...
 "Juarez Rudsatz" <juarez correio.com> wrote in message
 news:a1ho6p$1erl$1 digitaldaemon.com...

 I don't understand yet the difference between '~' and '!'.

uint a = 1; ~a == 0b11111111111111111111111111111110; !a == 0;
 The concatenation could use another symbol. There are no tradition on


 .

 Concatenation is already defined by ~. Large amount of code has
 already being written using this style. Also, Walter seems
 to like his invention - personally, me too, now - and won't
 give up so easy. =) We tried to convince him to change it
 already once, but... well you can see the results =)

Jan 09 2002
parent "Sean L. Palmer" <spalmer iname.com> writes:
That *almost* works, but since ! is an unary operator, it would preclude the
possibility of writing !!x to mean "convert x to boolean".  This is often
useful in C++ since you can explicitly cast something to bool indirectly
through the ! operator which is much shorter to say if (!!p) than it is to
say if(bool(p)) etc to get around compiler warnings (I always leave most of
them on).

So admittedly it's not anything crucial that I couldn't do without.  I bet
that's something to do with why K&R decided against it for C.

I don't think a "large amount of code has already been written using this
style" is a worthy excuse not to make a change since there are only alpha
compilers, nobody but a few of the people here (Walter!) has a huge
investment in D source.  I don't think the D compiler is yet written in D,
is it?  ;)   If a change is for the best, it's probably worth doing.

However there's a large amount of C/C++ code written using that style, that
will need lots of search-and-replacing or manual translating.  Or I wonder
if he meant he personally is too used to typing ~ to mean binary not that he
couldn't adjust if it were changed?  Hmm....

I favor making a strong language.  Its resemblance to C is, to me,
fortuitous, but not critical.

Sean

"Juarez Rudsatz" <juarez correio.com> wrote in message
news:a1is6p$24og$1 digitaldaemon.com...
 give up so easy. =) We tried to convince him to change it
 already once, but... well you can see the results =)

I will try to convince his with filosophy. If Hegel could write a compiler they could say : write a efficient, simple and correct version of what already is good ? And now look at this sequence : & -> && : For and bitwise you have similar and logical | -> || : For or bitwise you have similar or logical ! -> !! : For not bitwise you have similar not logical And "bingo" the "~" will &*$ %%▀¤. The question here is good have less characters as part of language. The first example is the italians and russians keyboards. And this

 change position in any different keyboard and his position is not so

 Concatenation is already defined by ~. Large amount of code has
 already being written using this style. Also, Walter seems

Sed or M4 this problem nicely

Jan 09 2002
prev sibling parent Roland <rv ronetech.com> writes:
Juarez Rudsatz a Úcrit :

 I don't understand yet the difference between '~' and '!'.
 If they have same meaning, why not remove '~' from D spec ?
 The concatenation could use another symbol. There are no tradition on '~=' .

In C++: !(true) = false = 0 ~(true) = 0xfffffffe Roland
Jan 11 2002