Further exploring racket’s http://the\|boolean, I found something interesting. For example, (implies (test)
(do-something))
It could be read as: (when (test)
(do-something))
And we even can combine them: (implies (a) (implies (b) (implies (c) (z))))
It seems more intuitive than and
(exceptimplies
has no multi args and return #t
if fails)? Ideally, we could write (implies (a) (b) (c) (z))
Aka implies
has no associativity, it’s not equivalent to (implies (implies (implies (a) (b)) (c)) (z))
It seems useless? Any idea of that? I have not found interesting application. In addition, xor
also supports Maybe
semantics, but I have not found any interesting application (it has no multi args as well).
Perhaps xor
could be used to avoid duplicate/overlapping.
Reminds me of the =>
version of cond
(cond [(test) => do-something]]
Racket’s or doesn’t seem that odd to me? It’s how it works in most the dynamic languages I know.
(Python, JavaScript, Ruby, Perl.)
It seems handy to have an https://en.wikipedia.org/wiki/Material_conditional\|implication function along with and
, or
, xor
, etc.
How do I remove the frame around legend in racket plots?
It seems it’s not possible right now. @soegaard2?
@badkins The problem of the implies
is that when antecedent fails, it will return #t
. It may causes confusion. For example, (implies (a) (b))
When (a)
fails, the whole expression returns #t
, but there is another explanation: (a)
and (b)
both succeed, but (b)
returns a value which is #t
. Thus programmers don’t know if it succeed or failed.
This problem also occurs on or
(or (a) (b))
(a)
and (b)
might both return a value which is #f
, just depending on the #f
, programmers don’t know if it is exactly succeed or failed…We know #f
means failure just because convention. I think this is what @sorawee concerned.
@chansey97 did you look at the link I provided? Unless I’m mistaken, Racket’s implies
is simply implementing a logical implication, so it’s exactly as someone would expect.
What I mean by “as someone would expect” is the truth table is what they would expect.
But, I agree the fact that it may not always return boolean?
could be confusing.
Of course, that’s easily solved by only using expressions that evaluate to a boolean?
@badkins Racket’s implies
is not logical implication. (implies expr1 expr2)
is same as (if expr1 expr2 #t)
, expr2
could return a value which not a boolean.
If you only use boolean?
expressions, it appears to be identical to a logical implication, no?
That’s no problem. But in general we don’t do that, because we assuming (just a convention) #f
means failure.
Here you go :) (define-syntax-rule (implies? expr1 expr2)
(implies (not (not expr1)) (not (not expr2))))
But we original purpose is using that value, not boolean.
I didn’t realize that. Where is it stated?
For example, (or (index-of lst1 sym) (index-of lst2 sym))
The explanation of this code is "try and return the first success value, otherwise return #f
, but sometime index-of return #f
.
The index-of is not good example, because it can not return a #f
as a normal value.
There are two options: 1. Use Just
and Nothing
to wrap value, as Haskell do. 2. Create new operators (e.g. <\|>
for or
) which behavior like the current logical operators, and make the current logical operators only deal with boolean. These new operators has semantics of Maybe
and assuming Nothing
= #f
.
I can’t see how to do it either.
I think, the relevant parts of the plot source is around here. Maybe. https://github.com/racket/plot/blob/9df19f3835e86cb385a78384f2f57bb2281265fd/plot-lib/plot/private/common/plot-device.rkt#L785
You might be interested in rebellion’s option
library https://docs.racket-lang.org/rebellion/Option_Values.html