Eiffel: is there a way to express a double implies clause in eiffel?

岁酱吖の 提交于 2020-01-17 02:40:06

问题


Like double bind in psychology, is there a way to tell that one expression implies another and reversely?

valid_last_error: attached last_error implies not attached last_success_message
valid_last_success_message: attached last_success_message implies not attached last_error

would be something like

valid_last_error: attached last_error double_binded_not attached last_success_message

which could be equivalent to

valid_last_error: attached last_error never_with attached last_success_message
  • T stands for True boolean expression
  • F for False
  • R for Result

implies (a, b: BOOLEAN): BOOLEAN

a b R
T T T
T F F
F T T
F F T

and (a, b: BOOLEAN): BOOLEAN

a b R
T T T
T F F
F T F
F F F

or (a, b: BOOLEAN): BOOLEAN

a b R
T T T
T F T
F T T
F F F

xor (a, b: BOOLEAN): BOOLEAN

a b R
T T F
T F T
F T T
F F F

double_implies (a, b: BOOLEAN): BOOLEAN

a b R
T T F
T F T
F T T
F F T

as a maybe more explaining example (more known) instead of writing

invalid_index_implies_off: index < 1 implies off
off_implies_invalid_index: off implies index < 1

we could write:

index_coherent_with_off: index < 1 never_both off

which would just add a function to BOOLEAN class such as

alias never_with, alias reversible_implies (v: like Current): like Current
    do
        if Current and v then
            Result := False
        else
            Result := True
        end
    end

Hope now everybody got my point... I don't know if there is such arithmetic operator.

We could extend it for a variable number of parameters


回答1:


The only answer for my question is to define a function in an util class like

feature -- could be in class BOOLEAN

double_implies, reversible_implies, never_both (a, b: BOOLEAN): BOOLEAN
        -- Into boolean class with never_with
    do
        if a and b then
            Result := False
        else
            Result := True
        end
    end


来源:https://stackoverflow.com/questions/52763915/eiffel-is-there-a-way-to-express-a-double-implies-clause-in-eiffel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!