Home Articles Software Reverse Assignment Operator in Programming Languages

Reverse Assignment Operator in Programming Languages

I came across this scenario more than a year back, and again today the same scenario is back, but no answers yet, and hence posting the same thoughts again :)

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 programming language which has this feature!)

Introduction

Usually when we want to assign a value of a variable a to another variable say b , then all we do is write somthing like this

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);

The Problem: Ternary Denial!

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;

The Solution: Reverse Assignment Operator

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 while writing some crazy code :)

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.

5 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

FacebookLike
InstagramFollow
PinterestFollow
RSS FeedSubscribe
Sound CloudFollow
TwitterFollow
YoutubeSubscribe

Latest Articles

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.

Online Education should be interactive and innovative – Fun to Learn

For online education to succeed for smaller classses - it should be as interesting as cartoons. Online education cant succeed unless it is more interesting, interactive and innovative than offline schooling.

The Complete List of Dhatus – Sanskrit Root Words and their English meaning

A complete list of all dhatus (root words or verb roots) in Sanskrit dictionary and their meanings with corresponding IPA transliteration.

Sanskrit Lesson 4 – Word Creation Magic using Dhatus

Learn how easy it is to create new words in Sanskrit using root words called Dhatus. This simple process of Sanskrit grammar powers the entire language.

Latest Music 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.

Title Track BGM – Irul – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Title Track BGM from the 2021 Malayalam movie Irul in Western and Indian Notations.

Ninnukori Varnam – Agni Natchathiram – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Ninnukori Varnam from the 1988 Tamil movie Agni Natchathiram in Western and Indian Notations.
Content Protection by DMCA.com