FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

everwise/conflisp-ruby at bug/avoid-stack-overflow-test · GitHub

 
 

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conflisp

A tool for buliding JSON-serializable lisps.

Sometimes you need to make something configurable at the database level, but you don't want your application to have to support all possible variations of that configuration.

You can also use Conflisp as a sort of JSON template language, à la Jsonnet.

Installation

RubyGems

gem install conflisp

Bundler

gem 'conflisp'

Usage

  1. Define your functions

    MyLang = Conflisp::Language.define do
      fn :add, ->(a, b) { a + b }
      fn :subtract, ->(a, b) { a - b }
    end
  2. Use it

    > MyLang.evaluate(['add', 2, ['subtract', 3, 1]])
    => 3

You can pass in variables into the evaluator and you will have access to them in your expressions:

> MyLang.evaluate(['add', 2, ['global', 'foo']], globals: { 'foo' => 3 })
=> 5

Normally you would store the expressions in a database and then evaluate them when you need to:

> myfoo = MyFoo.find(123)
> configuration = MyLang.evaluate(myfoo.config, globals: { 'current_time' => Time.now.utc })

Your functions can also refer to other functions using the resolve method:

MyLang = Conflisp::Language.define do
  fn :add, ->(a, b) { a + b }

  fn :add_twice, ->(a, b) do
    resolve([
      'add',
      ['add', a, b],
      ['add', a, b]
    ])
  end
end

Conflisp only provides one built-in function (global). We don't want to be opinionated on the ordering of the arguments to your functions (think lodash vs. lodash/fp), so it is up to the application developer to implement all of their functions.

You can also extend your languages to add new functions:

BaseLang = Conflisp::Language.define do
  fn :add, ->(a, b) { a + b }
end

# NewLang will also have access to the `add` method.
NewLang = BaseLang.extend do
  fn :foo, ->() do
    # ...
  end
end

License

MIT License

Copyright © 2019 Everwise

About

A tool for building JSON-serializable lisps

Topics

Resources

Stars

4 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL