Illustrated specification
The whole language, explained and checked
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.
- parts and appendices
- 20
- sections
- 105
- programs executed
- 209
- figures
- 101
How to read this specification
Conventions, figures and profiles: what helps to know before you start.
- 0.1What you will findThis specification describes the whole PseudoLearn language and its engine, with examples that really run every time it is built.
- 0.2Typographic conventionsEverything that belongs to the language looks like code; everything you have to fill in yourself looks like a slot.
- 0.3How to read a written formA 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.4How to read the figuresFigures show what the program text does not: memory, the order in which each part runs and what the engine records.
- 0.5Syntax profiles: Spanish and EnglishPseudoLearn has two vocabularies with exactly the same rules: you can program in Spanish or in English and the result is the same.
- 0.6EditionsAn edition is a closed version of the language; this specification describes the 2027 edition.
Overview
What PseudoLearn is and what happens to a program from the moment you write it until it ends.
- 1.1What PseudoLearn isPseudoLearn is a pseudocode language that really runs: what you write is analysed, run and can be watched step by step.
- 1.2The journey of a program: from text to executionBefore 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.3Analysing, running and observingThe engine does three different jobs with a program: analysing it without running it, running it, and letting you observe what happens inside.
- 1.4Determinism: the same program always gives the same resultWith the same program, the same inputs and the same seed, the engine always produces the same output, on any computer.
- 1.5How a program endsEvery 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.6Errors, warnings and failuresThe engine warns with diagnostics: errors prevent running, warnings do not, and failures happen while the program runs.
Lexical structure
The smallest pieces of the text: words, numbers, texts, signs and comments.
- 2.1Source text and encodingA 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.2Spaces and line breaksSpaces, tabs and line breaks only separate pieces: indentation does not change the meaning and a line break does not end a statement.
- 2.3CommentsA comment starts with // and runs to the end of the line; the engine keeps it but does not run it.
- 2.4IdentifiersAn 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.5Reserved wordsReserved words belong to the language itself, such as If or While; you cannot use them as the name of a variable.
- 2.6Numeric literalsA 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.7Text and character literalsA 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.8Operators and signsOperators and signs are the pieces made of symbols, such as +, <= or <-; the engine always reads the longest possible piece.
- 2.9Statement endEvery simple statement ends with a semicolon; the words that open and close blocks, such as If or EndWhile, do not.
- 2.10Lexical errorsA 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.
Types and values
Which kinds of data exist, how much they hold and how they relate.
- 3.1Primitive typesEvery 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.2Relations between types and wideningA 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.3Inference: the type is always declaredIn PseudoLearn no variable guesses its type: each one is declared with Define and an explicit type before it is used.
- 3.4ArraysAn array is a row (or a table) of boxes of the same type, with a fixed size and numbered from zero.
- 3.5VectorsA vector is a list that grows and shrinks while the program runs; all its elements have the same type.
- 3.6DictionariesA dictionary stores key-value pairs: you look up by the key and get the value, like in a phone book.
- 3.7RecordsA record groups several named pieces of data into a single value, like a card with its sections; assigning it copies it whole.
- 3.8EnumerationsAn enumeration is a type with a closed list of named values, like the colours of a traffic light.
- 3.9VariantsA 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.10Optional and ResultOptional 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.11Functions as valuesA subroutine is also a value: it can be stored in a variable, passed as an argument or returned, and called later.
- 3.12GenericsA generic is a subroutine or a type written once for any type: the concrete type is filled in when it is used.
- 3.13immutable and snapshotsnapshot takes a complete picture of a value and returns it as immutable: everything can be read, but nobody can change it.
- 3.14BytesBytes 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.15Checking levelsThe engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.
Expressions and operators
How things are computed: arithmetic, comparisons, logic and the order of operations.
- 4.1Arithmetic operators+, - and * compute with numbers: between two integers they give an exact integer and, if either is real, they give a real.
- 4.2Division, Div and ModThere are three ways of dividing: / always gives a real, Div gives the integer quotient and Mod gives what is left over.
- 4.3Power^ raises one number to another: 2 ^ 10 is 1024; between integers the result is exact, and with a real it is real.
- 4.4ComparisonComparison operators ask something about two values and answer with a Boolean: True or False.
- 4.5Logical operatorsAnd, Or and Not combine boolean answers: And needs both to be true, Or is happy with one and Not turns the answer around.
- 4.6Concatenation+ between texts glues them one after the other: "Hola, " + "Ana" is "Hola, Ana".
- 4.7Precedence and associativityWhen an expression has several operators, precedence decides which applies first: 2 + 3 * 4 is 14, not 20.
Declarations and statements
Creating variables and constants, giving them values and ending each instruction.
- 5.1Declaring variables with DefineDefine creates variables: named, typed boxes where the program keeps a value that can change.
- 5.2Fixed values with ConstantA Constant names a value that never changes, and the engine computes it before running.
- 5.3Assignmentx <- value stores a new value in a variable and forgets the one it had.
- 5.4DesignatorsA 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.5Variables without a valueBefore 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.6Unused variablesA variable that is declared and never used, or written and never read, produces a warning: the program works, but something is left over.
Control flow
Deciding, repeating, leaving early and leaving clean-up for the end.
- 6.1The If decisionIf 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.2Multiple selection with SwitchSwitch looks at a value only once and jumps straight to the branch whose label matches.
- 6.3The While loopWhile repeats a block while a condition is true, and checks it before every round, including the first.
- 6.4The Repeat loopRepeat runs the body first and asks afterwards: it repeats until the condition is true, and always does at least one round.
- 6.5The counted loop ForFor counts from one number to another and runs the body once for each value, with a control variable that moves by itself.
- 6.6Walking collections with For EachFor Each visits the elements of a vector, an array or a dictionary one by one, without indices.
- 6.7Leaving a loopExit ends the loop that contains it on the spot, even if its condition would still allow it to go on.
- 6.8Cleanups with DeferDefer notes down something to do when leaving the current block, whatever happens: closing a file, switching off a light, leaving things as they were.
Subroutines
Naming a piece of a program, passing it data and receiving a result.
- 7.1Declaring subprogramsA subprogram is a named piece of program: it is written once and used as many times as needed.
- 7.2ParametersParameters are the input variables of a subprogram: on every call they receive a copy of the values passed to it.
- 7.3Parameters by referenceA By Reference parameter is another name for the caller's variable: whatever the subprogram does to it, it does to that variable.
- 7.4CallsCalling a subprogram means pausing what you are doing, running the subprogram with its arguments and coming back exactly to where you paused.
- 7.5Returning a value with ReturnReturn ends the subprogram on the spot and, if it has a return type, hands the value to the caller.
- 7.6Scopes and namesEvery name exists only inside its scope: from where it is declared to the end of the block that contains it.
- 7.7RecursionA recursive subprogram calls itself with a smaller problem, until it reaches a case so simple that it is solved without calling itself.
- 7.8Purity: Function versus SubroutineA Function only computes: it does not write, read, or touch files or the network. Whatever has effects is declared with Subroutine.
Programs and modules
How a program is organised into units, files and packages.
- 8.1Structure of a programA program is a text with a single algorithm and, around it, the pieces that algorithm uses: subprograms, classes, records, enumerations and constants.
- 8.2Modules and projectsWhen 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.
Objects
Classes, attributes, methods, inheritance and interfaces.
- 9.1Classes and attributesA class is a mould: it describes what data every object keeps (its attributes) and what it can do (its methods).
- 9.2Methods and ThisA method is a subprogram that lives inside a class and works on a particular object: the one named before the dot.
- 9.3Constructors and NewNew creates an object and runs its constructor, which prepares the attributes before anyone uses it.
- 9.4Inheritance and overridingWith Inherits From, a class receives the attributes and methods of another and can change how some of them behave.
- 9.5InterfacesAn 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.6Copies, references and identityAssigning 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.7What classes do not havePseudoLearn deliberately leaves out some pieces of other object languages, and when it recognises them it explains so with a message of its own.
Errors and diagnostics
How the engine warns that something is wrong, and why.
- 10.1Anatomy of a diagnosticA 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.2Severity and classesSeverity says what to do with a diagnostic: an error prevents running, a warning tells you and lets you continue.
- 10.3Recovery and orderAfter 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.
Concurrency and asynchrony
Several tasks that take turns, talk to each other and wait for the outside world.
- 11.1Suspendible units and AwaitA Suspendible unit can pause half-way while it waits for something; Await marks in the code every point where that pause may happen.
- 11.2Task scopes with Tasks and SpawnTasks opens a space where tasks that progress together are spawned; EndTasks waits for all of them to finish, so none is left loose.
- 11.3Channels and SelectA channel is a fixed-capacity queue through which some tasks send values and others receive them, in order and without sharing memory.
- 11.4Effects and capabilitiesTo 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.
Library
Ready-to-use functions: text, mathematics, files, JSON, network and time.
- 12.1How the library is organisedThe 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.2Text functionsText functions measure, trim, search and transform strings without ever modifying the original: they always return a new one.
- 12.3ConversionsConversions 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.4Mathematics and roundingMathematical 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.5Reproducible randomnessPseudoLearn's randomness comes from a source with a seed: with the same seed, the program always draws the same numbers.
- 12.6Read and WriteWrite 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.7Files and foldersTo 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.8JSONparseJson turns a JSON text into a value you can walk through, and jsonText goes the other way.
- 12.9HTTPWith the network capability, a program builds an HTTP request, sends it and receives a response with its status, headers and body.
- 12.10Time and datesThe clock gives instants in nanoseconds, the timer waits, and DateTime turns an instant into year, month, day and time without depending on the machine.
The engine inside
The parts of the engine that analyse, translate and run every program.
- 13.1The engine's layersThe engine processes a program in layers: each one receives the previous result, checks or transforms it and hands it to the next.
- 13.2Memory and the collectorObjects, arrays and texts created while running live on the heap, and the collector recovers those nobody can reach without the program ever noticing.
- 13.3The task scheduleTasks 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.4Effect order and the tapeEverything 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.5Observing executionExecution can be watched step by step: the engine emits a trace of events, and every event carries what changed in memory.
- 13.6Engine limitsLimits 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.7Native code and the hostA 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.
Appendix B — Reserved words
Every word in Spanish and English, generated from the corpus.
Appendix F — Alphabetical index
Everything in the specification, ordered from A to Z.
For AI assistants and agents
Machines read it too.
Every section has a Markdown version with no styles or scripts. Start with the contents or with the language sheet.