| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | src/ataxic.erl | 6 | ||||
| -rw-r--r-- | src/ataxic_sugar.erl | 32 |
2 files changed, 24 insertions, 14 deletions
diff --git a/src/ataxic.erl b/src/ataxic.erl index 195d77f..4d829f3 100644 --- a/src/ataxic.erl +++ b/src/ataxic.erl @@ -126,7 +126,7 @@ -export([apply_to/2, matches/2]). --export([optimize/1]). +-export([optimize/1, is_constant/1]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -378,3 +378,7 @@ matches (OP, Entry) -> true -> true; _ -> false end. + +-spec is_constant (basic()) -> boolean(). +is_constant (#const{}) -> true; +is_constant(_) -> false. diff --git a/src/ataxic_sugar.erl b/src/ataxic_sugar.erl index 3098196..7f6e441 100644 --- a/src/ataxic_sugar.erl +++ b/src/ataxic_sugar.erl @@ -64,20 +64,26 @@ update_orddict_element (IX, OP) -> store, [ ataxic:constant(IX), - ataxic:sequence ( - [ - ataxic:apply_function - ( - orddict, - fetch, - [ - ataxic:constant(IX), - ataxic:current_value() - ] - ), - OP - ] + case ataxic:is_constant(OP) of + true -> OP; + false -> + ataxic:sequence + ( + [ + ataxic:apply_function + ( + orddict, + fetch, + [ + ataxic:constant(IX), + ataxic:current_value() + ] + ), + OP + ] + ) + end ), ataxic:current_value() ] |


