-
-
Notifications
You must be signed in to change notification settings - Fork 4
list
(1 2 3) {1 2 3} [1 2 3]
all denote a list with 3 elements.
{a:1 b:2 c:3} [a:1 b:2 c:3] (a:1 b:2 c:3)
all denote a map with 3 elements.
The fundamental data type of lisp is a list,
The fundamental data type of wasp is a node:
A node can express different forms of data, it contains a list of other node_pointer, which might be key -value-pairs, naturally forming maps which can be evaluated as blocks.
lists can have different grouping symbols:
separators ',' ';' '\n' '\t' ' ' '|' and
enclosures '()' '[]' '{}'.
These different enclosures have slightly different semantics:
- () groups are used for tuples
- {} objects are used for blocks
- [] patterns are used for matching and indexing
However, Without special context, all combinations of enclosures and groupings are identical denotations for lists:
a={1 2 3}
b=[x,y,z]
c=("u";"v";"w")
d=1,2,3
e=(1;2;3)
f={
x=1
y=2
z=3
}// functions as lists of statements/expression separated by '\n' are still a kind of list
- square braces can have special semantics as patterns
- curly braces can have special semantics as closures / code
Todo: Different separators have different bindings: While 1,2,3 binds as one expression, 1;2;3 yields the last element as return value.
As such, cvs and tsv files are valid data in wasp.
Lists with different enclosures and groupings can be nested to form
higher order arrays, maps, matrices, tensors etc:
m=(1 2; 3 4)
Utf has a variety of enclosures, angle supports them out of the box.
() ﴾ ﴿ ﹙﹚( ) ⁽ ⁾ ⸨ ⸩
{} ﹛﹜{} ﹝﹞〔〕〘〙
[] 〚〛〖〗【】『』「」「」 ⁅⁆
«» 《》〈〉〈〉
︷ ︵ ﹁ ﹃ ︹ ︻ ︽
︸ ︶ ﹂ ﹄ ︺ ︼ ︾
By default these act just like common groups however custom circumflex operator overloading is planned.
also see ‖…‖ norm, floor and ceiling operators
within curly braces {}
all groupings act as column forming!
otherwise ' ' and ',' act as row forming, whilst ';' and '\n' act as column forming!
x=(1 2) y={3 4}
x*y = 11 // 1*3+2*4
All functions automatically consume lists via auto broadcasting:
square:=it*it
square 1 2 3 == 1 4 9
lists have outer operators, inner operators and element wise operators:
x={1 2}
x x = (1 2; 1 2) // outer concatenation
x + x = (1 2 1 2) // list concatenation
x .+ x = (2 4) // element wise addition
x \+ x = (2 4) // inner addition
x /+ x = (2 3; 3 4) // outer addition
The following is typical data with implicit lists in wasp:
v=1,2,3
m=(1 2 3, 4 5 6)
t=(1 2, 3 4; 5 6, 7 8)
Because space, comma, semicolon and Newline have decreasing binding, they can be used to form arrays, matrices, tensors of three, four or higher dimension.
The fundamental data type of lisp is a list,
The fundamental data type of wasp is a node
which contains a list of other node_pointer, a value and or a 'next' node which might form key-value
-pairs, naturally forming maps which can be evaluated as blocks:
{a b:c d{e f g}}
When space, comma, semicolon or newline are used purely unmixed, their usage is equivalent, all forming the same list:1 2 3 == 1,2,3 == 1;2;3
In context however their semantics vary (as seen above in case of the tensor, or ubiquitously in programming code blocks). Comma and space bind more closely than assignment so that a=1,2,3 can be written without braces.
All functions can be fed with lists because of auto broadcasting: If a method does not have a signature which takes explicit lists, each parameter will get applied individually: square(1,2,3)==1 4 9
Todo: maybe add compiler warning for [] lists:
"patterns [] have special semantics in wasp and should be avoided as lists. Use () for lists instead"
A tuple is a list with fixed length and fixed size. A named tuple is a map with fixed keys, length and size.
Because of these properties addition of tuples is element wise: ( 1 2 3 ) + ( 4 5 6 ) == (5 7 9)
This is an important distinction to object lists where {1 2 3 } + { 4 5 6 } == {1 2 3 4 5 6 }
Unlike in some other languages, tuples in angle can be both mutable and immutable (constant final).
To be safe angle has explicit element wise operations .+ etc
Todo: can the ++ operator be overloaded for tuple concatenation ? Conflicts with element wise increase
Arrays are lists of fixed type and possibly predefined length. Vectors are (numerical) lists of fixed length and fixed type.
x:int[10]
y:char[20]
z:person[]
Note that in angle, char is shorthand for utf-8 character ( codepoint )
Internal note: Angle arrays are allocated in wasm linear memory, thus on 'heap' so to speak.
Todo: python style array or hash initialization: a=[] b={}
Lists of objects are denoted by semantic plural 's':
person{
numbers
addresses
}
means class person has an array of type number and and array of type address as field
equivalent syntax:
numbers x // angle style
number[] x // c style
x : [number] // Swift style
x = number[]
x is list of number
x is list of numbers
danger :
numbers x,y,z
means x,y,z are each of type number (not each a list)!
Typed arrays have Node kind Type::arrays
and any Node type.
Untyped arrays and typed vectors are represented via Node kind:
enum Type {
// each class can be made into a typed list / vector int => int[] :
classe, // as Java class, primitive int vs Node(kind==int) == boxed IntegerType.
vectors, // any[] vs Node[] list of type class! e.g. numbers xs => xs.type=number(type=vectors)
arrays, // Node[] vs any[] untyped array of Nodes. Unlike vector the node is NOT a class!
}
As angle is both a high level and low level programming language, it allows abstract arrays and construction of memory bound arrays:
person{
numbers
addresses
id:int[8]
}
Speakable syntax for list initialization:
id of 8 numbers
id is 8 numbers
id as 8 numbers