Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

v2 Issue: Equal sign (=) used to both assign and compare


  • Please log in to reply
119 replies to this topic

Poll: How should equal-sign (=) and colon-equals (:=) work in v2? (46 member(s) have cast votes)

How should equal-sign (=) and colon-equals (:=) work in v2?

  1. Leave it like v1: Colon-equals (:=) is an assignment and equals (=) is always a comparison. (16 votes [34.04%])

    Percentage of vote: 34.04%

  2. Make equal-sign (=) dual-purpose: it assigns an expression or performs a comparison, depending on context. (3 votes [6.38%])

    Percentage of vote: 6.38%

  3. Switch to the C style of using = only for assignments (never for comparisons). Double-equals (==) would compare for equality. (26 votes [55.32%])

    Percentage of vote: 55.32%

  4. Other (2 votes [4.26%])

    Percentage of vote: 4.26%

Vote Guests cannot vote
jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

Just to nitpick (it was bugging me... :wink:): my high school courses are very far away, but I don't recall having ever used an assignment in my math courses... = is always, AFAIK, a comparison symbol, meaning equality, nothing else. Assignment is a concept specific to computing. Now, perhaps you can prove me wrong.


Not necessarily, if you count something like this as an assignment:

Let x = 1. Then...

Technically it's an asserted equality, but that's all an assignment is at the core; asserting that a variable is equal to a value or another variable.


I wonder if (a = B) = c is legal, and if yes, what it means...


It should mean that a and b are compared, and then c is compared to the result. If the end result is never used, it doesn't affect anything. (Maybe that should flag something, though?)

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I agree with all of the above. Jonny's my hero. :)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

I mean, all we have to do is make a quick-reference table showing:

ASSIGN

a([b=])


COMPARE
if#(a)-eq-b#then

and we're all set, right?

LOL

This kind of exagerations are typical for kids and ppl that don't have anything else to say...

I wont comment this thred any more, I stated my opinon. AHK is full of suspicious rules and the last thing we need is another one.

I monitor this thred for eristic dialects as "some" ppl here think we don't have high school diploma or whatsoever...


___________________________________________________________________
Eristic is the method by which the form of the conclusion is correct, but the premisses, the materials from which it is drawn, are not true, but only appear to be true.

Dialectic is the method of arriving at conclusions that are accepted or pass current as true,


Reference: The Essays of Arthur Schopenhauer - the Art of Controversy

Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

Reference: The Essays of Arthur Schopenhauer - the Art of Controversy

Original German Essay
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Alright, it's the moment of truth. If you want to advocate a certain system, lay down a set of definite rules, and demonstrate what is done with example cases. They don't have to be these cases, just ones that get the point across. Here's my proposal:

- ':=' is always assignment.
- '==' is always comparison, but case-sensitive.
- '=' is comparison except when it is the leftmost operator (if's and function calls being operators as well), where it is assignment.

Given these rules...

x = y  ; Assigns y to x.
x := y  ; Assigns y to x.
x == y  ; Compares y to x.
x = a ? b : c  ; Assigns result of ternary to x.
x := a ? b : c  ; Assigns result of ternary to x.
func(x = y)  ; Compares y to x, passes boolean result to func.
x = func(y = z)  ; Compares z to y, passes boolean result to func. Assigns func's return value to x.
if x = y  ; Compares y to x.
if x == y  ; Compares y to x.
if x := y  ; Assigns y to x, uses result for if.
if x += y  ; Adds y to x, uses result for if.

If you can't figure out other "ambiguous" statements based on the rules, state them and I'll tell you what happens. Just one thing: First consider how often the ambiguity would occur.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
It is confusion, not ambiguity. You can always set up rules, that make the language unambiguous, but for me
x = y = z
is confusing. The dual use of "=", dependent of its position will cause many bugs.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
I knew that'd come up again. I was trying to avoid it for the sake of simplicity, but it's still easy enough to add.

- '=' is assignment if the preceding operator is a '=' assignment.

Which means...

x = y = z  ; Assigns z to y and x.
x = (y = z)  ; Preceding operator is (, compares z to y and assigns boolean result to x.
(x = y) = z  ; Compares y to x. Compares result to z.
(x = y = z)  ; Same thing.
x := y = z  ; Compares z to y, assigns boolean result to x, since it is assignment, but not with '='
x = y := z  ; Assigns z to y and x.

Note that this is the only special case, and it's to make things simpler, not harder to remember.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

x = y = z  ; Assigns z to y and x.
x = y := z  ; Assigns z to y and x.

I think these 2 should stay in the waste basket and we should be forced to use 2 lines or suffer a slight performance loss by using comma separated expressions instead.

(x = y) = z  ; Compares y to x. Compares result to z.
(x = y = z)  ; Same thing.

Two comparisons with no assignment seems useless...

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

Code:

I think these 2 should stay in the waste basket and we should be forced to use 2 lines or suffer a slight performance loss by using comma separated expressions instead.


That is, of course, an option... but that would mean specifically not including this functionality, and for what reason? It doesn't change anything else, and if it were otherwise, it would almost certainly not work as expected.

Code:

Two comparisons with no assignment seems useless...


Granted. I was simply showing that, even though they're not used for anything, that's what would be the case.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

this is the only special case, and it's to make things simpler, not harder to remember.

Not for me...

... well, I am only a user...

so am I.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Eristc dialectic catched (again)

Note that this is the only special case, and it's to make things simpler, not harder to remember.



Your only special case consists of 2 special cases:

- if = is leftmost it is assigment, otherawise it is comparison
- if = is not leftmost but there is a leftmost = before it, it is also assigment, not comparison...

- here comes 3th, 4th, .... Nth, N+1th... exception, as ex-proffesor Lazslo kindly pointed out. AHK is evolving project, you never know how future will play with AHK expressions and assigments...

Now, jonny, the link to Shopenhauer is above.
Posted Image

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Sorry, did you have a ruleset to propose? Or do you just enjoy grasping for logical fallacies in other people's words?

I had already included the special case when I came up with the rules. I didn't mention it because I knew it would make things more complicated even though it's such a rare case.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Hej johny

Or do you just enjoy grasping for logical fallacies in other people's words?

No, I just enjoy grasping for logical errors in other ppls words. :mrgreen:
FYI, it is of the same importance then the other things you mention as if you provide false logic covered by some hard to find fallacious axiome, then you can make everybody beleive that you are right, even the author itself, witch will lead to bad results. So, I am here to tell you that you are wrong.
Especially as you are Chris's hero. So, you wanted to be a hero, don't complain about side effects :D

As you might be in the hurry and didn't read carefully entire topic, I repeat again, that I find Pascall solution perfect for our case, like buch of other users here. Its the same as C but other symbols are used witch are more appropriate in this case. Browse the Pascal code around the world for examples of usage. And I will repeat Nth time, that Pascal is created for programming n00bs to stop being n00bs one day, and probably lot of psychology examinations were done in that time. Average non-programming person is the same now and back in time, so I don't see why you don't beleive in its value.

Other then that, if smb is so stupid not to grasp simple thing, then it is again good, as he will realise it is not for him, and stop using AHK, much better solution than spaming Ask for Help forum with countless trivial questions. Even BoBo has a limited amount of time.
Posted Image

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I often need this at the beginning of my functions
a = b = c = d ? e : f
It takes time to figure out what the code does. Of course, I write it as
a := b := c = d ? e : f
but others will drop the colons, and make the code less legible. It is very common, when c is a function parameter and d is a value, which needs special handling, like
a = b = param = 0 ? 0 : 1/param


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

a := b := c = d ? e : f
but others will drop the colons, and make the code less legible.

Even in C, I add extra parentheses to things like the above because I find them hard to read otherwise. For example:
C++: a = b = [color=red]([/color]c == d[color=red])[/color] ? e : f
AHK: a := b := [color=red]([/color]c = d[color=red])[/color] ? e : f
 V2: a = b = [color=red]([/color]c = d[color=red])[/color] ? e : f   ; Both of the above would also work in V2, even without the parentheses (though the parentheses are necessary in this line here).