FAQ
I did never say that it is purposeful to allow +, -, * and / on booleans.
The only things I asked for are & and | (and possible &^) as you sometimes
really don't want the short-circuit functionality.

Am Sonntag, 3. März 2013 00:47:04 UTC+1 schrieb Nate Finch:
Making true + true == false is not really any better than 2.
On Saturday, March 2, 2013 5:52:09 PM UTC-5, Robert Clausecker wrote:

I think you missed the part where I say »... as an unsigned *one bit*integer...«. One bit (as in either 0 [false] or 1 [true]) especially means
that True + True can never yield 2. 2 is not representable in one bit.

Am Samstag, 2. März 2013 20:49:39 UTC+1 schrieb John Nagle:
On 3/1/2013 2:01 PM, Robert Clausecker wrote:
I don't see how viewing Bool as an unsigned one bit integer yields True +
True = 2.
It does in Python.
python
True + True
2

It does in C:

$ cat booladd.c
#include <stdio.h>
#include <stdbool.h>

int main(int argc, char* argv[])
{ int n = true + true;
printf("n = %d\n", n);
return(0);
}
nagle@user-PC ~/junk
$ gcc booladd.c

nagle@user-PC ~/junk
$ ./a.exe
n = 2

In Go, it's an error:

package main

import (
"fmt"
)

func main() {
var n int
n = true + true
fmt.Printf("n = %d\n", n)
}

src\examples\booladd\booladd.go:9: invalid operation: true + true
(operator + not defined on bool)

That's the right answer. There's an argument for defining the
arithmetic operators for booleans ("+" is AND, "*" is OR, etc.)
but while it makes set theory people happy, it confuses C
programmers.
Please tell me what you mean with �retrofitting�.
In the beginning, C did not have a Boolean type. It was added later.
In the beginning, Python did not have a Boolean type. It was added
later.

John Nagle
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 20 of 21 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 1, '13 at 7:02p
activeMar 3, '13 at 2:38a
posts21
users9
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase