Skip to content

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.

:a : 88

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:

:t : @true
:f : @false

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.
:name : 'Alice'

\< "Welcome \:name" 
# Prints "Welcome Alice" 

See Quotes for more details about quotes, string, and string interpolation.

Characters

Characters start with escape \ followed by quotes:

:a : \'A'
:b : \"'"
:c : \'❤️'
:d : \'\x81'
:e : \'u{41}'

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.

0:.:2   # 0,1,2
0:.<:2  # 0,1
0:<.:2  # 1,2
0:<.<:2 # 1

0:+2:6 #[0,2,4,6]
6:-2:0 #[6,4,2,0]

Like any collection, ranges can have iterators:

'a':<.<:'z' {: v
    \< v
}

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.

Functions and Closures

See Functions and Closures.