Project

smullyan

0.0
No release in over 3 years
A Ruby gem implementing the combinatory logic birds from Raymond Smullyan's To Mock a Mockingbird
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.18
~> 13.0
~> 1.50
 Project Readme

Smullyan

A Ruby implementation of combinators from Raymond Smullyan's "To Mock a Mockingbird".

Installation

Add this line to your application's Gemfile:

gem 'smullyan'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install smullyan

Usage

require 'smullyan'

# Using SKI combinator names
s = Smullyan::Birds::S
k = Smullyan::Birds::K  
i = Smullyan::Birds::I

# Or use the bird names!
kestrel = Smullyan::Birds::Kestrel      # K combinator
starling = Smullyan::Birds::Starling    # S combinator
mockingbird = Smullyan::Birds::Mockingbird # M combinator

# Example: Identity function derived from S and K
identity = s.(k).(k)
identity.(42) # => 42

# Example: Function composition with the Bluebird
bluebird = Smullyan::Birds::Bluebird
double = ->(x) { x * 2 }
increment = ->(x) { x + 1 }
double_after_increment = bluebird.(double).(increment)
double_after_increment.(5) # => 12

# Example: Y combinator for recursion
why = Smullyan::Birds::Why
factorial = why.(->(f) {
  ->(n) { n <= 1 ? 1 : n * f.(n - 1) }
})
factorial.(5) # => 120

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/philcrissman/smullyan.

License

The gem is available as open source under the terms of the MIT License.