GithubHelp home page GithubHelp logo

juliapoo / floof Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 86 KB

A minimal programming language comprised entirely of one object type: `T ::= T -> T`

Python 100.00%
programming-language language interpreter esolang

floof's Introduction

Floof

Floof is a minimal programming language comprised entirely of one object type: T ::= T -> T, or in other words, the only object type in Floof is a function of type T, whose input and output is also of type T. The exception to this are the reserved functions that take in user input, which has no arguments, and the reserved functions that prints, which has side effects.

Introduction

Function Definitions

A function in Floof consists of an argument_name and a definition. The syntax is as follows:

[argument_name:definition]

The function can then be called as such:

[argument_name:definition](argument)

Examples:

[f:f]                   ; Identity function
[f:[x:f(f(x))]](g)(y)   ; Equivalent to g(g(y))

Literals Representation

The only literals in Floof are nonnegative integers and implemented as special functions of type T. The integer n is implemented as a function that takes in a function f and an object x and returns f^n(x).

Examples:

[f:[x:x]]         ; Represents the literal `0`
[f:[x:f(x)]]      ; Represents the literal `1`
[f:[x:f(f(x))]]   ; Represents the literal `2`

Input and Output

Floof takes in either integers or char, and can output (print) in either integer or char. Several reserved names are used for these:

_IN_INT_()      ; Waits for user to input a non-negative
                ; integer and returns it in the representation
                ; mentioned above
                
_IN_CHAR_()      ; Waits for user to input a character and
                ; returns an integer representing the Unicode 
                ; code point of that character, in the 
                ; representation mentioned above

_OUT_INT_(arg)  ; Prints the integer represented by `arg` of 
                ; type `T`. Returns `arg`.

_OUT_CHAR_(arg) ; Prints a char in the Unicode code indexed by the
                ; integer represented by `arg` of type `T`
                ; Returns `arg`.

Examples:

_OUT_INT_(
    [f:[x:x]]
)                       ; Prints `1`
_OUT_CHAR_(
    _IN_CHAR_()
)                       ; Waits for user to input a character and echos it out

Comments

Comments start with a ;. Everything in a line after a ; is ignored and treated as a comment.

Program Format

A Floof program consists of several macro blocks and a main block. Each block starts with either a # or a ! and ends with a ~. Each block can contain only one expression. Everything after the main block is ignored.

Macro blocks

Macro blocks are meant to modularise the program. Once defined, they can be used further down in the program. Macro blocks cannot reference themselves. They have the following format:

#<macro_name>
<macro_definition>
~

macro_name must follow these conditions:

  1. Start with a letter or the underscore character.
  2. Cannot start with a number.
  3. Can only contain alpha-numeric characters and underscores (A-z, 0-9, and _)
  4. Case-sensitive (age, Age and AGE are three different variables)

macro_definition must consist of a single expression.

Macros are also defined top down. A macro cannot reference a macro below it in a file.

Examples:

#N0     ; Represents the integer 0
[f:[x:x]]
~

#INC    ; INC(a) computes a+1
[n:
    [f:
        [x:
            f(n(f)(x))
        ]
    ]
]
~

#N1     ; Represents the integer 1
INC(N0) ; Used the above macros
~

#N2     ; Represents the integer 2
INC(N1)
~

Main block

Each Floof program can only contain one main block. The main block is what the interpreter will run. Any macros that the main block uses must be defined above it. They have the following format:

!
<main_definition>
~

main_definition must consist of a single expression.

Examples:

!       ; Prints `1`
_OUT_INT_(
    [f:[x:x]]
)
~
#N1     ; Represents the integer 1
[f:[x:f(x)]]
~

#INC    ; INC(a) computes a+1
[n:
    [f:
        [x:
            f(n(f)(x))
        ]
    ]
]
~

!       ; Prints `2`
_OUT_INT_(
    INC(N1)
)
~ 

Running a Floof program

This repository contains a python3 interpreter. Run:

python -m floof -f <filename>

An additional -v flag can be given to make the interpreter output intermediate representations of the Floof program.

Try running Floof programs in the folder ./examples.

The interpreter will also alert you of syntax errors in your floof program by giving the line number.

Tips

You can build data structures with just type Ts! Abstract it out! You might wanna take a look at ./examples for examples.

Programming with Nothing by Tom Stuart can get you started on some possible constructions.

Credits Due

I got the idea for this programming language from reading Tom Stuart. Do check him out!

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.