abstract logic question?

ganutenator

Lifetime Supporting Member
Join Date
May 2002
Location
kansas
Posts
1,440
A question was proposed to me at work after a programmer complained about '=' being both a comparative operator and also an assignment operator.

I probably wouldn't want to use this in code, but I immediately thought of
a = b could be written as NOT (a <> b).

But I couldn't think of a way to assign b to a w/ out using the '=' sign.

Closest I came was a - a + b, but then still found my way stuck.
 
With Red Lion Crimson software you can put expressions and operations in most fields anywhere in the application. I once intended to use a comparison for an indicator "a = b" and unwitting I was forcing "a" to be assigned the value of "b".

I don't remember now what type of field or object where I had done that, but It took me an hour to figure out what the hel was going on. I immediately made the habit of using two characters for all assignment and comparison operations that include an equal sign:

a := b //assigns a the value of b
a == b //returns TRUE if a equals b
a != b //returns TRUE if a does not equal b

That syntax is specific to C based scripting languages and not universal, but is somewhat on the same topic as your discussion.
 
I have read that every logic circuit can be represented as a NAND gate.
I'm not sure if I am ready to jump down that rabbit hole quite yet.
 
I can think of only two languages, Visual Basic and SQL, where a lone equals sign (without a prefix :, as in Pascal and its illegitimate child Structured Text) does double duty as both binary comparator and assignment operators. Also, I think := and = can do assignment in ST, but the effect is different somehow; does it have summat to do with persistence?

I am pretty sure that in VB it will be interpreted correctly based on context i.e. [IF (A = B) ...] will not assign the value of A to B.

PHP has the double-=, and even a triple-=, comparator.

Lord knows what perl does.

FORTRAN has .EQ. for a comparator.

Python has == for a comparator and will throw an error if summat like [if a=b ...] is attempted.

C will assign a value if a single = is found in an otherwise logical expression i.e. [if (a=b)...] will be true if b is non-0 and will assign the value of b to a; [if (a==b)...] will be true if a equals b and will not change the value of a. Because of this I have gotten in the habit of doing things like [if (1==b)...] instead of [if (b==1)...] so that, if I forget the second =, the compiler will throw an error. The other thing in C is that it is sometimes useful to have that single equals in the if express i.e. [if (status=test_summat(a,b))...] will be true if the result of test_summat(a,b) is non-zero, and it will also put that result into the variable [status], which I can then test to find out what the non-zero status was (C-based functions usually return 0 for success and non-zero for failure). C: all the power of assembler with all the convenience of assembler.

@gatenuator: what was the question; and what was the language being referred to?

Railing against the syntax choices of any language seems like commanding the tide not to come in: pretty pointless.
 
Because of this I have gotten in the habit of doing things like [if (1==b)...] instead of [if (b==1)...] so that, if I forget the second =, the compiler will throw an error.
That's a neat idea; I think I'll steal it.
 
That is truely a big misstake by the designers of C.
Luckily there are numerous other (and more well constructed) languages than C.
(Object)Pascal for example as mentioned in the thread.
 
The question:
Is there some tricky way to assign a variable to another w/o using an '=' sign.
I.E. some tricky logic operation similar to how you can run an XOR on the same variable to clear the word?
 
That is truely a big misstake by the designers of C.
Luckily there are numerous other (and more well constructed) languages than C.
(Object)Pascal for example as mentioned in the thread.


Sigh.

Do we allow religious arguments in this forum? Apparently yes, so ...

I asked my son how his new job was. He said, "At least I am not programming in Pascal anymore."

I once ported a Pascal program to Fortran using only search and replace.

There are no such things as structured and/or good programming languages, only structured and/or good programmers.

C: all the power of assembly with all the convenience of assembly.
 
That is truely a big misstake by the designers of C.
No! It is a feature!



Luckily there are numerous other (and more well constructed) languages than C.
I bet the firmware in your PLC is written in C. The garbage collection in C++ can cause delays that are too long.



(Object)Pascal for example as mentioned in the thread.
Pascal is great for learning but who uses it any more?
I don't see Pascal on this list
https://www.northeastern.edu/graduate/blog/most-popular-programming-languages/


When speed and control count, C rules except when floating point isn't available. Then assembly rules. Fortunately those days are long gone. I haven't touched assembly language for a few years now. There are somethings that can't be done in higher level languages.


Now I do have a big complaint about C. Declaring complex data structures was a b!tch. I never had any problems with memory allocation. BTW, motion controllers do not like garbage collection.



Now I program mostly in Python. What is cool is that sympy can generate code that can be used in ST if the A=B is replaced with an A:=B. I could probably enhance the python code to replace the = with an := if it isn't part of an if or while statement.
 
There are no such things as structured and/or good programming languages, only structured and/or good programmers.
Yeah but there is sucky syntax in languages.

:= and = in ST suck.

Can't we be civilized and do = assignment and == comparison, like the rest of the sane universe?


Also in Codesys FB Properties, the lack of no value/return keywords suck.

Like what do I have to do Set PropA(){_backingPropA := PropA;} and Get PropA() {PropA := _backingPropA; }

WHy can't I just have a value and return key word????

Set PropA() { _backingPropA := value;}
Get PropA() {return _backingPropA; } (this applies to Functions too.)

it is one less thing I have to worry about when making a bunch of properties.
 
Last edited:
The question:
Is there some tricky way to assign a variable to another w/o using an '=' sign.
I.E. some tricky logic operation similar to how you can run an XOR on the same variable to clear the word?


How about memcpy, similar to COP/CPW/CPS/BLK_MOV/etc.? E.g.
Code:
memcpy(&destination, &source, sizeof destination);
 

Similar Topics

I am running out of ideas for this problem I have on one of our machines. In advance I want to say there are no MCR's or doubled outputs in some...
Replies
9
Views
2,683
I got my PanelView Plus 7 working with a Micrologix 1500. How would I connect my laptop to the PanelView to view the ladder logic while operating...
Replies
6
Views
116
Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
Replies
13
Views
228
Hello again..trying something on an existing poorly written program and just wanted to double check something system is an A-B MicroLogix 1200 In...
Replies
5
Views
169
Good morning fellow sea captains and wizards, I am being asked to do the above and obtain 4 values from each slave, I know about the MRX and MWX...
Replies
32
Views
833
Back
Top Bottom