Ticket #58 (new defect)
Definition of "keyword"
| Reported by: | sebastien | Owned by: | otter |
|---|---|---|---|
| Priority: | normal | Milestone: | undecided |
| Component: | --Modelica Specification-- | Version: | 3.0 |
| Severity: | normal | Keywords: | keyword |
| Cc: | Hide ticket: | no |
Description
According to the language specification, here is the definition of "keyword":
"Keywords are reserved words and may not be used as identifiers, with the exception of initial which is a keyword in section headings, but it is also possible to call the function initial()."
And here is the list of Modelica keywords:
algorithm and annotation assert block
break class connect connector constant
constrainedby der discrete else elseif
elsewhen encapsulated end enumeration equation
expandable extends external false final
flow for function if in
initial inner input loop model
not or outer output package
parameter partial protected public record
redeclare replaceable return then true
type when while within
I think that, for instance, "pre" and "reinit" are missing in the above list. What is the motivation behind that? (If it is the economy of keywords, then why not remove "true" and "false" which can be considered as "pervasive constants", denoting the elements of Boolean)
I think that the above definition is not clear enough, and I want to propose here a more consistent definition of "keyword", based on rigorous syntactic considerations such as Scheme's (see for instance http://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-6.html#%_sec_3.1). Without trying to reach Scheme's expressiveness and flexibility, it should be possible to satisfy both users expectations (e.g., having reserved words) and language theory (e.g., well-defined criteria). In Scheme, syntactic keywords and variable share the same namespace, which is quite surprising for users of more conventional languages:
(define define 42) ; we define a new variable named... define
means that now "define" is a variable, so "define" cannot be used anymore to define anything. In other words, there is no reserved keyword. Of course this is not satisfying from the Modelica language point of view: we want keywords to be in a separate namespace for clarity (IMO).
However, Scheme suggests a very elegant definition of "keyword" for Modelica: a keyword is an identifier for a language element that cannot be defined as a regular Modelica entity. By "regular Modelica entity" I mean the name of an element in a "class" syntactic construct ("model", "function", "package", etc.). Of course, the toplevel namespace is considered here to be an unnamed package.
From that definition, it follows that some new identifiers should be considered as keywords because they cannot be defined nor redefined by users (for instance "size", "ndims", "zeros", etc.): in fact they trigger syntactic actions. Be careful however not to confuse names of primitives with keywords: primitives cannot be created /ex nihilo/ but identifiers can be assigned to them:
function mySin = sin; // valid since sin is a guenuine function
function myZeros = zeros; // invalid since zeros is syntax
What are your opinions about that?
