Nomsu's Syntax
Nomsu's syntax has a few basic structures. Most of them have an inline form, and an indented form, which can be used when something is to big to fit on one line. For consistency, Nomsu requires all indentation to be exactly 4 spaces.
Numbers
Nomsu's number literals are very standard: 5
, 2.3
,
0x2A
. Since Nomsu runs on the Lua virtual machine, 'number'
is a single type–integers and floating point numbers both have the same type.
Variables
Nomsu variables have a "$" prefix: $x
. Optionally, if you
want to use a space in your variable's name, you can surround the variable name in
parentheses: $(my list)
. Variable names are not limited
by typical programming language constraints. You can have nameless variables:
$
, number variables: $2
or
$4th
, and unicode variables:
$徳川家康
.
Dictionaries
Nomsu dictionaries (also known as hash maps, or hash tables) are surrounded by
curly braces, and each key has a "." in front of it:
{.x=1, ."my string"=5, .99="foo"}
.
Dictionary keys and values may have any type (.x
is a shorthand
for ."x"
). Values in the dictionary are accessed
with the "." operator: $dict.x
, $dict."my string"
,
$dict.99
. Multi-line dictionaries start with a "{", have an
indented list of comma- or newline-separated entries, and end with a "}":
Trailing commas are allowed.
Lists
Nomsu lists are surrounded by square brackets: [1, 2, 3]
.
Lists are indexed in the same way as dictionaries (i.e. with the "." operator),
but it's important to note that Nomsu lists are 1-indexed (because Nomsu runs
on the Lua virual machine). This means that $things.1
accesses the first element in $things
, $things.2
the second, and so on. #$things
(as in "number of things")
can be used to get the length of a list. For Lua programmers, this should be familiar.
For new programmers, this should be intuitive. For experienced programmers, this can be
annoying at first, but don't worry, the adaptation phase is short! Multi-line lists
start with a "[", have an indented list of comma- or newline-separated items, and end with a "]":
Again, trailing commas are allowed.
Text
Nomsu's text is enclosed in double quotation marks: "hello"
.
Special characters may be escaped with a backslash: "newline: \n, quote: \", control: \x1B"
,
and the backslash may also be used to insert values: "the value of $x is \$x and 2 + 3 = \(2 + 3)"
.
Long text can span multiple lines by starting with a ("
, then including the
text in an indented region, then ending with a ")
:
Actions
A Nomsu action is a heavy-duty high-utility concept. The term "action" encompasses
functions, macros, control flow, and operators. For now, let's just think of them
as functions. An action is a sequence of one or more words or expressions separated
by spaces: say 55
(this calls the action say _
with the single argument 55). The words collectively make up the name of the action,
and Nomsu does not require the name of the action to come before the arguments, so
55 squared
(call _ squared
with 55) is equally
valid, as is take 55 and square it
(call take _ and square it
) or 5 plus 6
(call _ plus _
with 5 and 6). Actions can use a wide range of symbols
and unicode characters, so their names can be symbolic like: √5
or 1 +/- 2
. Nomsu does not have any reserved keywords,
so any words are allowed in an action. However, defining an action with the exact
same full name as a language structure like if _ _ else _
might cause problems.
Actions may be defined using the _ means _
action:
Optionally, you can also define an anonymous function literal as [$x, $y] -> ($x + $y)
.
Actions can be grouped with parentheses: say (5 squared)
,
and for long lines, an indented region can be used:
Actions with only arguments and no words (like $my_fn 1 2 3
)
are treated as a function call, where the first value is the function and the rest are
arguments (for no arguments, $my_fn()
). Nomsu also supports
a method call syntax, using a comma: $x, do thing with $y
.
This is equivalent to $x."do thing with" $x $y
, i.e. calling
$x
's "do thing with" function and passing $x
as the first argument, along with all
the extra arguments. This chains nicely, so you can have $x, as text, with "\n" -> " "
.
Blocks
Blocks are a way to group multiple actions together, or to put actions into their
own indented areas. A block is a colon followed by an indented region. The block
ends when the indentation ends. In the above example, _ means _
is
an action with two arguments, an action:
(say how cool $person is)
and a block that contains
say "\$person is awesome!!"
Nomsu's basic control flow structures are just actions that use blocks:
Here, the action if _ _
is given two arguments: ($x == 10)
and a block with some more actions. If you need to add more action words or
arguments after a block, just start the next line with ..
. This is
how if-else works in Nomsu: