Skip to content

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.

Start readingSpecification contents
parts and appendices
20
sections
105
programs executed
209
figures
101
  1. Lexical structure

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

    1. 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. 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.
    3. 2.3CommentsA comment starts with // and runs to the end of the line; the engine keeps it but does not run it.
    4. 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.
    5. 2.5Reserved wordsReserved words belong to the language itself, such as If or While; you cannot use them as the name of a variable.
    6. 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.
    7. 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.
    8. 2.8Operators and signsOperators and signs are the pieces made of symbols, such as +, <= or <-; the engine always reads the longest possible piece.
    9. 2.9Statement endEvery simple statement ends with a semicolon; the words that open and close blocks, such as If or EndWhile, do not.
    10. 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.
  2. Types and values

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

    1. 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.
    2. 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. 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.
    4. 3.4ArraysAn array is a row (or a table) of boxes of the same type, with a fixed size and numbered from zero.
    5. 3.5VectorsA vector is a list that grows and shrinks while the program runs; all its elements have the same type.
    6. 3.6DictionariesA dictionary stores key-value pairs: you look up by the key and get the value, like in a phone book.
    7. 3.7RecordsA record groups several named pieces of data into a single value, like a card with its sections; assigning it copies it whole.
    8. 3.8EnumerationsAn enumeration is a type with a closed list of named values, like the colours of a traffic light.
    9. 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.
    10. 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.
    11. 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.
    12. 3.12GenericsA generic is a subroutine or a type written once for any type: the concrete type is filled in when it is used.
    13. 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.
    14. 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.
    15. 3.15Checking levelsThe engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.
  3. Library

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

    1. 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.
    2. 12.2Text functionsText functions measure, trim, search and transform strings without ever modifying the original: they always return a new one.
    3. 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.
    4. 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.
    5. 12.5Reproducible randomnessPseudoLearn's randomness comes from a source with a seed: with the same seed, the program always draws the same numbers.
    6. 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.
    7. 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.
    8. 12.8JSONparseJson turns a JSON text into a value you can walk through, and jsonText goes the other way.
    9. 12.9HTTPWith the network capability, a program builds an HTTP request, sends it and receives a response with its status, headers and body.
    10. 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.
  4. Appendix A — Grammar

    The complete grammar, generated from the corpus.

    1. A.1Grammar
  5. Appendix B — Reserved words

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

    1. B.1Reserved words
  6. Appendix C — Diagnostics

    The complete catalogue of engine messages.

    1. C.1Diagnostic catalogue
  7. Appendix D — Built-in functions

    Every function and operation of the library.

    1. D.1Built-in functions
  8. Appendix E — Glossary

    The technical words of this specification, explained.

    1. E.1Glossary
  9. Appendix F — Alphabetical index

    Everything in the specification, ordered from A to Z.

    1. F.1Alphabetical index

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.