An important aspect of new programming languages and their design is Naming and Identities.
Essentially:
Software Engineers, usually English speaking, typically use easy to remember and descriptive names for classes, functions and similar. There is a lot of variance in style and length, so our new language has to cope with this.
The Harth Programming Language will have a Name type to represent
the simplest name. This is typically used to represent local
variables, function parameters. For example the x local variable defined below:
var x : Int = 1
The Name type therefore:
x).String; the name of the definition (here "x").class Name
{
property Text : String
}
The Path type will represent more complex names. This is typically
used to represent classes, functions and other definitions which have
non-local scope. For example:
package /MyPackage
class MyType
{
}
Here the class MyType;
Path representing"/MyPackage/MyType",class Path
{
property Parent : Path?
property Name : Name
}
The Path type:
Parent path (in our example /MyPackage is the parent path).Name instance; the simple local name.We could also derive a URL type to represent paths for naming files,
URLs and other similar resources later on.
Identities are used more by the language itself to represent:
A Name or Path is more useful as a label to define or refer to
something using human textual names. Much like our own name, we could
add more (aliases) or change them (deprecate, rename). This is more
useful to the human.
An Identity is more useful as a unique identity which is
immutable; whatever that something is always has the same unchanging
identity. This is more useful to the computer.
For Identity we could use a GUID or UUID.
I think initally it would be best that Identity composes and hides
this decision as much as possible:
class Identity
{
property Value : Int128
@private
property ID : GUID
}
The Identity has a Value (initially an 128-bit integer), and
internally we would use a standard GUID or UUID type.
We will also need Definition and Reference types to represent
definitions and references to class et. al.
All definitions such as classes, functions, local variables and
parameters would be sub-types of Definition:
class Definition
{
property ID : Identity
property Path : Path
property Aliases : Sequence<Path>
property References : Sequence<Reference>
}
A definition would have:
ID; the unique identity of this definition.Path; the current primary path (full name) of this definition.Aliases; any other known (or deprecated) names.References; any known references to this definition.All references to classes, functions, local variables and
parameters would be sub-types of Reference:
class Reference
{
property Path : Path
property Definition : Definition?
}
A Reference has:
Path; the current primary path (or name) of this reference.Definition; the currently “bound” definition with the given Path.During the Semantic Analysis phase of compilation, we will also need
“Binding” and Scope processes and types to manage linking
Definition and Reference instances (class definitions and class
references by name for example).
The process of “Binding” is where all Reference instances are bound
by name to their respective Definition. Typically binding is done
during the Semantic Analysis of the compiler.
The Scope of a “Binding” would need to be modeled. The semantic
analysis phase would need to build the definition scopes (packages,
classes, functions) during analysis.
class Scope
{
property Parent : Scope?
property Owner : Definition
property Definitions : Sequence<Definition>
property References : Sequence<Reference>
}
A Scope has:
Parent; the parent scope which contains this scope.Owner; the owner definition of this scope.Definitions; any known definitions in this scope.References; any known references to this definitions in this scope.Not much new here, if you are very familiar with semantic analysis, names and types.
Some differences;
Path or Name to allow for renaming.Identity (guids).Some thoughts:
Identity allows for definitions to be stored in databases.Reference and Definition instances,