# Language specification · PseudoLearn

> How every part of PseudoLearn is written and exactly what it does. Every example runs on the real engine each time this specification is published.

Web page: https://pseudolearn.app/en/spec

## 0. How to read this specification

Conventions, figures and profiles: what helps to know before you start.

- [0.1 What you will find](https://pseudolearn.app/en/spec/lectura/contenido.md): This specification describes the whole PseudoLearn language and its engine, with examples that really run every time it is built.
- [0.2 Typographic conventions](https://pseudolearn.app/en/spec/lectura/convenciones.md): Everything that belongs to the language looks like code; everything you have to fill in yourself looks like a slot.
- [0.3 How to read a written form](https://pseudolearn.app/en/spec/lectura/formas.md): A written form is the mould of a construct: it says which words are fixed, which slots you fill in and which parts you may leave out.
- [0.4 How to read the figures](https://pseudolearn.app/en/spec/lectura/figuras.md): Figures show what the program text does not: memory, the order in which each part runs and what the engine records.
- [0.5 Syntax profiles: Spanish and English](https://pseudolearn.app/en/spec/lectura/perfiles.md): PseudoLearn has two vocabularies with exactly the same rules: you can program in Spanish or in English and the result is the same.
- [0.6 Editions](https://pseudolearn.app/en/spec/lectura/ediciones.md): An edition is a closed version of the language; this specification describes the 2027 edition.

## I. Overview

What PseudoLearn is and what happens to a program from the moment you write it until it ends.

- [1.1 What PseudoLearn is](https://pseudolearn.app/en/spec/vision/que-es.md): PseudoLearn is a pseudocode language that really runs: what you write is analysed, run and can be watched step by step.
- [1.2 The journey of a program: from text to execution](https://pseudolearn.app/en/spec/vision/viaje.md): Before running a program, the engine breaks it into pieces, checks that it makes sense and translates it into simple instructions for its virtual machine.
- [1.3 Analysing, running and observing](https://pseudolearn.app/en/spec/vision/analizar-ejecutar.md): The engine does three different jobs with a program: analysing it without running it, running it, and letting you observe what happens inside.
- [1.4 Determinism: the same program always gives the same result](https://pseudolearn.app/en/spec/vision/determinismo.md): With the same program, the same inputs and the same seed, the engine always produces the same output, on any computer.
- [1.5 How a program ends](https://pseudolearn.app/en/spec/vision/terminacion.md): Every run ends in one of six states: it finished well, it failed, it is waiting for input, it is waiting for the outside world, it was cancelled or it ran out of a limit.
- [1.6 Errors, warnings and failures](https://pseudolearn.app/en/spec/vision/errores.md): The engine warns with diagnostics: errors prevent running, warnings do not, and failures happen while the program runs.

## II. Lexical structure

The smallest pieces of the text: words, numbers, texts, signs and comments.

- [2.1 Source text and encoding](https://pseudolearn.app/en/spec/lexico/texto-fuente.md): A program is UTF-8 text; the engine reads it character by character and remembers the line and column of each one to point at errors precisely.
- [2.2 Spaces and line breaks](https://pseudolearn.app/en/spec/lexico/espacios.md): Spaces, tabs and line breaks only separate pieces: indentation does not change the meaning and a line break does not end a statement.
- [2.3 Comments](https://pseudolearn.app/en/spec/lexico/comentarios.md): A comment starts with // and runs to the end of the line; the engine keeps it but does not run it.
- [2.4 Identifiers](https://pseudolearn.app/en/spec/lexico/identificadores.md): An identifier is the name you choose for a variable, a subroutine or a type: it starts with a letter or an underscore and distinguishes upper case, lower case and accents.
- [2.5 Reserved words](https://pseudolearn.app/en/spec/lexico/palabras-reservadas.md): Reserved words belong to the language itself, such as If or While; you cannot use them as the name of a variable.
- [2.6 Numeric literals](https://pseudolearn.app/en/spec/lexico/numeros.md): A number written in the program is an integer if it has only digits and a real if it has a point with digits on both sides.
- [2.7 Text and character literals](https://pseudolearn.app/en/spec/lexico/textos.md): A text goes between double or single quotes; if it contains exactly one character it is a Character, and in any other case it is a String.
- [2.8 Operators and signs](https://pseudolearn.app/en/spec/lexico/operadores.md): Operators and signs are the pieces made of symbols, such as +, <= or <-; the engine always reads the longest possible piece.
- [2.9 Statement end](https://pseudolearn.app/en/spec/lexico/fin-de-sentencia.md): Every simple statement ends with a semicolon; the words that open and close blocks, such as If or EndWhile, do not.
- [2.10 Lexical errors](https://pseudolearn.app/en/spec/lexico/errores.md): A lexical error appears when a piece of the text does not form any valid token: a character the language does not know, an invented escape or unclosed quotes.

## III. Types and values

Which kinds of data exist, how much they hold and how they relate.

- [3.1 Primitive types](https://pseudolearn.app/en/spec/tipos/primitivos.md): Every piece of data has a type that says which values it can hold and what can be done with it; PseudoLearn has five primitive types and every other type is built from them.
- [3.2 Relations between types and widening](https://pseudolearn.app/en/spec/tipos/relaciones.md): A value only moves by itself from one type to another when the target type contains it whole: from Integer to Real, from Character to String and from a subclass to its superclass.
- [3.3 Inference: the type is always declared](https://pseudolearn.app/en/spec/tipos/inferencia.md): In PseudoLearn no variable guesses its type: each one is declared with Define and an explicit type before it is used.
- [3.4 Arrays](https://pseudolearn.app/en/spec/tipos/arreglos.md): An array is a row (or a table) of boxes of the same type, with a fixed size and numbered from zero.
- [3.5 Vectors](https://pseudolearn.app/en/spec/tipos/vectores.md): A vector is a list that grows and shrinks while the program runs; all its elements have the same type.
- [3.6 Dictionaries](https://pseudolearn.app/en/spec/tipos/diccionarios.md): A dictionary stores key-value pairs: you look up by the key and get the value, like in a phone book.
- [3.7 Records](https://pseudolearn.app/en/spec/tipos/registros.md): A record groups several named pieces of data into a single value, like a card with its sections; assigning it copies it whole.
- [3.8 Enumerations](https://pseudolearn.app/en/spec/tipos/enumerados.md): An enumeration is a type with a closed list of named values, like the colours of a traffic light.
- [3.9 Variants](https://pseudolearn.app/en/spec/tipos/variantes.md): A variant is a type whose values can take several different shapes, each with its own data, like a figure that can be a circle or a rectangle.
- [3.10 Optional and Result](https://pseudolearn.app/en/spec/tipos/opcional-resultado.md): Optional represents a value that may be missing and Result an operation that may go well or badly; both force you to look at the bad case before using the value.
- [3.11 Functions as values](https://pseudolearn.app/en/spec/tipos/funciones.md): A subroutine is also a value: it can be stored in a variable, passed as an argument or returned, and called later.
- [3.12 Generics](https://pseudolearn.app/en/spec/tipos/genericos.md): A generic is a subroutine or a type written once for any type: the concrete type is filled in when it is used.
- [3.13 immutable and snapshot](https://pseudolearn.app/en/spec/tipos/inmutable.md): snapshot takes a complete picture of a value and returns it as immutable: everything can be read, but nobody can change it.
- [3.14 Bytes](https://pseudolearn.app/en/spec/tipos/bytes.md): Bytes is a sequence of octets, numbers from 0 to 255; it is used to work with binary data, such as the exact content of a file.
- [3.15 Checking levels](https://pseudolearn.app/en/spec/tipos/niveles.md): The engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.

## IV. Expressions and operators

How things are computed: arithmetic, comparisons, logic and the order of operations.

- [4.1 Arithmetic operators](https://pseudolearn.app/en/spec/expresiones/aritmeticos.md): +, - and * compute with numbers: between two integers they give an exact integer and, if either is real, they give a real.
- [4.2 Division, Div and Mod](https://pseudolearn.app/en/spec/expresiones/division.md): There are three ways of dividing: / always gives a real, Div gives the integer quotient and Mod gives what is left over.
- [4.3 Power](https://pseudolearn.app/en/spec/expresiones/potencia.md): ^ raises one number to another: 2 ^ 10 is 1024; between integers the result is exact, and with a real it is real.
- [4.4 Comparison](https://pseudolearn.app/en/spec/expresiones/comparacion.md): Comparison operators ask something about two values and answer with a Boolean: True or False.
- [4.5 Logical operators](https://pseudolearn.app/en/spec/expresiones/logicos.md): And, Or and Not combine boolean answers: And needs both to be true, Or is happy with one and Not turns the answer around.
- [4.6 Concatenation](https://pseudolearn.app/en/spec/expresiones/concatenacion.md): + between texts glues them one after the other: "Hola, " + "Ana" is "Hola, Ana".
- [4.7 Precedence and associativity](https://pseudolearn.app/en/spec/expresiones/precedencia.md): When an expression has several operators, precedence decides which applies first: 2 + 3 * 4 is 14, not 20.

## V. Declarations and statements

Creating variables and constants, giving them values and ending each instruction.

- [5.1 Declaring variables with Define](https://pseudolearn.app/en/spec/declaraciones/definir.md): Define creates variables: named, typed boxes where the program keeps a value that can change.
- [5.2 Fixed values with Constant](https://pseudolearn.app/en/spec/declaraciones/constante.md): A Constant names a value that never changes, and the engine computes it before running.
- [5.3 Assignment](https://pseudolearn.app/en/spec/declaraciones/asignacion.md): x <- value stores a new value in a variable and forgets the one it had.
- [5.4 Designators](https://pseudolearn.app/en/spec/declaraciones/designadores.md): A designator is something that names a place where a value can be stored: a variable, an array cell or an attribute of an object.
- [5.5 Variables without a value](https://pseudolearn.app/en/spec/declaraciones/sin-valor.md): Before running, the engine walks every possible path of the program and rejects reading a variable that some path has not given a value to.
- [5.6 Unused variables](https://pseudolearn.app/en/spec/declaraciones/sin-usar.md): A variable that is declared and never used, or written and never read, produces a warning: the program works, but something is left over.

## VI. Control flow

Deciding, repeating, leaving early and leaving clean-up for the end.

- [6.1 The If decision](https://pseudolearn.app/en/spec/control/si.md): If asks a question whose answer can only be True or False, and runs one path or the other depending on the answer. Never both.
- [6.2 Multiple selection with Switch](https://pseudolearn.app/en/spec/control/segun.md): Switch looks at a value only once and jumps straight to the branch whose label matches.
- [6.3 The While loop](https://pseudolearn.app/en/spec/control/mientras.md): While repeats a block while a condition is true, and checks it before every round, including the first.
- [6.4 The Repeat loop](https://pseudolearn.app/en/spec/control/repetir.md): Repeat runs the body first and asks afterwards: it repeats until the condition is true, and always does at least one round.
- [6.5 The counted loop For](https://pseudolearn.app/en/spec/control/para.md): For counts from one number to another and runs the body once for each value, with a control variable that moves by itself.
- [6.6 Walking collections with For Each](https://pseudolearn.app/en/spec/control/para-cada.md): For Each visits the elements of a vector, an array or a dictionary one by one, without indices.
- [6.7 Leaving a loop](https://pseudolearn.app/en/spec/control/salir.md): Exit ends the loop that contains it on the spot, even if its condition would still allow it to go on.
- [6.8 Cleanups with Defer](https://pseudolearn.app/en/spec/control/diferir.md): Defer notes down something to do when leaving the current block, whatever happens: closing a file, switching off a light, leaving things as they were.

## VII. Subroutines

Naming a piece of a program, passing it data and receiving a result.

- [7.1 Declaring subprograms](https://pseudolearn.app/en/spec/subprogramas/declaracion.md): A subprogram is a named piece of program: it is written once and used as many times as needed.
- [7.2 Parameters](https://pseudolearn.app/en/spec/subprogramas/parametros.md): Parameters are the input variables of a subprogram: on every call they receive a copy of the values passed to it.
- [7.3 Parameters by reference](https://pseudolearn.app/en/spec/subprogramas/referencia.md): A By Reference parameter is another name for the caller's variable: whatever the subprogram does to it, it does to that variable.
- [7.4 Calls](https://pseudolearn.app/en/spec/subprogramas/llamada.md): Calling a subprogram means pausing what you are doing, running the subprogram with its arguments and coming back exactly to where you paused.
- [7.5 Returning a value with Return](https://pseudolearn.app/en/spec/subprogramas/retornar.md): Return ends the subprogram on the spot and, if it has a return type, hands the value to the caller.
- [7.6 Scopes and names](https://pseudolearn.app/en/spec/subprogramas/ambito.md): Every name exists only inside its scope: from where it is declared to the end of the block that contains it.
- [7.7 Recursion](https://pseudolearn.app/en/spec/subprogramas/recursion.md): A recursive subprogram calls itself with a smaller problem, until it reaches a case so simple that it is solved without calling itself.
- [7.8 Purity: Function versus Subroutine](https://pseudolearn.app/en/spec/subprogramas/pureza.md): A Function only computes: it does not write, read, or touch files or the network. Whatever has effects is declared with Subroutine.

## VIII. Programs and modules

How a program is organised into units, files and packages.

- [8.1 Structure of a program](https://pseudolearn.app/en/spec/programas/estructura.md): A program is a text with a single algorithm and, around it, the pieces that algorithm uses: subprograms, classes, records, enumerations and constants.
- [8.2 Modules and projects](https://pseudolearn.app/en/spec/programas/modulos.md): When a program grows, it is split into files: every file is a module, and a module uses what another one makes public by importing it.

## IX. Objects

Classes, attributes, methods, inheritance and interfaces.

- [9.1 Classes and attributes](https://pseudolearn.app/en/spec/objetos/clase.md): A class is a mould: it describes what data every object keeps (its attributes) and what it can do (its methods).
- [9.2 Methods and This](https://pseudolearn.app/en/spec/objetos/metodos.md): A method is a subprogram that lives inside a class and works on a particular object: the one named before the dot.
- [9.3 Constructors and New](https://pseudolearn.app/en/spec/objetos/constructor.md): New creates an object and runs its constructor, which prepares the attributes before anyone uses it.
- [9.4 Inheritance and overriding](https://pseudolearn.app/en/spec/objetos/herencia.md): With Inherits From, a class receives the attributes and methods of another and can change how some of them behave.
- [9.5 Interfaces](https://pseudolearn.app/en/spec/objetos/interfaces.md): An interface is a list of methods a class promises to have; it lets you write code that works with any class that keeps the promise.
- [9.6 Copies, references and identity](https://pseudolearn.app/en/spec/objetos/copia.md): Assigning an object does not duplicate it: it gives another name to the same object. To get a new object with the same data you need Copiar.
- [9.7 What classes do not have](https://pseudolearn.app/en/spec/objetos/ausentes.md): PseudoLearn deliberately leaves out some pieces of other object languages, and when it recognises them it explains so with a message of its own.

## X. Errors and diagnostics

How the engine warns that something is wrong, and why.

- [10.1 Anatomy of a diagnostic](https://pseudolearn.app/en/spec/diagnosticos/anatomia.md): A diagnostic is not a sentence: it is a piece of data with a stable code, a class, a severity and a position. The message you read is built afterwards, in your language.
- [10.2 Severity and classes](https://pseudolearn.app/en/spec/diagnosticos/severidad.md): Severity says what to do with a diagnostic: an error prevents running, a warning tells you and lets you continue.
- [10.3 Recovery and order](https://pseudolearn.app/en/spec/diagnosticos/recuperacion.md): After a syntax error, the engine looks for a safe point to keep reading: that way it reports every independent error at once, each one only once.

## XI. Concurrency and asynchrony

Several tasks that take turns, talk to each other and wait for the outside world.

- [11.1 Suspendible units and Await](https://pseudolearn.app/en/spec/tareas/suspendible.md): A Suspendible unit can pause half-way while it waits for something; Await marks in the code every point where that pause may happen.
- [11.2 Task scopes with Tasks and Spawn](https://pseudolearn.app/en/spec/tareas/ambitos.md): Tasks opens a space where tasks that progress together are spawned; EndTasks waits for all of them to finish, so none is left loose.
- [11.3 Channels and Select](https://pseudolearn.app/en/spec/tareas/canales.md): A channel is a fixed-capacity queue through which some tasks send values and others receive them, in order and without sharing memory.
- [11.4 Effects and capabilities](https://pseudolearn.app/en/spec/tareas/efectos.md): To touch the outside world —the console, files, the clock, the network— a program asks for a capability: a key that gives access to one single thing.

## XII. Library

Ready-to-use functions: text, mathematics, files, JSON, network and time.

- [12.1 How the library is organised](https://pseudolearn.app/en/spec/biblioteca/modelo.md): The library is the set of functions the language brings: each has a fixed identity, a name in each profile and a signature that does not change with the language.
- [12.2 Text functions](https://pseudolearn.app/en/spec/biblioteca/texto.md): Text functions measure, trim, search and transform strings without ever modifying the original: they always return a new one.
- [12.3 Conversions](https://pseudolearn.app/en/spec/biblioteca/conversion.md): Conversions change a value's type explicitly: from number to text, from text to number, or from real to text with a fixed number of decimals.
- [12.4 Mathematics and rounding](https://pseudolearn.app/en/spec/biblioteca/matematicas.md): Mathematical functions compute roots, logarithms and trigonometry with results exact to the last bit, and rounding functions go from real to integer in four different ways.
- [12.5 Reproducible randomness](https://pseudolearn.app/en/spec/biblioteca/azar.md): PseudoLearn's randomness comes from a source with a seed: with the same seed, the program always draws the same numbers.
- [12.6 Read and Write](https://pseudolearn.app/en/spec/biblioteca/consola.md): Write shows values on the output and Read asks the person using the program for values: they are the simplest way to talk to the outside.
- [12.7 Files and folders](https://pseudolearn.app/en/spec/biblioteca/archivos.md): To read or write files you ask for a folder capability, open the file with it, and every operation returns a Result that may carry an IoError.
- [12.8 JSON](https://pseudolearn.app/en/spec/biblioteca/json.md): parseJson turns a JSON text into a value you can walk through, and jsonText goes the other way.
- [12.9 HTTP](https://pseudolearn.app/en/spec/biblioteca/http.md): With the network capability, a program builds an HTTP request, sends it and receives a response with its status, headers and body.
- [12.10 Time and dates](https://pseudolearn.app/en/spec/biblioteca/tiempo.md): The clock gives instants in nanoseconds, the timer waits, and DateTime turns an instant into year, month, day and time without depending on the machine.

## XIII. The engine inside

The parts of the engine that analyse, translate and run every program.

- [13.1 The engine's layers](https://pseudolearn.app/en/spec/motor/capas.md): The engine processes a program in layers: each one receives the previous result, checks or transforms it and hands it to the next.
- [13.2 Memory and the collector](https://pseudolearn.app/en/spec/motor/memoria.md): Objects, arrays and texts created while running live on the heap, and the collector recovers those nobody can reach without the program ever noticing.
- [13.3 The task schedule](https://pseudolearn.app/en/spec/motor/agenda.md): Tasks do not really run at the same time: a deterministic schedule decides which one advances, and that is why every run always follows the same order.
- [13.4 Effect order and the tape](https://pseudolearn.app/en/spec/motor/efectos.md): Everything a program does towards the outside happens in program order and is noted on a tape, with which the run can be replayed without touching the world again.
- [13.5 Observing execution](https://pseudolearn.app/en/spec/motor/observacion.md): Execution can be watched step by step: the engine emits a trace of events, and every event carries what changed in memory.
- [13.6 Engine limits](https://pseudolearn.app/en/spec/motor/limites.md): Limits are resources set by whoever runs the program —depth, statements, memory, time— and are not part of the language: a program that does not reach them gives the same result under any configuration.
- [13.7 Native code and the host](https://pseudolearn.app/en/spec/motor/nativo.md): A program can also be compiled to a native executable that behaves exactly as in the virtual machine: the same output, the same failures, the same messages.

## A. Appendix A — Grammar

The complete grammar, generated from the corpus.

- [A.1 Grammar](https://pseudolearn.app/en/spec/apendice/gramatica.md): 

## B. Appendix B — Reserved words

Every word in Spanish and English, generated from the corpus.

- [B.1 Reserved words](https://pseudolearn.app/en/spec/apendice/palabras.md): 

## C. Appendix C — Diagnostics

The complete catalogue of engine messages.

- [C.1 Diagnostic catalogue](https://pseudolearn.app/en/spec/apendice/diagnosticos.md): 

## D. Appendix D — Built-in functions

Every function and operation of the library.

- [D.1 Built-in functions](https://pseudolearn.app/en/spec/apendice/funciones.md): 

## E. Appendix E — Glossary

The technical words of this specification, explained.

- [E.1 Glossary](https://pseudolearn.app/en/spec/apendice/glosario.md): 

## F. Appendix F — Alphabetical index

Everything in the specification, ordered from A to Z.

- [F.1 Alphabetical index](https://pseudolearn.app/en/spec/apendice/indice.md): 
