Code Monkey home page Code Monkey logo

soul's Introduction

Soul - an esoteric concatenative language

Soul is an esoteric concatenative one-stack language, a small explorative language with an interpreter written in a day.

Most concatenative languages work on a state, often that's another stack. For example, Forth has a data and return stack and Postscript has an extra stack outputting to a page.

Soul is a minimalist language that provides one thing, and one thing only, the one sole stack. That, of course, is very problematic as a model of computation but Soul gets around that with two tricks:

  1. Treat the stack as random access memory.
  2. Whenever a constant integer or text is found on top of the stack, that gets swapped with whatever is underneath.

Soul expressions consist of integers, texts, and words. Words may define other expressions. A Soul expression defines a stack. The top of the stack is repeatedly evaluated until the stack is empty.

Predefined Operators

fetch, put, and delete inspect or modify the stack, they all take an integer argument where put takes a second argument to put somewhere in the stack.

The arithmetic operators +, -, *, / are all binary prefix operators. + is overloaded to work on texts also.

The equality operator = tests two arguments for equivalence, it results in either true or false. Both booleans are functions that select between two arguments; e.g., true f g evaluates to f.

print and line are the basic input/output words, to_int and to_text convert between integers and texts.

Examples

Hello World example:

"hello" print "world" print

Output 42, showcasing the defintion of a word:

# calculate the answer to everything
:f  * 6
+ 3 4 f print

The faculty function:

# the faculty function

# get
:get2   delete 1
:get1   fetch 5 + 3 delete get2
:get0   fetch 4 + 4 fetch get2 
:get    fetch 2 get0 get1 

# fac
:fac3   get 2 fac *
:fac2   fetch 3 - 1 fac3
:fac1   delete 1 1
:fac0   get 4 = 0 fac1 fac2
:fac    fetch 1 fac0 

fac 6 print

The Soul interpreter is written as an Egel script and implements a REPL.

You can run the interpreter with egel soul.eg. Either pipe the example programs to that process or copy-paste the source directly into the REPL.

soul's People

Contributors

egel-lang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mercerenies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.