Deutsch   English   Français   Italiano  
<vrkb6m$7bc3$1@solani.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: Mild Shock <janburse@fastmail.fm>
Newsgroups: comp.lang.prolog
Subject: Re: What about allowing numbers 1e19, etc.. (Re: Novacore is a Prolog
 profile that explores various relaxations)
Date: Fri, 21 Mar 2025 19:29:43 +0100
Message-ID: <vrkb6m$7bc3$1@solani.org>
References: <vrkadh$7arh$1@solani.org> <vrkanf$7b21$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 21 Mar 2025 18:29:42 -0000 (UTC)
Injection-Info: solani.org;
	logging-data="241027"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101
 Firefox/128.0 SeaMonkey/2.53.20
Cancel-Lock: sha1:jnbzKKvTow9iVmKg/k/q//9+mlQ=
X-User-ID: eJwFwQkBwDAIA0BLfAkgh7bDv4Tdwam8GQQDi7VSjtlr89XOGK+AeIn0lF6KpPhpJ74jezGr1XyYRI9jfhDJFA4=
In-Reply-To: <vrkanf$7b21$1@solani.org>

Hi,

Interestingly unknowningly, to facilitate JSON
parsing, I had already partially introduced such
numbers. Namely I have already:

/* Dogelog Player 1.3.0 */
?- number_codes(X, "1e19").
X = 1.0e19.

SWI-Prolog consequently does the same:

/* SWI-Prolog 9.3.20 */
?- number_codes(X, "1e19").
X = 1.0e+19.

So all that remains is change the tokenizer a little
bit to allow 1e19. And then we can be lazy and
write 1e19, which is the winner in length, i.e. the

shortes variant among these variants:

- 10.0^19
- 10**19  /* except for SWI-Prolog 9.3.20 */
- 1.0e19
- 1e19

Bye

Mild Shock schrieb:
> Hi,
> 
> Somehow I have the feeling it doesn't make
> sense to only recognize floating point numbers
> as number literals that have a period in it.
> 
> Most programming languages I have encountered
> also recognize floating point numbers when
> they have an exponent e or E in it:
> 
> - Python:
>  >>> 1e19
> 1e+19
> 
> - JavaScript:
>  > 1e19
> 10000000000000000000
> 
> JavaScript is a little special. Since it has a
> integer subset inside there floating point numbers.
> Now I find that SWI-Prolog also allows 1e19:
> 
> /* SWI-Prolog 9.3.20 */
> ?- X = 1e19.
> X = 1.0e+19.
> 
> I think this is a good idea. Since there is no
> confusion. Most Prolog systems I checked never
> alias an operator e with a number:
> 
> /* SWI-Prolog 9.3.20 */
> ?- op(500,yfx,e).
> true.
> 
> ?- X = 1 e 2.
> X = 1 e 2.
> 
> Bye
> 
> Mild Shock schrieb:
>> Interestingly a flag strict_iso could solve a few
>> vexing problems. For example the ISO core standard
>> did only mention floor/1 with signature F → I.
>>
>> So in GNU Prolog I can do:
>>
>> /* GNU Prolog 1.5.0 */
>>
>> ?- current_prolog_flag(strict_iso, X).
>> X = on
>> yes
>>
>> ?- X is floor(1).
>> uncaught exception: error(type_error(float,1),(is)/2)
>>
>> ?- set_prolog_flag(strict_iso, off).
>> yes
>>
>> ?- X is floor(1).
>> X = 1
>> yes
>>
>> A few Prolog systems don’t share the above behavior,
>> like SWI-Prolog for example doesn’t throw the type error.
>> Also SWI-Prolog has nowhere a flag strict_iso.
>>
>> Currently I have changed my Prolog system to tell me:
>>
>> /* Dogelog Player 1.3.1 */
>>
>> ?- current_prolog_flag(strict_iso, X).
>> X = off.
>