From: Pierre Weis <Pierre.Weis@inria.fr>
To: reig@dcs.gla.ac.uk
Cc: caml-list@inria.fr
Subject: Re: Question on language design (keywords vs Pervasives)
Date: Sun, 20 Aug 2000 21:01:03 +0200 (MET DST) [thread overview]
Message-ID: <200008201901.VAA17272@pauillac.inria.fr> (raw)
In-Reply-To: <200008180207.LAA05417@ropas.kaist.ac.kr> from Fermin Reig at "Aug 18, 100 11:07:05 am"
> I'm curious about some interesting language design choices in ocaml
> 3.0.
>
> * "raise", "exn" are not keywords, but definitions in the Pervasives module.
>
> This means that I can rebind them, for ex., like this:
[...]
> Similarly for other types in the Pervasives module, like int,
> etc. (However, "exception", for declaring a new exception is a
> reserved word).
You encounter here the border between syntax, language design choices
and semantics: ``exception'' must be a keyword, since it introduces a
syntactic construct (precisely the addition of a new constructor to
the predefined type exn: ident of type).
On the other hand, ``raise'' does not introduce a syntactic construct
since exception raising is parsed as a regular application
(application of the identifier raise to an exception value). Hence,
strictly speaking, raise has not to be a keyword. However there are
two good reasons to turn raise into a keyword:
1) To prevent the redefinition of the predefined raise primitive.
2) To parse the exception raising slightly differently than the
regular application: for instance, we could spare some parentheses in
case of a functional exception constructor, and write
raise Invalid_argument "divide"
instead of
raise (Invalid_Argument "divide").
This is as reasonable as the current syntactic status of raise: indeed,
this scheme has been used in Caml for a long time.
> I can speculate that the intention is precisely that praogrammers be
> able to rebind them at will, or maybe that it simplifies implementing
> interpreters/compilers, but I don't know for sure. Could anyone
> (preferably someone involved in the design) comment on the rationale
> for these choices?
>
> Thanks,
>
> Fermin Reig
>
> ------------------------------------------------------
> Department of Computing Science, University of Glasgow
> http://www.dcs.gla.ac.uk/~reig
The ``users can rebind'' argument is definitively what we intended
when we decided to allow the rebinding of usual operators (infix or
prefix symbols, such as +, -, *, ...). For ``raise'' this is not so
clear, since redefining ``raise'' is a very bad idea to obtain a
readable Caml program. Anyway, this treatment of ``raise'' saved one
or 2 lines in the parser of the language, and several characters in
the lexer definition. Long time ago, we were hesitating before addding
that little amount of code to the compiler. Now that the parser has
become considerably bigger, we may give it a second thought! In
particular, if we consider that knowing for sure that ``raise'' indeed
raises exceptions is important for the programmer... (and probably for
automatic tools that can try to analyse exception handling in Caml
programs).
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
next prev parent reply other threads:[~2000-08-20 19:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-08-18 2:07 Fermin Reig
2000-08-19 16:57 ` Frank Atanassow
2000-08-20 19:01 ` Pierre Weis [this message]
2000-08-20 19:55 ` John Prevost
2000-08-21 8:58 ` Pierre Weis
2000-08-21 19:47 ` John Prevost
2000-08-21 21:41 ` Pierre Weis
2000-08-21 16:44 ` John Max Skaller
2000-08-21 21:24 ` Pierre Weis
2000-08-22 0:38 ` Kwangkeun Yi
2000-08-22 2:25 ` John Max Skaller
2000-08-22 9:08 ` Pierre Weis
2000-08-22 8:31 ` Pierre Weis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200008201901.VAA17272@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=reig@dcs.gla.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox