caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Negative float consts
@ 1997-01-14 16:19 Christian Boos
  1997-01-14 19:59 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Boos @ 1997-01-14 16:19 UTC (permalink / raw)
  To: caml-list


	Hello caml-list,


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) 

IMO, it is more pleasant to write instead:

	two_float_func 1.0 -1.0

so I tried the following change in the lexer:

  | '-'? ['0'-'9']+ '.' ['0'-'9']* (['e' 'E'] ['+' '-']? ['0'-'9']+)?
      { FLOAT (Lexing.lexeme lexbuf) }

... and everything worked well !  I think this could be an improvement in
the readability of numerical programs.

(an analog change may eventually be needed for int constants ?)


-- Christian





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Negative float consts
  1997-01-14 16:19 Negative float consts Christian Boos
@ 1997-01-14 19:59 ` Pierre Weis
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 1997-01-14 19:59 UTC (permalink / raw)
  To: Christian Boos; +Cc: caml-list

Hi,

> 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

        x+1

and conversely

        x-1

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, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-01-14 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-14 16:19 Negative float consts Christian Boos
1997-01-14 19:59 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).