سؤال

Is there a programming language in which we can write something like:

a => b

to compute implication? (where a and b are booleans)

The closest I can find is in Scala:

a <= b

But it looks completely different from the actual meaning of "implication".

هل كانت مفيدة؟

المحلول

So the winner is Scala:

implicit class BooleanMagic(val b: Boolean) extends AnyVal {
  def ==>(other: =>Boolean) = !b || other
}

Thanks to that:

> true ==> false
res0: Boolean = false

> false ==> (throw new Exception("I'm the president"))
res1: Boolean = true
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top