chansey97
2021-11-2 08:08:10

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).


chansey97
2021-11-2 08:57:00

Perhaps xor could be used to avoid duplicate/overlapping.


soegaard2
2021-11-2 11:50:45

Reminds me of the => version of cond (cond [(test) => do-something]]


seanbunderwood
2021-11-2 12:15:11

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.)


badkins
2021-11-2 13:36:11

It seems handy to have an https://en.wikipedia.org/wiki/Material_conditional\|implication function along with and, or, xor, etc.


arifshaikh.astro
2021-11-2 14:31:58

How do I remove the frame around legend in racket plots?


laurent.orseau
2021-11-2 15:07:46

It seems it’s not possible right now. @soegaard2?


chansey97
2021-11-2 16:41:56

@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.


badkins
2021-11-2 17:08:07

@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.


badkins
2021-11-2 17:09:00

What I mean by “as someone would expect” is the truth table is what they would expect.


badkins
2021-11-2 17:10:04

But, I agree the fact that it may not always return boolean? could be confusing.


badkins
2021-11-2 17:11:44

Of course, that’s easily solved by only using expressions that evaluate to a boolean?


chansey97
2021-11-2 17:13:57

@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.


badkins
2021-11-2 17:14:50

If you only use boolean? expressions, it appears to be identical to a logical implication, no?


chansey97
2021-11-2 17:17:14

That’s no problem. But in general we don’t do that, because we assuming (just a convention) #f means failure.


badkins
2021-11-2 17:18:59

Here you go :) (define-syntax-rule (implies? expr1 expr2) (implies (not (not expr1)) (not (not expr2))))


chansey97
2021-11-2 17:19:45

But we original purpose is using that value, not boolean.


badkins
2021-11-2 17:20:15

I didn’t realize that. Where is it stated?


chansey97
2021-11-2 17:23:17

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.


chansey97
2021-11-2 17:24:04

The index-of is not good example, because it can not return a #f as a normal value.


chansey97
2021-11-2 17:27:17

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 .


soegaard2
2021-11-2 21:12:17

I can’t see how to do it either.


soegaard2
2021-11-2 21:31:41

notjack
2021-11-2 21:55:31

You might be interested in rebellion’s option library https://docs.racket-lang.org/rebellion/Option_Values.html