• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code-as-data in Ruby, without the metaprogramming madness.

LISPY

Yeah, right. Get a room, you two.

Nothing to do with LISP, Problem?

The backstory.

I've written a number of Ruby libraries in my time. I've used many, many more. Wait, let's back up a bit.

Assumptions.

  • People love libraries like Sinatra and ActiveRecord and Babushka and AASM and (name your favourite Ruby library).
  • What they love about these is the small amount of Ruby syntax required to get a whole lot done.
  • They love that they can contextualise their definitions (that make the libraries do things) with natural Ruby syntax such as blocks.
  • To enable these kinds of libraries the use of so-called 'meta-programming' constructs are required (instance_eval, instance_exec).
  • Clever but inexperienced Ruby programmers often make very useful libraries with wonderful APIs but horrible internals (my hand is up, see: Workflow).

Goals.

  • Decouple the 'pretty Ruby junk' from the (hopefully) clean and explicit implementation that makes the library do it's job.
  • Allow library authors to dream up APIs and implement them without entering Ruby metaprogramming hell (it is a real place).

Examples.

Take the following example:

Lispy.new.to_data do
  fart 1
  fart 2
  fart 3, 4
  fart
  fart :where => :in_bed
end

This will return [[:fart, 1], [:fart, 2], [:fart, [3, 4]], [:fart, []], [:fart, {:where => :in_bed}]]. It looks somewhat like an abstract syntax tree (I think). Let's take an example with nesting:

Lispy.new.to_data do
  todo_list do
    item :priority => :high do
      desc 'Take out the trash, it stinks.'
    end
    item :priority => :normal do
      desc 'Walk the dog.'
    end
    item :priority => :normal do
      desc 'Feed the cat.'
    end
  end
  interested_parties do
    person 'Me.'
    person 'You.'
    person '...'
  end
end

The pretty printed output is this, but before you continue, I ask you to take a deep breath, and remember that you are a programmer and that you have been writing Ruby for too long to be able to look at anything else than ActiveRecord declarations and say something along the lines of "WTF IS THIS, IT IS BAD CODE OMFG I AM TELLING!!!1". Yes, once upon a time you were able to think as a programmer and once you had patience! Now, that output:

[[:todo_list, []],
 [[:item, {:priority=>:high}],
  [[:desc, "Take out the trash, it stinks."]],
  [:item, {:priority=>:normal}],
  [[:desc, "Walk the dog."]],
  [:item, {:priority=>:normal}],
  [[:desc, "Feed the cat."]]],
 [:interested_parties, []],
 [[:person, "Me."], [:person, "You."], [:person, "..."]]]

That last example, I just wrote off the top of my head. You see how you can start with an API design and worry about implementation later? If you haven't tried to make a 'nice' Ruby library before, this wont be self evident, but for those that have, and have struggled through all the madness, you'll see what I mean. Once you've made up your API, all you have to do is write the translation library that does whatever that needs to be done. If that is piping out to a shell, writing a configuration file or constructing an object graph, then well, you're covered aren't you?

Your crazy so-called 'DSL' is now decoupled from your wonderfully explicitly programmed library, I hope. Because I might have to modify it one day and man, if I see a rats nest of instance_execs and auto-generated classes I might just... write you a nasty letter. With angry faces like this: >:|

Now what?

If you have any questions about this, or how I'm using it for real-world problems (I am!), please get in touch. Pete won't talk to me about this, and I bought his car and everything!!!

Why Lispy?

To my mind, this whole API fandangle we've gotten ourselves into is due to Ruby having a nice enough syntax to describe APIs in a way that is easy to understand, but Ruby itself wasn't designed with this usage in mind. When I see lines like has_one :brain and dep 'nginx' do it reminds me of a feature of LISP, which is code as data. Ruby doesn't have this code as data facility but I reckon if it did, we'd have cleaner library implementations with it's idomatic syntax.

Saying that, I've written about 10 lines of LISP in my life. Pete keeps telling me to go read SICP and I keep meaning to but then I end up at the local bar listening to some rock band and I'm like "crap, it's 3am". And even then, I wont get to use LISP at work because I don't think anyone in our company except for Pete has actually read SICP.

License.

Released under the MIT license (see MIT-LICENSE). GPL can go fart itself, seriously. I like open source, but I also like money.

More Repositories

1

workflow

A Ruby state machine library, like assm / acts_as_state_machine, but with a nicer, more sensible API (in my opinion).
Ruby
233
star
2

w1000-super-total-mega-shark-cache-on-a-boat-on-a-plane

Fork of wp-cache plugin that uses uri based filepaths (like wp-super-cache) but with query strings and without wp-super cache's codebase and behaviour. Aim is to be the absolute fastest and simplest wp cache plugin coz each of them have their warts in their own ways.
24
star
3

sir-sync-a-lot

Baby got backups! (a fast S3 backup tool).
Ruby
22
star
4

lumberjack

Lumberjacks cut down trees. This lumberjack builds them (it's a generic DSL for constructing object trees).
Ruby
16
star
5

hack

The tiniest web-framework, ever.
Ruby
12
star
6

dns

Migrating a lot of DNS? Yeah, well this should help a bit.
Ruby
11
star
7

aspect

A kind of sort of AOP-ish library thingy that I did, everyone else is mad, I swear.
Ruby
7
star
8

modelling

Wraps some common-ish plain-ruby object modelling junk.
Ruby
6
star
9

not

Inverts booleans. I'm not sure if this was not or not done before, but it's not done now!
Ruby
6
star
10

offload

A background job library that doesn't exist (really).
5
star
11

dashboard

Set this as your homepage and put things on it that you need in front of your face often (coz you always forget).
5
star
12

superheroes

Tease apart the semantics of what things are versus what they can do.
Ruby
5
star
13

ryan-allen.github.com

5
star
14

hijack

Another AOP-like (hijacking) library, when I forgot that I had already written one (aspect), and I still swear everyone else is mad.
Ruby
3
star
15

best3

The best Ruby Amazon S3 library in existence (well, not yet).
Ruby
3
star
16

lost-socks

Lost Socks is a Ruby DSL (lol) for specifying DNS records, and verifying these records against name servers. Handy for large DNS migrations, where a record here or there are inevitably left behind, misspelled or entered incorrectly.
Ruby
3
star
17

lest

A minimal Lua testing framework, just for kicks.
Lua
2
star
18

tdsa

TDSA = Test Driven System Administration. Well, this only plays with web servers. But anyway.
Ruby
2
star
19

rock_view

A deprecated view library, ERB on steroids. We replaced it with about 10 lines of helper methods.
Ruby
2
star
20

tilde-slash

Junk that lives in my home directory, .gvimrc, .profile, .gitconfig, etc :)
Vim Script
2
star
21

jdigits

Key combinations in JavaScript because, like, it's never been done before. LOL.
JavaScript
2
star
22

hiccup

The same thing, over and over again, until it's not.
2
star
23

turns.js

Single-player option-based story engine thing.
JavaScript
2
star
24

yeahnah.org

My frig website.
2
star
25

stumpy

Automatotron.
Ruby
1
star
26

douche

WHAT IF I DIDN'T WANT TO BUY THE POTION? WHAT APOUT QUESTS?
Ruby
1
star
27

interceptor

Mad Max had one, and he was freaking awesome.
Ruby
1
star
28

comb

A simple assembler for client-side modularity in JavaScript applications.
Ruby
1
star
29

tree-face

Tree Face is the successor to Lumberjack. It's a big nasty tree with a big nasty face and it's out for revenge!
1
star
30

blaaag

My bl(o|aaa)g.
1
star
31

the-railroad

Now when people ask "What are you working on?" I can say "I've been working on the-railroad". They ask "How long have you been working on that?" and my reply "All the live long day."
1
star