Concepts
We can visualize running a U program as a sequence of expressions – a calculation or simplification step – that lead to:
- a final value
- a weel defined repetition: loop or recursion
For better understanding, U source code model groups all elements managed by U compiler in dimensions or dims. Dims allows you to clearly visualize how you can leverage U powerful features.
Source Code Model¶
U's simple but powerful source code model is depicted below:
Where dimensions are:
- User: your code is at the center of the model. It represents your intent,
-
Host: the left side of your code represents the outside world and side effects. Most actions towards the Host are symbolized with arrow pointing:
-
Left: when sending values like
\<
for printing; - Right: when receiving values like
\>
for user input. - Ulet: Ulet manages every compile-time needs, like converting your code to values or generating const data structures,
- U: U is the orchestrator through all compilation steps to generate an efficient executable.
Apertures let easily navigate between dimensions for better expressiveness, reliability, extensibility, and performance.
Build system¶
U has a powerful build system: ugo. Ugo lets you customize U features, manage your codebase, and control the compilation process.
This documentation uses 'the ugo' when referring to 'changing the ugo configuration file ugo.u'.
see ugo.
User dim¶
At user dim, syntax elements are divided in two groups: values like 1
or "title"
, and expressions like +
in 1 + 3
.
Value¶
What are values for? Values help you make decisions:
- a calculation
- a login
- a change in UI
- a loop in a device driver
In user dim, every piece of information is represented as a value. But a value is not an "object" (storage + methods). This difference lets you use OOP when needed. For example, for data streaming and array programming, OOP is not well suited.
In U, a value is an expression for which there is no computation remaining to be performed.
All values share a number of properties:
- Values have syntel for better readability. Syntel are representation of value at the syntax level: numbers
123
, functions{}
, collections[]
... - Values do not expose their location in memory. However, low-level data are accessible through compiler directives
- Values can be shared with control: visibility, ownership, enqueued
- Values can change place: copy, clone, locally or remotely
Expressions¶
Expressions let you define steps to reach a final value. Your intent is then managed in U dim following an efficient internal execution model.
At user dim, there are only two possibles expression types binding and applying:
-
Binding: bind a value to another one with control: variable, constant, function...
-
Applying: evaluate an expression to eventually a new value with/without parameters.
Those rules have been proven to be correct in functional programming for example. Expressions associated with immutability, flexible syntax, and efficient code generation, allow U to be a swiss-knife for most domains.
Operations¶
Operations are expressions using operators as identifiers. For example, a + 1
is an operation. It's equivalent to + a, 1
with +
being the expression identifier.