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.
True + True

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);
nagle@user-PC ~/junk
$ gcc booladd.c

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

In Go, it's an error:

package main

import (

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


Follow ups

Related Discussions

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



site design / logo © 2022 Grokbase