Giter Club home page Giter Club logo

syrup's Introduction

Syrup, a syntactically-light LISP

fib = fn: [n]
    calc-fib = fn: [n a b]
        if: (n == 0)
            a 
            calc-fib: (n - 1) b (a + b)
    calc-fib: n 0 1

print: fib: 10

From the command line:

coffee syrup.coffee examples/fib.syrup

And for a REPL:

coffee syrup.coffee

Syntax

Syrup is whitespace-significant. Function calls are made by a colon following an atom. All subsequent arguments on a line are passed to the function until a newline of the same indentation, the end of a parenthetical, or a semicolon ;

print: "Cool language x" 5000  # Parses as (print "Cool language x" 5000)
print:                         # Equivalent
    "Cool language x"
    5000
print: square: 5; square: 6;   # "25", "36"

Parentheses are for disambiguation, and are insignificant. Commas are allowed, but not required.

calc-fib: (n - 1) b (a + b)
calc-fib: n - 1, b, a + b

Vector (array) syntax is like JavaScript's array literals. Vectors are not executed as functions.

[5 6 7 8] # equivalent to list: 5 6 7 8

Quoting uses `.

print: `apples                 # prints "apples"

Infix notation is supported for arithmetic operators and the assign operator:

5 + 6                          # these two lines...
+: 5 6                         # ...are equivalent
test = fn: [] print: 'hi'      # declares the function 'test'

Macros are supported:

unless = macro: [cond t f]
  [`if cond f t]

print: unless: true "falsy" "truthy"

Object literals can be defined using quoted strings or string variables as keys (as in python). Any arguments after the first passed to a string function have their properties copied to the new object literal. Finally, curly-braces combine all listed objects into one.

"a": 1                         # JSON: {"a": 1}
key = "somekey"
key: "val"                     # JSON: {"somekey": "val"}
("some" + "key"): "val"        # JSON: {"somekey": "val"}
obj = "b": 2 "c": 3            # parses to ("b" 2 ("c" 3)), equals {"b": 2, "c": 3}
obj2 = {"a": 1, obj}           # parses to (combine ("a", 1) obj), equals {"a": 1, "b": 2, "c": 3}

Syrup's loop struct helps mimic the benefits of tail-call optimization.

range = fn: [i]
  loop: [i, r = []]
    if: (i == 0) r
      continue: (i - 1), concat: (i - 1), r

print: range: 5                # [0, 1, 2, 3, 4]

Roadmap

  • Lots more bikeshedding.
  • Option to write Node.js scripts in syrup.
  • Rewrite compiler in Syrup.

License

Syrup is released under the MIT License.

syrup's People

Contributors

tcr 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.