Skip to content

justland/just-func

Repository files navigation

just-func

just-func is a functional programming language interoperable as JSON.

It is homoiconic (code as data) and implementation independent.

It can be written in JSON, YAML, or other media that can be translated to simple JSON.

It can be used to capture logic that shared across multiple programming languages.

Its typical use case is to define the logic in data or some markup language, the logic can then be used in runtime or code generation in various programming languages.

Here is a hello world example for REST API:

paths:
  /hello:
    get:
      parameters:
        - name:
          type: string,
          required: true
      # handler is defined using `just-func`
      handler: [str, "welcome to just-func, ", [param/get, name]]

Using just-func

Languages supporting just-func will provide a parser and other tools to enable further processing.

For example, the following code uses the Interpreter to handle the call in PHP:

use JustLand/JustFunc/Interpreter;

class HelloRoute
{
  /**
   * @var Interpreter
   **/
  private $interpreter;

  public function __construct()
  {
    $this->interpreter = new Interpreter([
      "param/get" => function ($name) { return $_REQUEST[$name]; }
    ]);
  }
  public function execute()
  {
    return $this->interpreter->execute('[str, "welcome to just-func, ", [param/get, name]]');
  }
}

What's in this repository

This repository is distributed in package manager of various languages, so they can be used to provide:

  • IDE support by the use of language schema
  • Program validation by the use of language schema
  • Language implementation validation by the use of specs

install - PHP

This package is distributed as justland/just-func-schema on composer.

composer require justland/just-func-schema

It comes with some helper functions you can use to update the schema for your application (as currently the schema is not added to schemastore.org and requires json-schema 2020-12 to be fully functional).

// composer.json
{
  "scripts": {
    "update-json-func-schema": "justland\\just-func-schema\\Composer::copySchema"
  }
}

Contribute

# install TypeScript dependencies
# TypeScript code are used for testing
yarn

# validate specs in the `schema-specs` folder
yarn validate:specs

# install mdbook for book development
# you need to first install Rust (https://www.rust-lang.org/tools/install)
cargo install mdbook

# build books
mdbook build [path/to/book]

# watch build books
mdbook watch [path/to/book]

# serve books
mdbook serve [path/to/book]

About

Just a Functional Programming Language

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published