ReedOei / Enki

A beginner-focused logic programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

Build Status

Enki is intended to be a logic language for teaching programming to people with no programming experience. It is still a work in progress, and is not yet ready to be used for this purpose.

To run an Enki file (see examples below or in the examples directory, use the following command:

enki run FILENAME [OUTPUT FILE PATH]

To compile the file:

enki compile FILENAME <OUTPUT FILE PATH>

To see the code output, run:

enki FILENAME

Installation

You will need stack:

curl -sSL https://get.haskellstack.org/ | sh

Then you can run:

git clone https://github.com/ReedOei/Enki
cd Enki
stack install
echo "export ENKI_PATH=\"$(pwd)/libraries/base\"" >> ~/.bashrc

Examples

Sample code to solve Problem 1 on Project Euler:

A divides B if B = A*N.

multiples of A in List is
    when List = H :: T, A divides H then prepend H to multiples of A in T;
    when List = H :: T then multiples of A in T;
    when List = empty then empty.

answer less than N is
    ThreeMult = multiples of 3 in range 1 to N,
    FiveMult = multiples of 5 in range 1 to N,
    FifteenMult = multiples of 15 in range 1 to N,
    sum of ThreeMult + sum of FiveMult - sum of FifteenMult.

display as text answer less than 999.

Alternatively, we may use partial application and higher order functions to rewrite multiples of _ in _ as:

multiples of A in List is filter List with (A divides _).

Sample code to solve Problem 2 on Project Euler:

fib nums A B Limit is
    when A > Limit then empty;
    when A <= Limit then prepend A to fib nums B (A + B) Limit.

fib seq up to N is fib nums 0 1 N.

display as text sum of multiples of 2 in fib seq up to 4000000.

About

A beginner-focused logic programming language.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 72.2%Language:Prolog 27.8%