From 464cbe840a8a6e9b171b86f5e494fabfa3fd0fb7 Mon Sep 17 00:00:00 2001 From: Euryn Date: Mon, 22 Jan 2024 03:00:43 +0100 Subject: [PATCH] finalized examples --- docs/03-supported-syntax.md | 2 +- docs/04-examples.md | 98 +++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/docs/03-supported-syntax.md b/docs/03-supported-syntax.md index 7c45410..9f2b088 100644 --- a/docs/03-supported-syntax.md +++ b/docs/03-supported-syntax.md @@ -25,7 +25,7 @@ A process can contain any number of words and symbols, but it must contain at le From Wikipedia's article on Nassi–Shneiderman diagram: -> "The loop allows the program to loop one or a set of processes until a particular condition is fulfilled. +> "The loop allows the program to loop one or a set of processes until a particular condition is fulfilled." The project supports two types of loops: test-first loops and test-last loops, each differing in the sequence of executed steps. diff --git a/docs/04-examples.md b/docs/04-examples.md index 97f29a8..487a959 100644 --- a/docs/04-examples.md +++ b/docs/04-examples.md @@ -5,48 +5,118 @@ It is not a tutorial on how to use the project, but rather a showcase of what th ## Variable assignment +> Variable assignment is a fundamental concept that involves giving a name to a piece of data. +> It allows for storage and manipulation of information within a computer program. + +When a value is assigned to a variable, it is akin to instructing the system, "Remember this information by this name." +It's like storing a number, a word, or any other data type under a chosen label. +The label can then be utilized in the code to perform operations, make decisions, or simply reference that piece of data. + Textual description: -The [Pseudocode](https://en.wikipedia.org/wiki/Pseudocode#Common_mathematical_symbols) style variable assignment: +[Pseudocode](https://en.wikipedia.org/wiki/Pseudocode#Common_mathematical_symbols) style using ":=" symbol: +[Pseudocode](https://en.wikipedia.org/wiki/Pseudocode#Common_mathematical_symbols) style using "<-" symbol: + + + ## Type annotation +> Type annotation is the practice of explicitly specifying the data type of a variable. +> This helps in defining the kind of information that a variable can hold, promoting code clarity and preventing potential errors. + +When annotating the type of a variable, additional information is provided to both programmers and the compiler or interpreter. +It is similar to informing the system that a variable is meant to store numbers, text, or some other specific data type. + Textual description: -The [C programming language](https://en.wikipedia.org/wiki/The_C_Programming_Language) style type declaration: +[C programming language](https://en.wikipedia.org/wiki/The_C_Programming_Language) style: - + -[Python](https://docs.python.org/3/library/typing.html) and [Typescript](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html) type annotation: +[Python](https://docs.python.org/3/library/typing.html) style: - + ## Loop -The [Pascal]() style loop: +> Loops are a construct that allows a program to repeat a set of processes or operations until a particular condition is met. +> They enhance the efficiency and flexibility of code, enabling the automation of repetitive tasks. + +The loop concept involves two main types, both types provide a mechanism for controlled repetition, contributing to the structured flow of a program: + +- **Test-First Loops**: The condition is checked before executing the processes. +- **Test-Last Loops**: The condition is assessed after the processes have run. - +Textual Description (Test-first loop): + + + +Pseudocode style (Test-first loop): + + ## Sequence calculation -Sequence calculation is a pattern of algorithm which reduces a sequence of elements to one element. -In the most generic form, this pattern requires an initial value as a starting point and a reducer function. +Sequence calculation is a pattern of algorithm which reduces a sequence of elements to one element, which is archieved by repeated applying functions or operations to two elements and combining them into one. -The "result" variable is the accummulator as the sequence is calculated and the "op" function is the reducer function. +Sequence calculation on integers using addition: - + ## Counting Counting is a pattern of algorithm which reduces a sequence of elements to a natural number. -The behavior is archieved through a predicate function. +It looks at every element in a sequence and see how many of those elements have a certain property. + +Counting the number of primes numbers in an interval: + + + +## Maximum selection and minimum selection + +Maximum selection and minmium selection are a similar pattern algorithm. +Both of them reduce a sequence of elements to one element. +This element is either the "maximum" or the "minimum" element of the sequence. + +Maximum selection on integers: + + + +Minimum selection on integers: + + + +## Search + +Search is a pattern of algorithm which reduces a sequence of elements to one element. +The element is chosen based on whether it has a certain property or not. +However, such an element might not exist in the sequence. + +Searching for a prime number in a sequence of integers, defaults to "-1" when the sequence does not contain a prime number: + + + +## Selection + +Selection is a pattern of an algorithm which reduces a sequence of elements to one element. +Unlike Search, at least one such element exists. + +Selecting the last prime number in a sequence of integers: + + + +## Decision + +Decision is a pattern of an algorithm which reduces a sequence of elements to a boolean value. +If an element in a sequence satisfies a certain property, it resolves to true, and false otherwise. -The "counter" variable keeps track of valid and invalid elements and the "hasAttr" function serves as the predicate. +Decide whether a sequence of integers contains a prime number or not: - +