Coder Social home page Coder Social logo

basil's Introduction

Basil

Basil is a message-based programming language. Its name is a reference to both Aceto and OIL.

Concept

Basil has something like a message queue, but it's called the message bag, because the order elements are taken out is "random"; non-guaranteed. There is rudimentary support for expressions and some operators, but for the most part, all a basil program does is wait for messages and react to them by sending other messages.

Syntax

A basil file contains one or more blocks. A block consists of a header, and a set of statements that get executed when a message is received. The header is a space-seperated list of topics this block listens to.

A statement starts with an optional condition, followed by a > character, followed by an action, optionally followed by another > character and another action. A semicolon finalizes a statement:

(condition) ">" (action) ">" (another action) ";"

A condition is an expression. An action is a triplet, seperated by spaces: topic, body, and reply-to. Both topic and reply-to have to be atoms, body can be an arbitrary expression. body and reply-to are optional, but when reply-to is given, body has to be given too.

An expression is either:

  • an integer
  • a string (enclosed in double-quotes)
  • a tuple of one or more values (in Python syntax)
  • an atom; a alphanumerical string of characters.
  • a complex expression consisting of an operator and one or more operands (prefix notation)

Apart from alphanumerical atoms, there are three special atoms: @, &, and $. They refer to the current body, current reply-to and current topic, respectively.

The usual operators do what one would expect, and there's one more: # is an indexing operator, such that #ab evaluates to the bth element of a.

Semantics

When a message (basically a triplet of topic, body, and reply-to) is being sent, it is being pushed in the bag. When one is being popped, every block that has the message's topic listed in its header gets executed with the message. This may happen in any order.

For every statement, the condition is first evaluated. If it is truthy (not 0 or an empty string or an empty atom) or if it doesn't exist, the first action gets evaluated and sent as a message. Otherwise, this happens with the second action.

At the beginning of the execution of a basil program, a message with the topic "main", an empty body and empty reply-to is pushed in the bag.

Builtins:

Some topics are listened to by built-in blocks (that are not implemented in basil). All built-in topics are lowercase, so it is recommended to choose Titlecase topics in user code to avoid collision (unless collision is intended).

A list of builtins can be seen in the file stdB.py.

Example code

The typical Hello World program just sends a message with the print topic, which the standard library picks up.

main { print "Hello, World!"; }

basil's People

Contributors

l3viathan avatar

Watchers

 avatar  avatar

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.