Code Monkey home page Code Monkey logo

minima's Introduction

Minima

Minima is an experimental interpreter written in Go (the language is called the same). We needed a way to massage our JSON data with a scripting language.

The syntax (or the lack of it) is inspired by Lisp, to be easy to parse for machines. However, I tried to get rid of the zillions of parentheses to be easy to parse for humans too. With significant whitespace and indentation, the outermost parentheses are there, but they are kinda transparent.

Everything is subject to change.

General example

-- This is a comment
set n (+ 2 1)
set x 8
if (< n x)
	run
		println "Multiline if."
		println "n is smaller than " x
	println "n is greater or equal than " x
for n
	println "n is " n

This above snippet will produce:

Multiline if.
n is smaller than 8
n is 3
n is 3
n is 3

Newline shorthand

One can use the ";" as a shorthand for a newline with same indentation:

set a 10; set b 20

Function definition and call

set k 10
func l (u) (run
	println k
	+ u u u u)
println (l 20) 
println u

Produces:

10
80
<nil>

Closures

func l (u) (run
	set m 9
	func (v) (+ v u m))
set p (l 10)
println (p 30)
println (p 40)

Produces:

49
59

Recursion

func fib (x)
	if (| (eq x 0) (eq x 1))
		get x
		+ (fib (- x 1)) (fib (- x 2))
println (fib 15)

Produces:

610

Panic/recover

func k (panic "OMG")
func f (run
	recover (run(println "Recovering from " prob) (+ 1 1))
	println "Panicking in next function call."
	k
	println "This shall not run.")
func l (run
	println "Just a casual println..."
	set ret (f)
	println "This shall run."
	get ret)
println (l)
println "Recovered"

Produces:

Just a casual println...
Panicking in next function call.
Recovering from OMG
This shall run.
2
Recovered

Defer

func f (run
	defer (println 0)
	defer (println 1)
	println "This shall run before the deferred functions.")
f

Produces:

This shall run before the deferred functions.
1
0

Goals

  • Create a language in pure Go.
  • Create a scripting language which is statically typed.

Latest additions

  • Defer
  • Panic/Recover
  • Better recursion support.
  • Eq, |, & operators.
  • Variable scoping, functions, closures.

Roadmap

  • Defer
  • []interface{} and map[string]interface{} types to be able to handle JSON data.
  • More syntactic sugar (expect some neat things here).
  • More builtin goodies.
  • Static typing.
  • Packages.
  • A mongodb driver ;)
  • Optimizations.

minima's People

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.