> But you are probably asking for new syntax and types because there are
> intangibles that I don't see, since I don't have occasion to usecomplexnumbers. Can you explain the practical benefit? Is it
> legibility? Greater accessibility for those whose focus is not
> programming?
Kevin, you have to understand that a lot of calculations the the realm
of signal processing (radio & cell phone communication, computer
signal processing) is dealing with complex numbers, as eg. the
calcualtion of electical impedance is. No-native support for complex
numbers is like digging a grave for an elephant with a kids shovel;
sure it works, it's just overly tedious!
Johann
>> But you are probably asking for new syntax and types because there are
>> intangibles that I don't see, since I don't have occasion to use
>> complexnumbers. �Can you explain the practical benefit? Is it
>> legibility? �Greater accessibility for those whose focus is not
>> programming?
>
>Kevin, you have to understand that a lot of calculations the the realm
>of signal processing (radio & cell phone communication, computer
>signal processing) is dealing with complex numbers, as eg. the
>calcualtion of electical impedance is. No-native support for complex
>numbers is like digging a grave for an elephant with a kids shovel;
>sure it works, it's just overly tedious!
To illustrate, when working with complex numbers one wants to be able to
write:
a = b+c*d
rather than
a = add(b,mul(c,d))
One scheme that's popped into my mind would be to make the suffix "i",
appended to numeric constants, denote an imaginary number, so that:
z := 2 + 3i
would mean that the complex variable z was initialized with a real part
of 2, and an imaginary part of 3. (Despite the lack of decimal points,
this would be a floating-point complex number; hardly anyone does complex
arithmetic with integers, so it's safe to neglect that case.) But I
haven't thought about the ramifications of this as regards the rest of
the language, so am just tossing it out to be shot down.
--
Norman Yarvin http://yarchive.net
On Jan 16, 6:48 pm, Norman Yarvin <yar...@yarchive.net> wrote:
>
> One scheme that's popped into my mind would be to make the suffix "i",
> appended to numeric constants, denote an imaginary number, so that:
>
> z := 2 + 3i
>
> would mean that the complex variable z was initialized with a real part
> of 2, and an imaginary part of 3. (Despite the lack of decimal points,
> this would be a floating-point complex number; hardly anyone does complex
> arithmetic with integers, so it's safe to neglect that case.) But I
> haven't thought about the ramifications of this as regards the rest of
> the language, so am just tossing it out to be shot down.
>
It seems like Go's current parser is very simplistic, in this context
it would first encounter an integer literal, the '+' operator and
later an integer literal. As soon it parses the 'i', the whole
expression has suddenly to be interpreted as a complex literal, with
'+' beeing kind of 'separator'. This would certainly add strange code
paths into the present parser.
On Jan 16, 3:01 am, Ken Thompson <k...@google.com> wrote:
> i am interested in this and hope to do something.
>
What about general literal prefixes?. A complex literal may get
anotated as CP'23+6' , with variable substitution as C'x+9' or C'x+y',
wtih '+' kind of mini-DSL. Other types might get annotations such as
S'Blah' for a string literal or I'4567' Integer literal.
Would be perfectly doable with a macro system or a rewritting parser.
Johann
>On Jan 16, 6:48 pm, Norman Yarvin <yar...@yarchive.net> wrote:
>
>> One scheme that's popped into my mind would be to make the suffix "i",
>> appended to numeric constants, denote an imaginary number, so that:
>>
>> z := 2 + 3i
>>
>> would mean that the complex variable z was initialized with a real part
>> of 2, and an imaginary part of 3. �(Despite the lack of decimal points,
>> this would be a floating-point complex number; hardly anyone does complex
>> arithmetic with integers, so it's safe to neglect that case.)
>
>It seems like Go's current parser is very simplistic, in this context
>it would first encounter an integer literal, the '+' operator and
>later an integer literal. As soon it parses the 'i', the whole
>expression has suddenly to be interpreted as a complex literal, with
>'+' beeing kind of 'separator'.
Nah, it'd be an integer literal, a + operator, and then a complex
literal; adding the integer literal and the complex literal would yield
another complex literal.