Home Articles Software Reverse assignment option

Reverse assignment option

While writing a piece of software I got this thought about a feature that could be provided in programming languages (at least I am not aware of any language which has this feature)

Usually when we want to assign a value of a variable “a” to another variable say “b” all we do is write

b=a;

Now consider this case. Suppose we want to assign the value of variable “a” to “b” if “c” equals 1 OR else we want to assign “d” to “b”, then we write

if(c==1)
b=a;
else
b=d;

an easier way to write the above code would be to use a ternary operator as

b=(c==1?a:d)

Now consider another scenario, where we want to assign “a” to “b” if “c” equals 1 OR we want to assign “a” to “e”

Oops then we cant use the ternary operator, instead we have to fallback to our old friend “if.. else” as

if(c==1)
b=a;
else
e=a;

Now wouldnt it be nice if this could be achieved using something like

a#(c==1?b:e) where # is the reverse assignment operator which assigns LHS to RHS !

so here if c==1 then # would assign “a” to “b” else it would assign “a” to “e” !!!

Just some crazy thoughts

Content Protection by DMCA.com
Gurudevhttps://www.hitxp.com
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.

9 COMMENTS

  1. @kaushik.
    well, its bouncing off my head…
    laches.. multiplex…
    it would be great if you could give a high level view of this please….
    else i need to do googling :(

  2. Kaushik,

    The value of b when c~=1 should continue be whatever it is currently! isnt that possible? like (0 0) in SR latch? or am I talking something crap, bcos I am not an electronics student :)

  3. well i guess you are aware of a multiplexer. a simple example of a 2×1 mux assigns one of the two inputs to the single output depending on select line. that is what the conditional operator does. if we code this using a hardware descriptive language, like VHDL or verilogthe language synthsisers will implement the logic to a multiplexer.

    the second thought of a reverse assignment doesnt acutally happen in circuit(at least not a good method of implementation). although the thought is interesting, but the ciruit will be unstable. that is becuase, there are two outputs. and in digital logic, any output should always be either 0 or 1. but when we look into the second expression the two ouptus are getting the value of the input on a select line, and the state of a particular output when there is no select line is unkown. for eg., if c=1, then b=a. but what is the value of b when c~=1 is unknown. thus there is an ambiguity and when we try to synthesis such logic, and we get latches where the older value of b gets latched. although theoretically lathces may seem OK for design, but are not preferred practically.

    Infact this is the reason why we dont find any general expressions(ternary operator kind of) for the second logic.

  4. @kaushik
    i didnt got that…
    could u explain how assignments happen in circuit level…

    @dev..
    good thought man…
    in that case, for many of my methods, i would ask for an operator :P

LEAVE A REPLY

Please enter your comment!
Please enter your name here

FacebookLike
InstagramFollow
PinterestFollow
RSS FeedSubscribe
Sound CloudFollow
TwitterFollow
YoutubeSubscribe

Latest Articles

The Power of Democracy: How Free Societies Foster Innovation in Science and Technology

Democracy allows freedom of speech and thought, boosting creativity and innovation. This leads to scientific breakthroughs and technological advancements.

How does GOD helps us?

Do prayers really help? Do miracles happen when we are in trouble? Does God really help us in times of need? Are prayers enough to save us during bad times? How should we face problems?

Sanskrit poem on Ramayana – read in reverse becomes Mahabharata!

A Sanskrit poem about Ramayana when read in reverse direction becomes a poem on Mahabharata!

The difference between Itihasa and Puranas

Documentation of ancient Indian history and the historical events of Indian civilization in the form of Itihasa and Puranas - Ramayana and Mahabharata.

Latest Music Notations

Jai Shri Ram – Adipurush – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Jai Shri Ram from the 2023 Hindi movie Adipurush in Western and Indian Notations.

Sojugada Soojumallige – Garuda Gamana Vrishabha Vahana – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Sojugada Soojumallige from the 2021 Kannada movie Garuda Gamana Vrishabha Vahana in Western and Indian Notations.

Oo Antava Mava – Pushpa – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Oo Antava Mava from the 2022 Telugu movie Pushpa in Western and Indian Notations.

Kaa Chalige Bangalore (Tiningaa Miningaa Tishaaaa) – Salaga – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Tiningaa Miningaa Tishaaaa (Kaa Chali Ge) from the 2022 Kannada movie Salaga in Western and Indian Notations.
Content Protection by DMCA.com