News for hackers. Stuff that matters.
Re:An Honest Look at Urbit by riverlong on Monday October 04, 2021 @12:23AM (#28743034)
Where in C is 0 truthy (or 1 falsy)?
Re:An Honest Look at Urbit by jstanley on Monday October 04, 2021 @12:36AM (#28743123)
strcmp,memcmp,etc. return 0 for equality, maybe you'd count that? But it's not really indicating "true", more "no difference".

main() returns 0 for success, but I expect that is owed more to Unix.

A lot of (e.g. Linux) system calls return 0 for success and an error value on error, but again that's more down to Unix than C.

Re:An Honest Look at Urbit by riverlong on Monday October 04, 2021 @12:43AM (#28743175)
I wouldn't count strcmp, etc. It returns < 0 if str1 is shorter and > 0 if str1 is longer. Returning 0 means there is 0 difference. That's not a True/False.

"0" is not a "truthy" exit code for a system call, it rather denotes the absence of an error.

In my view, a value X being "truthy" means that `bool(X)` evaluates to TRUE, or `if(X)` gets executed.

Re:An Honest Look at Urbit by vegetablepotpie on Monday October 04, 2021 @12:27AM (#28743062)
I think it’s where many functions return 0 when they are successful.
Re:An Honest Look at Urbit by leeoniya on Monday October 04, 2021 @12:33AM (#28743098)
maybe cause there's only one way to succeed and many ways to error. 0 success and 1..N are error codes.

what is a reasonable alternative?

(this isnt the same as 0 false and 1 true)

Re:An Honest Look at Urbit by toomim on Monday October 04, 2021 @03:14AM (#28743988)
Ok, but:

     success vs. fail
is different than:

     true vs. false
They're both binary, but only one is boolean.
Re:An Honest Look at Urbit by voxic11 on Monday October 04, 2021 @01:40AM (#28743433)
Re:An Honest Look at Urbit by saagarjha on Monday October 04, 2021 @01:48AM (#28743477)
I think those go in the opposite direction.
Re:An Honest Look at Urbit by foobiekr on Monday October 04, 2021 @12:26AM (#28743059)
Well, unix, as in exit codes.
Re:An Honest Look at Urbit by riverlong on Monday October 04, 2021 @12:30AM (#28743083)
Yeah, exit codes aren't what I'm talking about here.

In Hoon/Nock, `if(0)` literally gets interpreted as True. That's insane.

Re:An Honest Look at Urbit by tromp on Monday October 04, 2021 @06:22AM (#28745009)
In lambda calculus, true and false are conventionally represented as functions

    lambda x. lambda y. x
and

    lambda x. lambda y. y
so that "if b then x else y" is represented by "b x y". When identifying booleans with bits, it seems natural to write this as "bit x_0 x_1" rather than "bit x_1 x_0" where the arguments seem to be in the wrong order.

This is one possible justification for identifying true with 0 and false with 1.

Re:An Honest Look at Urbit by knownjorbist on Monday October 04, 2021 @12:36AM (#28743129)
It's not insane, just dissimilar to what you're used to.
Re:An Honest Look at Urbit by creata on Monday October 04, 2021 @12:52AM (#28743227)
Okay, it's not insane, it just breaks from a convention followed by practically every programming language (and every logic / engineering / computing course) where integers can be interpreted as booleans. And that might be okay if there's a good reason, but the reasons given are pretty awful:

https://news.ycombinator.com/item?id=11852434

Re:An Honest Look at Urbit by nitrogen on Monday October 04, 2021 @02:47AM (#28743815)
Ruby is one popular example of a language with a truthy zero. This is to allow the use of truthiness to detect the presence of a value (as long as the value isn't false), even if the value is zero. Say I wanted to allow an environment variable to override a value in my code. I could do something like this:

    a = ENV['A']&.to_i || 1
and then run the program with A=0 to set a to 0.
Re:An Honest Look at Urbit by jstanley on Monday October 04, 2021 @03:12AM (#28743981)
Perl has this too. The string "0 but true" is truthy, but is 0 as a numeric value.

(Any string starting with 0 that doesn't evaluate to a different number also works - but "0 but true" is specifically exempt from causing warnings).

DBI uses "0E0" instead, which I guess more reliably evaluates to 0 outside Perl, and still doesn't cause warnings.

Re:An Honest Look at Urbit by int_19h on Monday October 04, 2021 @06:04AM (#28744914)
That approach is not unreasonable per se. But 1 being false is much harder to rationalize.
Re:An Honest Look at Urbit by praptak on Monday October 04, 2021 @12:47AM (#28743199)
Dissimilarity for no good reason is, well, maybe not insanity but plain old dumb. Unless we're talking fashion not software projects, hence the "vanity" classification.
Re:An Honest Look at Urbit by pasquinelli on Monday October 04, 2021 @01:01AM (#28743271)
i don't really see why. if anything is insane, it's interpreting a number as true or false. but if you're doing that anyway, then you pick a number for false, or you pick a number for true. 0 is a natural number to pick for whichever truth value, because it's the base case of the natural numbers.

it's unconventional, but no more insane than 0 = false, which, again, _is_ insane, but conventional.

i'm not bothered either way

Re:An Honest Look at Urbit by drdeca on Monday October 04, 2021 @02:53AM (#28743852)
Using 0 as false and 1 as true has the benefit that + (mod 2) becomes xor and * becomes and.

(or, if instead of mod 2, you use min(1,a + b) to keep things in the set, then + becomes or )

To use 0 as true and 1 as false, you don't get nice things like this. It's not nice.

Well.. I guess * becomes or. But, + (mod 2) becomes, uh, xnor , and (min(1,a+b)) becomes, and...

ok well I guess that's not as bad as I thought.

Still a bad decision imo though.