Primitive Expressions

prim

( expr ) LiteralExpr quasiliteral NounExpr HideExpr MapComprehensionExpr ListComprehensionExpr ListExpr MapExpr

expr

assign continue break return ( ) ; blockExpr

Parentheses, braces, and square brackets set off primitive expressions.

Parentheses override normal precedence rules:

>>> 4 + 2 * 3
10
>>> (4 + 2) * 3
18

Noun

NounExpr

name

name

IDENTIFIER :: stringLiteral

A noun is a reference to a final or variable slot:

>>> Int
Int

>>> _equalizer
_equalizer

Any string literal prefixed by :: can be used as an identifier:

>>> { def ::"hello, world" := 1; ::"hello, world" }
1

Literal Expression

LiteralExpr

StrExpr IntExpr DoubleExpr CharExpr

Quasi-Literal Expression

quasiliteral

IDENTIFIER ` QUASI_TEXT DOLLAR_IDENT ${ expr } `

See also

quasiliteral,

List Expression

ListExpr

[ expr , ]

comprehension

pattern in iter expr pattern => pattern in iter expr => expr

iter

order if comp

Among Monte’s collection types, the list is a very common type. Lists are heterogenous ordered unsorted collections with sequencing and indexing, and have the performance characteristics of arrays in C, vectors in C++, or lists in Python:

>>> ['I', "love", "Monte", 42, 0.5][3]
42

A list expression evaluates to a ConstList:

> { def l := ['I', "love", "Monte", 42, 0.5]; l[3] := 0 }
...
Message refused: ([I, love, Monte, 42, 0.500000], Atom(put/2), [3, 0])

Use diverge and snapshot to go from ConstList to mutable FlexList and back:

>>> { def l := ['I', "love", "Monte", 42, 0.5].diverge(); l[3] := 0 }
0

See also

comprehension

Expansion:

>>> m`[]`.expand()
m`_makeList.run()`

Map Expression

MapExpr

[ mapItem , ]

mapItem

expr => expr => SlotExpr BindingExpr NounExpr

Monte uses the “fat arrow”, => for map syntax:

>>> { def m := ["roses" => "red", "violets" => "blue"]; m["roses"] }
"red"

Like list expressions, a map expressions evaluates to an immutable data structures, a ConstMap:

> { def m := ["roses" => "red", "violets" => "blue"]; m["roses"] := 3 }
...
Message refused: ([roses => red, violets => blue], Atom(put/2), ["roses", 3])

Use diverge and snapshot similarly:

>>> { def m := ["roses" => "red", "violets" => "blue"].diverge(); m["roses"] := 3 }
3

Warning

Maps in monte are ordered:

>>> [ "a" => 1, "b" => 2] == [ "b" => 2, "a" => 1]
false

To compare without regard to order, use sortKeys:

>>> [ "a" => 1, "b" => 2].sortKeys() == [ "b" => 2, "a" => 1].sortKeys()
true