adda (ADD's Automatica) programming lang

the adda-tagged posts
adda's project page
. adda is the programming language of addx,
a secure and friendly system
that promotes computing as a
universal 2nd language
. having everyone -- including children
and seniors -- as its intended client
requires that addx provide a language
that is not straying far from current conventions
while at the same time improving on natural language
 with an elegant system that has
fewer rules for the beginner to learn .
. a language should also be iconic like math,
never using a keyword when a symbol would be
more easily understood;
 though neither should it be using
a morass of arcane symbols
just for the sake of abbreviation .
. there should be a binary version of the language,
-- a common intermediate language --
and tools that allow humans to
work in the language of their choice .
-- because freedom, foremost,
is the Americium Dream .

hist
12.10.5: page is up with abstract .
. I still haven't got the syntax completed yet;
this is what I have so far .

2012.10: adda/summary of the syntax
. this lang tries to use the more popular features
of the syntax found in math, internet url's, and english .

url's look like this:
protocol://subdomain.domain.domType/folder/subfolder/file.fileType#component .
. folders are actually pointers to records
whose fields are files or folders,
hence (/) becomes the pointer dereferencing operator .
. likewise,
the (.) specifies either a type identifier or a record component;
and the (#) specifies an array component
(an array is defined as a sequence of items,
and all these item share the same type;
so f.txt is a container for type txt,
or for a sequence of .txt .

. the internet uses (:) somewhat like english does,
to make an association, or pairing;
adda uses (:) for labels and mappings
( labeling means a symbol is declared,
and after the (:), it is defined;
a mapping means showing the names of items
rather than relying on list position for item identification);
examples include:
# constant declaration:
symbol: (some value the symbol will constantly have );
# variable declaration:
symbol: .aType`= (initial value);
# a case statement:
truthFunction ? (true: doWhenTrue; false: doWhenFalse);
# parameter association:
functionCall( color: red, mood: blue ) .

type"type:
. we need a special type identifier
for declaring that a symbol is a type identifier,
and that identifier is .type; for example:
integer.type: .< (list functions for accessing integers) >;
TrafficLight.type: .{ black, red, yellow, green};
RealPoint.type: .( x, y: .real ) -- this is a record .
. finally,
to help us distinguish the 2 uses of (.):
{ record component selection, type specification},
we need to ensure that record components are
never allowed to have the same name as type identifiers .
. one way to avoid that is by capitalizing type id's,
and never capitalizing component names,
but adda should not enforce this way,
because a less restrictive way to make this distinction
is to depend on prior declarations:
. when you find x.y, then either y should be a type id,
or x should have already been declared to be a record .

inline typing:
. to avoid having to declare symbols before use,
we have a syntax convention for
combining declaration with first use:
. only the first use of a symbol
need include its type specification;
other uses of it can still include its type,
but it's unnecessary, and if you spell the name wrong
that has the effect of declaring another symbol;
examples:
x.integer --. this declares x to be type integer;
x: .integer --. this does the same thing .
. here's a for-loop declaring a control variable:
for x.integer in 0..n: print x;
--. we could have said (print x.integer)
and it would have meant the same thing .


power of a unary operator:
f^(3)(x) = f f f x
power of a binary operator:
(x ^ 3 ) implicitely means x*^3 = *(x, x, x)
power of a list for a binary operator:
* (^(x:1..3).int: x ) = 1 * 2 * 3 = *(1,2,3)
--( same as an operator applied to a
list generated with a power of a parenthetical ).
. generally, (^(x.inType).outType: f(x) )
is saying: for x in inType: include f(x);
eg, (^(x.symbol).list: for terminal in f(s):
    s in grammar? be terminal else be '(s) )
-- (be x) means (return x)
but it's exiting the nearest enclosing expression
not the innermost function literal .

. a function is implicitly describing a set of points,
and sets can be generated:
( f(x:1..3).t: x+1 ) is equivalent to
f = { (1, 2), (2,3), (3,4) } is equivalent to
f = {^(x.{1..3}).(int,int): (x, x+1) } .

a parenthetical declared to return a certain type:
(.int: ...) -- has type int .
. this ( f(x.int).t: x+1 ) can also be expressed as:
f: ((x.int).t: x+1) -- has a function type .

function/pre- and post-conditions:
(x.t).t | (conditions) .

constants:
. to define something as a constant,
we can use (symbol: value) or (symbol.type: value)
instead of (symbol.type`= value).

TypeId#value vs ValueType$valueLiteral:
. types can be thought of as arrays of values,
so t#x evals x as one of t's values .
. B$10 = the value 10 as parsed by the binary value type .
Color#green works only if green is not redefined;
because in the expression (aType#x),
x can be any expression, not just a literal;
Color$green is always unambiguous;
because the ($) says what follows is
one of a type Color's literals .
.  RGB$(0,0,1) -- RGB color model for color literals .

12.3.23: 8.21: adda/oop/syntax/sections for use, is, has[as]:

<
use ,,,imports;
is ,,,supertypes; -- establishing type compatibility .
as ,,, subtypes;
type.( my class vars: t )
.( my public ivars: t )
#( more public ivars -- names from t1 ).t3
#( even more pub ivars --names from t2 ).t4
>;

the use.section:
. why would an interface need to import a module?
they may refer to types other than self
that are not in the top-level library .
the as.section:
. a supertype has or controls its subtypes;
eg, number has all of these types:
int, real, quotient, complex, modular .

review the syntax:

obj`= value -- ivar initialization;
type::value -- fully-qualified instance value

obj.component -- public ivar;
obj`body/local -- private ivars;
obj#(component expression),
type::.component -- access default initial value

type.component -- public class var;
type#(component expression), -- same;
type`body/local -- private class vars;

obj`message(...);  instance message call;
type::`message -- access message's body
type`attribute -- class message call;

obj(obj callable? apply it to this expression),
function obj -- call with this obj
type::function(...) -- access function's body

obj.type(select a variant of this type)
    -- declare obj to be of this type .

No comments:

Post a Comment