Leonardus
Loading...
Searching...
No Matches
EXAMPLES

Introduction

There is a collection of examples in the directory Examples.

Run it from a Leonardus git repository

To run one of them in the shell, use:

‍../Examples> ../lb Hanoi.leo

All examples can be executed with:

‍make runxtest

Run it from the docker image

To run one of them in the shell, use:

‍../Examples> lb Hanoi.leo

or by using the Linux shebang:

‍../Examples> ./Hanoi.leo

List of Examples

ArrayEqual.leo

A procedure arrayeq to compare array contents.
This is not a deep comparison; the contents of the arrays are compared
with the build-in eq operator.

Caesar.leo

Demonstrates Caesar decryption

Complex.leo

Demonstrates a prototype-based object (PTBO) by using the
data type Complex from vocabulary Prototype.

EgyptianFraction.leo

Demonstrates the representation of a rational
number in the interval [0,1] as a sum of unit fractions (fractions with numerator 1).
However, the computed representation is not always the shortest possible.

EndDictOperator.leo

A simple example of how to implement one operator with others.
The enddict procedure is equivalent to the >> operator.

ExtendedEuclidean.leo

Demonstrates the usage of the Extended Euclidean Algorithm, implemented as xgcd.

Factorial.leo

Demonstrates the implemented 128-Bit integer size.
The definition of the factorial procedure is a fragment from the Green Book.

Factors.leo

Demonstrates a procedure factors,
that generates a list of all factors of an integer X > 0 and places the list on the stack.

FibonacciGoldenRatio.leo

The list of the first 51 Fibonacci numbers.
Using the vocabulary Numbers algorithm with an exponentiation of the golden ratio.

FibonacciLinear.leo

A linear algorithm to calculate Fibonacci numbers.
The rational numbers allows arbitrary long integers.

FibonacciQ5FastExp.leo

Fibonacci numbers by fast exponentiation of quadratic field elements.
The rational numbers allows arbitrary long integers.
F_n = ( sqrt(5)-coefficient of (1+sqrt(5))^n ) / 2^(n-1)
The script calculates some example Fibonacci numbers and at
the end F(10,000,000) to demonstrate the performance of the calculation.

FibonacciRecursive.leo

A compact but inefficient recursive way to print the first 20 Fibonacci numbers.
(copied from Wikipedia).
This script can be executed by Ghostscript, if one removes the shebang.

Hanoi.leo

Demonstrates stack objects in a procedure hanoi,
which solves the mathematical puzzle Tower of Hanoi recursively.

ListComprehension.leo

Demonstrates semantics similar to Python's list comprehension

MonteCarlo.leo

Demonstrates the approximation of pi with a simple
Monte Carlo simulation of random points within a circle.

NCat.leo

A procedure ncat to concatenate strings.
It demonstrates an implementation using only stack manipulation and the putinterval operator.
This could replace the concat operator, making the LeoScript core code smaller.
Source: stackoverflow luser droog

PyMapFunction.leo

Demonstrates semantics similar to Python's map() function on lists with a lambda

PyUnpacking.leo

Demonstrates semantics similar to Python's unpacking operator

Snap.leo

Demonstrates a statistics snapshot at program end.

StatisticsOOP.leo

Demonstrates a prototype-based object (PTBO) encapsulation using the
calculation of measures of statistical dispersion in descriptive statistics.

switch.leo

Demonstrates the switch operator