rohd icon indicating copy to clipboard operation
rohd copied to clipboard

Add support for `++` and `--` types of operations in conditional logic

Open mkorbel1 opened this issue 2 years ago • 1 comments

Motivation

There are cases in procedural execution in _Always blocks where ++ and -- are useful. Dart does not allow overloading these operators, however.

Desired solution

Some sort of function on Logic which acts like ++ and --, both postfix and prefix (i.e. ++x vs. x++). Some thought has to go into the API and function names to make this intuitive.

To effectively use these requires some careful thought. A prefix is simple, i.e. ++x is the same thing as x + 1. A postfix requires that the original signal is returned, but then a modified conditional operation is performed afterwards. This means that it needs to return some special type of object that other Conditionals can handle, but that also might need to play nicely with other Logic manipulation within conditional procedural logic. There's a number of combinations to consider, and this could involve some modifications to the way things like ConditionalAssignments work in general.

Alternatives considered

Just omit the feature.

Additional details

There are real designs where users had wished for a feature like this.

mkorbel1 avatar Jul 27 '22 20:07 mkorbel1

Adding something like += and -= would also be good!

mkorbel1 avatar Aug 19 '22 23:08 mkorbel1

Hey Max, I would like to give a try on this issue! :)

RPG-coder-intc avatar Oct 11 '22 21:10 RPG-coder-intc

@RPG-coder-intc great! Let me know once you have a strategy mapped out if you'd like to review the approach. I expect there could be some tricky surprises in implementing this.

mkorbel1 avatar Oct 11 '22 22:10 mkorbel1

A function will be made for postIncrement and preIncrement taking the Logic object value as a reference. The result computation will be worked on this reference object taken as a parameter.

RPG-coder-intc avatar Oct 24 '22 01:10 RPG-coder-intc

Similar pattern will be followed on += (addAssign(&ref)) , -= (diffAssign(&ref)) , *= (mulAssign(&ref)), /= (divAssign(&ref)).

RPG-coder-intc avatar Oct 24 '22 01:10 RPG-coder-intc

logicVar++ === postIncr(&ref) ++logicVar === preIncr(&ref)

RPG-coder-intc avatar Oct 24 '22 01:10 RPG-coder-intc

Perhaps it's better to use subAssign instead of diffAssign?

chykon avatar Oct 24 '22 06:10 chykon

Perhaps it's better to use subAssign instead of diffAssign?

It can be done. What's your say @mkorbel1 ?

RPG-coder-intc avatar Oct 24 '22 16:10 RPG-coder-intc

Why not make postIncr and preIncr support another input (which defaults to 1) so that the same function can support ++ and +=? Then the natural extension for subtraction would be postDecr and preDecr.

mkorbel1 avatar Oct 24 '22 16:10 mkorbel1

Why not make postIncr and preIncr support another input (which defaults to 1) so that the same function can support ++ and +=? Then the natural extension for subtraction would be postDecr and preDecr.

The would be a great addition.

RPG-coder-intc avatar Oct 24 '22 16:10 RPG-coder-intc

I can make Logic addAssign(&ref=Const(value:1)) get reused the function within postIncr or preIncr

RPG-coder-intc avatar Oct 24 '22 16:10 RPG-coder-intc

I can make Logic addAssign(&ref=Const(value:1)) get reused the function within postIncr or preIncr

Not sure what the difference would be between those two, but I guess you can code it to show that

mkorbel1 avatar Oct 24 '22 22:10 mkorbel1