Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Numeric literals in other than base 10 - was Annoying octal notation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  19 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
James Harris  
View profile  
 More options Aug 22 2009, 5:54 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Sat, 22 Aug 2009 14:54:41 -0700 (PDT)
Local: Sat, Aug 22 2009 5:54 pm
Subject: Numeric literals in other than base 10 - was Annoying octal notation
On 22 Aug, 10:27, David <71da...@libero.it> wrote:

... (snipped a discussion on languages and other systems interpreting
numbers with a leading zero as octal)

...

> >        Or Ada's        16#FF#, 8#377#...
> >        I forget if DEC/VMS FORTRAN or Xerox Sigma FORTRAN used x'FF' or
> >   'FF'x, and o'377' or '377'o

...

> What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ?

They look good - which is important. The trouble (for me) is that I
want the notation for a new programming language and already use these
characters. I have underscore as an optional separator for groups of
digits - 123000 and 123_000 mean the same. The semicolon terminates a
statement. Based on your second idea, though, maybe a colon could be
used instead as in

  2:1011, 8:7621, 16:c26b

I don't (yet) use it as a range operator.

I could also use a hash sign as although I allow hash to begin
comments it cannot be preceded by anything other than whitespace so
these would be usable

  2#1011, 8#7621, 16#c26b

I have no idea why Ada which uses the # also apparently uses it to end
a number

  2#1011#, 8#7621#, 16#c26b#

Copying this post also to comp.lang.misc. Folks there may either be
interested in the discussion or have comments to add.

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mel  
View profile  
 More options Aug 22 2009, 7:16 pm
Newsgroups: comp.lang.python, comp.lang.misc
Followup-To: comp.lang.python
From: Mel <mwil...@the-wire.com>
Date: Sat, 22 Aug 2009 19:16:39 -0400
Local: Sat, Aug 22 2009 7:16 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

James Harris wrote:
> I have no idea why Ada which uses the # also apparently uses it to end
> a number

>   2#1011#, 8#7621#, 16#c26b#

Interesting.  They do it because of this example from
<http://archive.adaic.com/standards/83rat/html/ratl-02-01.html#2.1>:

2#1#E8                    -- an integer literal of value 256

where the E prefixes a power-of-2 exponent, and can't be taken as a digit of
the radix.  That is to say

16#1#E2

would also equal 256, since it's 1*16**2 .

        Mel.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Harter  
View profile  
 More options Aug 22 2009, 11:38 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: c...@tiac.net (Richard Harter)
Date: Sun, 23 Aug 2009 03:38:59 GMT
Local: Sat, Aug 22 2009 11:38 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On Sat, 22 Aug 2009 14:54:41 -0700 (PDT), James Harris

I opine that a letter is better; special characters are a
valuable piece of real estate.  However for floating point you
need at least three letters because a floating point number has
three parts: the fixed point point, the exponent base, and the
exponent.  Now we can represent the radices of the individual
parts with the 'r'scheme, e.g., 2r101001, but we need separate
letters to designate the exponent base and the exponent.  B and E
are the obvious choices, though we want to be careful about a
confusion with 'b' in hex.  For example, using 'R',

3R20.1B2E16Rac

is 20.1 in trinary (6 1/3) times 2**172 (hex ac).

I grant that this example looks a bit gobbledegookish, but normal
usage would be much simpler.  The notation doesn't handle
balanced trinary; however I opine that balanced trinary requires
special notation.

Richard Harter, c...@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
No one asks if a tree falls in the forest
if there is no one there to see it fall.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmitry A. Kazakov  
View profile  
 More options Aug 23 2009, 4:21 am
Newsgroups: comp.lang.python, comp.lang.misc
From: "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
Date: Sun, 23 Aug 2009 10:21:52 +0200
Local: Sun, Aug 23 2009 4:21 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

If you are going Unicode, you could use the mathematical notation, which is

   1011<sub>2</sub>, 7621<sub>8</sub>, c26b<sub>16</sub>

(subscript specification of the base). Yes, it might be difficult to type
(:-)), and would require some look-ahead in the parser. One of the
advantages of Ada notation, is that a numeric literal always starts with
decimal digit. That makes things simple for a descent recursive parser. I
guess this choice was intentional, back in 1983 a complex parser would eat
too much resources...

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
garabik-news-2005...@kassiopeia.juls.savba.sk  
View profile  
 More options Aug 23 2009, 6:08 am
Newsgroups: comp.lang.python, comp.lang.misc
From: garabik-news-2005...@kassiopeia.juls.savba.sk
Date: Sun, 23 Aug 2009 10:08:43 +0000 (UTC)
Local: Sun, Aug 23 2009 6:08 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
In comp.lang.python James Harris <james.harri...@googlemail.com> wrote:

> On 22 Aug, 10:27, David <71da...@libero.it> wrote:

...

>> What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ?

> They look good - which is important. The trouble (for me) is that I
> want the notation for a new programming language and already use these
> characters. I have underscore as an optional separator for groups of
> digits - 123000 and 123_000 mean the same.

Why not just use the space? 123 000 looks better than 123_000, and
is not syntactically ambiguous (at least in python). And as it
already works for string literals, it could be applied to numbers, too…

--
 -----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
 -----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Finney  
View profile  
 More options Aug 23 2009, 10:01 am
Newsgroups: comp.lang.python, comp.lang.misc
Followup-To: comp.lang.python
From: Ben Finney <ben+pyt...@benfinney.id.au>
Date: Mon, 24 Aug 2009 00:01:46 +1000
Local: Sun, Aug 23 2009 10:01 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

garabik-news-2005...@kassiopeia.juls.savba.sk writes:
> Why not just use the space? 123 000 looks better than 123_000, and is
> not syntactically ambiguous (at least in python). And as it already
> works for string literals, it could be applied to numbers, too…

+1 to all this. I think this discussion was had many months ago, but
can't recall how it ended back then.

--
 \              “Only the educated are free.” —Epictetus, _Discourses_ |
  `\                                                                   |
_o__)                                                                  |
Ben Finney


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bartc  
View profile  
 More options Aug 23 2009, 11:57 am
Newsgroups: comp.lang.python, comp.lang.misc
From: "bartc" <ba...@freeuk.com>
Date: Sun, 23 Aug 2009 15:57:57 GMT
Local: Sun, Aug 23 2009 11:57 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

<garabik-news-2005...@kassiopeia.juls.savba.sk> wrote in message

news:h6r4fb$18a$1@aioe.org...

> In comp.lang.python James Harris <james.harri...@googlemail.com> wrote:
>> On 22 Aug, 10:27, David <71da...@libero.it> wrote:

> ...

>>> What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ?

>> They look good - which is important. The trouble (for me) is that I
>> want the notation for a new programming language and already use these
>> characters. I have underscore as an optional separator for groups of
>> digits - 123000 and 123_000 mean the same.

> Why not just use the space? 123 000 looks better than 123_000, and
> is not syntactically ambiguous (at least in python).

If the purpose is to allow "_" to introduce a non-base ten literal, using
this to enter a hexadecimal number might result in:

16_1234 ABCD

I'd say that that was ambiguous (depending on whether a name can follow a
number; if you have a operator called ABCD, then that would be a problem).
Unless each block of digits used it's own base:

16_1234 16_ABCD

> And as it
> already works for string literals, it could be applied to numbers, too…

String literals are conveniently surround by quotes, so they're a bit easier
to recognise.

--
Bart


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Harris  
View profile  
 More options Aug 23 2009, 4:55 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Sun, 23 Aug 2009 13:55:19 -0700 (PDT)
Local: Sun, Aug 23 2009 4:55 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 04:38, c...@tiac.net (Richard Harter) wrote:

Very very true.

>  However for floating point you
> need at least three letters because a floating point number has
> three parts: the fixed point point, the exponent base, and the
> exponent.  Now we can represent the radices of the individual
> parts with the 'r'scheme, e.g., 2r101001, but we need separate
> letters to designate the exponent base and the exponent.  B and E
> are the obvious choices, though we want to be careful about a
> confusion with 'b' in hex.  For example, using 'R',

> 3R20.1B2E16Rac

Ooh err!

> is 20.1 in trinary (6 1/3) times 2**172 (hex ac).

> I grant that this example looks a bit gobbledegookish,

You think? :-)

> but normal
> usage would be much simpler.  The notation doesn't handle
> balanced trinary; however I opine that balanced trinary requires
> special notation.

When the programmer needs to construct such values how about allowing
him or her to specify something like

  (20.1 in base 3) times 2 to the power of 0xac

Leaving out how to specify (20.1 in base 3) for now this could be

  (20.1 in base 3) * 2 ** 0xac

The compiler could convert this to a constant.

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Harris  
View profile  
 More options Aug 23 2009, 5:42 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Sun, 23 Aug 2009 14:42:16 -0700 (PDT)
Local: Sun, Aug 23 2009 5:42 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 00:16, Mel <mwil...@the-wire.com> wrote:

> James Harris wrote:
> > I have no idea why Ada which uses the # also apparently uses it to end
> > a number

> >   2#1011#, 8#7621#, 16#c26b#

> Interesting.  They do it because of this example from
> <http://archive.adaic.com/standards/83rat/html/ratl-02-01.html#2.1>:

Thanks for providing an explanation.

> 2#1#E8                    -- an integer literal of value 256

> where the E prefixes a power-of-2 exponent, and can't be taken as a digit of
> the radix.  That is to say

> 16#1#E2

> would also equal 256, since it's 1*16**2 .

Here's another suggested number literal format. First, keep the
familar 0x and 0b of C and others and to add 0t for octal. (T is the
third letter of octal as X is the third letter of hex.) The numbers
above would be

  0b1011, 0t7621, 0xc26b

Second, allow an arbitrary number base by putting base and number in
quotes after a zero as in

  0"2:1011", 0"8:7621", 0"16:c26b"

This would work for arbitrary bases and allows an exponent to be
tagged on the end. It only depends on zero followed by a quote mark
not being used elsewhere. Finally, although it uses a colon it doesn't
take it away from being used elsewhere in the language.

Another option:

  0.(2:1011), 0.(8:7621), 0.(16:c26b)

where the three characters "0.(" begin the sequence.

Comments? Improvements?

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Harris  
View profile  
 More options Aug 23 2009, 5:45 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Sun, 23 Aug 2009 14:45:39 -0700 (PDT)
Local: Sun, Aug 23 2009 5:45 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 21:55, James Harris <james.harri...@googlemail.com> wrote:

...

Using the suggestion from another post would convert this to

  0.(3:20.1) * 2 ** 0xac


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott David Daniels  
View profile  
 More options Aug 23 2009, 6:50 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: Scott David Daniels <Scott.Dani...@Acm.Org>
Date: Sun, 23 Aug 2009 15:50:29 -0700
Local: Sun, Aug 23 2009 6:50 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

James Harris wrote:...
> Another option:

>   0.(2:1011), 0.(8:7621), 0.(16:c26b)

> where the three characters "0.(" begin the sequence.

> Comments? Improvements?

I did a little interpreter where non-base 10 numbers
(up to base 36) were:

     .7.100   == 64  (octal)
     .9.100   == 100 (decimal)
     .F.100   == 256 (hexadecimal)
     .1.100   == 4   (binary)
     .3.100   == 9   (trinary)
     .Z.100   == 46656 (base 36)
Advantages:
Tokenizer can recognize chunks easily.
Not visually too confusing,
No issue of what base the base indicator is expressed in.

--Scott David Daniels
Scott.Dani...@Acm.Org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bartc  
View profile  
 More options Aug 23 2009, 7:04 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: "bartc" <ba...@freeuk.com>
Date: Sun, 23 Aug 2009 23:04:37 GMT
Local: Sun, Aug 23 2009 7:04 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

"Scott David Daniels" <Scott.Dani...@Acm.Org> wrote in message
news:kN2dnSZR5b0BWAzXnZ2dnUVZ_s-dnZ2d@pdx.net...

It can be assumed however that .9. isn't in binary?

That's a neat idea. But an even simpler scheme might be:

.octal.100
.decimal.100
.hex.100
.binary.100
.trinary.100

until it gets to this anyway:

.thiryseximal.100

--
Bartc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piet van Oostrum  
View profile  
 More options Aug 24 2009, 3:51 am
Newsgroups: comp.lang.python, comp.lang.misc
From: Piet van Oostrum <p...@cs.uu.nl>
Date: Mon, 24 Aug 2009 09:51:37 +0200
Local: Mon, Aug 24 2009 3:51 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

I wonder how you wrote that interpreter, given that some answers are wrong.
--
Piet van Oostrum <p...@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Harris  
View profile  
 More options Aug 24 2009, 4:25 am
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Mon, 24 Aug 2009 01:25:35 -0700 (PDT)
Local: Mon, Aug 24 2009 4:25 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On 24 Aug, 09:05, Erik Max Francis <m...@alcyone.com> wrote:

...

Why do you say that here? MRAB's suggestion is one of the clearest
there has been. And it incorporates the other requirements: starts
with a digit, allows an appropriate alphabet, has no issues with
spacing digit groups, shows clearly where the number ends and could
take an exponent suffix.

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Max Francis  
View profile  
 More options Aug 24 2009, 4:30 am
Newsgroups: comp.lang.python, comp.lang.misc
From: Erik Max Francis <m...@alcyone.com>
Date: Mon, 24 Aug 2009 01:30:11 -0700
Local: Mon, Aug 24 2009 4:30 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

In your opinion.  Obviously not in others.  Which is pretty obviously
what I meant, so the rhetorical question is a bit weird here.

There's a reason that languages designed by committee end up horrific
nightmares.

--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Do not seek death. Death will find you.
    -- Dag Hammarskjold


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Harris  
View profile  
 More options Aug 24 2009, 4:47 am
Newsgroups: comp.lang.python, comp.lang.misc
From: James Harris <james.harri...@googlemail.com>
Date: Mon, 24 Aug 2009 01:47:44 -0700 (PDT)
Local: Mon, Aug 24 2009 4:47 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On 24 Aug, 09:30, Erik Max Francis <m...@alcyone.com> wrote:

Don't get defensive.... Yes, in my opinion, if you like, but you can't
say "obviously not in others" as no one else but you has commented on
MRAB's suggestion.

Also, when you say "This is starting to get truly nutty" would you
accept that that's in your opinion?

> There's a reason that languages designed by committee end up horrific
> nightmares.

True but I would suggest that mistakes are also made by designers who
do not seek the opinions of others. There's a balance to be struck
between a committee and an ivory tower.

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NevilleDNZ  
View profile  
 More options Aug 24 2009, 8:22 am
Newsgroups: comp.lang.python, comp.lang.misc
From: NevilleDNZ <neville...@gmail.com>
Date: Mon, 24 Aug 2009 05:22:42 -0700 (PDT)
Local: Mon, Aug 24 2009 8:22 am
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation
On Aug 23, 9:42 pm, James Harris <james.harri...@googlemail.com>
wrote:

> The numbers above would be

>   0b1011, 0t7621, 0xc26b

Algol68 has the type BITS, that is converted to INT with the ABS
operator.
The numbers above would be:

>   2r1011, 8r7621, 16rc26b

"r" is for radix: http://en.wikipedia.org/wiki/Radix

The standard supports 2r, 4r, 8r & 16r only.

The standard supports LONG BITS, LONG LONG BITS etc, but does not
include UNSIGNED.

Compare gcc's:

bash$ cat num_lit.c
#include <stdio.h>
main(){
  printf("%d %d %d %d\n",0xffff,07777,9999,0b1111);

}

bash$ ./num_lit
65535 4095 9999 15

With Algol68's: https://sourceforge.net/projects/algol68/

bash$ cat num_lit.a68
main:(
  printf(($g$,ABS 16rffff,ABS 8r7777,9999,ABS 2r1111,$l$))
)

bash$ algol68g ./num_lit.a68
     +65535      +4095      +9999        +15

Enjoy
N


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott David Daniels  
View profile  
 More options Aug 24 2009, 12:18 pm
Newsgroups: comp.lang.python, comp.lang.misc
From: Scott David Daniels <Scott.Dani...@Acm.Org>
Date: Mon, 24 Aug 2009 09:18:20 -0700
Local: Mon, Aug 24 2009 12:18 pm
Subject: Re: Numeric literals in other than base 10 - was Annoying octal notation

Obviously I started with a different set of examples and edited after
starting to make a table that could be interpretted in each base.  After
doing that, I forgot to double check, and lo and behold .F.1000 = 46656,
while .F.100 = 1296.  Since it has been decades since I've had access
to that interpreter, this is all from memory.

--Scott David Daniels
Scott.Dani...@Acm.Org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Numeric literals in other than base 10" by robin
robin  
View profile  
 More options Aug 27 2009, 12:07 pm
Newsgroups: comp.lang.python, comp.lang.misc, comp.lang.pl1
From: "robin" <robi...@bigpond.com>
Date: Thu, 27 Aug 2009 16:07:20 GMT
Local: Thurs, Aug 27 2009 12:07 pm
Subject: Re: Numeric literals in other than base 10
"James Harris" <james.harri...@googlemail.com> wrote in message

news:bc3607b3-7fdd-43fd-8ede-66ac3f597403@32g2000yqj.googlegroups.com...
On 22 Aug, 10:27, David <71da...@libero.it> wrote:

>They look good - which is important. The trouble (for me) is that I
>want the notation for a new programming language and already use these
>characters. I have underscore as an optional separator for groups of
>digits - 123000 and 123_000 mean the same. The semicolon terminates a
>statement. Based on your second idea, though, maybe a colon could be
>used instead as in

XPL uses "(2)1011" for base 4,
"(3)03212" for octal,
"(4)0741" for base 16.

PL/I uses 8FXN for numeric hex and X suffix for a hex character constant.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »