From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA16745 for caml-red; Sun, 20 Aug 2000 21:01:45 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA18921 for ; Sun, 20 Aug 2000 21:01:04 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e7KJ13D02671; Sun, 20 Aug 2000 21:01:03 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA17272; Sun, 20 Aug 2000 21:01:03 +0200 (MET DST) From: Pierre Weis Message-Id: <200008201901.VAA17272@pauillac.inria.fr> Subject: Re: Question on language design (keywords vs Pervasives) In-Reply-To: <200008180207.LAA05417@ropas.kaist.ac.kr> from Fermin Reig at "Aug 18, 100 11:07:05 am" To: reig@dcs.gla.ac.uk Date: Sun, 20 Aug 2000 21:01:03 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr > 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/