Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Negative float consts
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: Negative float consts

> I recently found the syntax of negative float consts to be annoying.
> You have to write things like this:
> 	two_float_func 1.0 (-. 1.0) 

You could also use
 	two_float_func 1.0 (-1.0) 

> IMO, it is more pleasant to write instead:
> 	two_float_func 1.0 -1.0
> so I tried the following change in the lexer:
> ... and everything worked well !  I think this could be an improvement in
> the readability of numerical programs.

We abandoned this idea, since users seem to like operations without
spaces, writing


and conversely


If we had adopted negative lexems then we have a discrepancy, since
x+1 would have been an addition, while x-1 would have been an
application (interpreted as x(-1)).

In my mind, the advantages of negative lexems overcome the need of
sparse extra spaces (that we already have to add anyway, for instance
in x:=!x+1 (written x:= !x+1, to avoid the interpretation of :=! as a
single operator)). But some users argue that minimum spacing is a
well-established mathematical tradition, so that we have to avoid
mandatory extra spaces as much as possible.

If a rule had to be set, I would vote for mandatory spaces around
operators, with the benefit of negative lexems (and may be a more
liberal lexing rule for identifiers).

Pierre Weis

INRIA, Projet Cristal,,