Values
In U, there are only two Value kind:
- Primitive values: built in U like numbers, strings, arrays,
- Derived values: created from primitive Values, like classes.
Symbol¶
Symbol starts with :
followed with a name. Special cases arise when using non alphanumeric names. In that case, use quotes to create symbols:
:"a -> b" # With spaces
:1234 # From a number
:'*' # From operator
:(name) # From an expression
:\'A' # From a Char
When using operator as symbol, enclosed them with quotes. Without quotes, :*
would be interpreted as the aperture ':*'.
Variables¶
In U, variables are defined with aperture :
and a name.
See Variables.
No Null Value¶
U has no Null
, Nil
or Undefined
value by default. To denote no value or an empty set of values, use built-in Optional Type. However, to be able to manage legacy codebases, you can set the 'allow-null' config key with ugo.
Booleans¶
like in other languages, U has boolean, but only as a type:
The size of the bool type is implementation-specific.
Numbers¶
For convenience and readability, underscore characters (_) are accepted and ignored within number literals:
# Integer
1234 # Integer
1_234 # Integer
# Floating point: FP
12.34 # Decimal FP
1234e-5 # Decimal FP
# Hexadecimal FP
0x1.FFp4
See Number.
Quotes¶
In U, three quote types denote Values:
'...'
: single quote,"..."
: double quote,`...`
: backtick or left quote.
See Quotes for more details about quotes, string, and string interpolation.
Characters¶
Characters start with escape \
followed by quotes:
See Characters.
Collections: Sequences, Arrays, Lists, Sets, hashes, matrices¶
Collections are structures that group values with special relationships between them: ordered, unique, same type...
(a, b) # Sequence
[1, 2] # Array
[- a, b -] # List
[$ a, b $] # Set
[< a, b >] # Hash
[| a, b |] # Matrix
See Collections
Ranges¶
Range are a special kind of collection with computed content.
Like any collection, ranges can have iterators:
Regexps¶
Regular expressions are powerful parser generator under the hood.
:line : /[^\n]+/
# Escaping '/'
:path : /\/?(\w+\/)+/
# Without escaping '/', use '{}'
:line : ::R{/?(\w+/)+}
Enums, Variants¶
See Enums and Variant.
Classes¶
Classes are defined using U keywords ::A
and ::a
.
::A :Position, :x: @int, ...
::A :Position, {
# Constructors
(:x, :y) : (... @Int)
}, {
# Body if needed
:move : ...
}, ... # Options
See Classes.