Skip to content
/ ludy Public

Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library, especially for functional programming.

License

Notifications You must be signed in to change notification settings

godfat/ludy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= ludy 0.1.13
by Lin Jen-Shin (godfat[http://godfat.org])
  godfat (XD) godfat.org

== LINKS:

* rdoc[http://ludy.rubyforge.org]
* rubyforge-project[http://rubyforge.org/projects/ludy]
* github-project[http://github.com/godfat/ludy]
* redmine-project[https://redmine.godfat.org/projects/show/ludy]

== DESCRIPTION:

Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library, especially for functional programming.

== FEATURES:

1. ludy standard library extension, especially for functional programming.
2. rails/array paginator, included since 0.1.2
3. c++ erb meta-programming, included since 0.1.0 (support erubis 2.5+)
4. puzzle_generator, included since 0.0.8

== SYNOPSIS:

please see unit test for all examples.

    $ ludy test # run all ludy tests
    $ ludy      # see all tasks related to ludy

 please don't run any task about release... contact me first
 if you would like to make changes into official ludy release.

    require 'ludy/all'        # for all ludy things
    require 'ludy/kernel'     # for all kernel methods
    require 'ludy/tasks'      # for all ludy tasks
    require 'ludy/proc/curry' # for proc's method curry

 you can make any change and then $ ludy gem:install on your local machine.
 below is some example extracted from unit test.

curry:
  require 'ludy/proc/curry'
  assert_equal 29, :+.to_proc.curry[18][11]

bind:
  require 'ludy/proc/bind'
  assert_equal [9,8,7], ([1,2,3].map &(lambda{|lhs, rhs| lhs-rhs}.bind 10, :_1))

defun:
  require 'ludy/kernel/defun'
  defun :fact, 0 do |n|
    1
  end

  defun :fact, Integer do |n|
    n * fact(n-1)
  end

  assert_equal 3628800, fact(10)

  defun :f, Integer do |n| 1; end
  defun :f, String do |n| '2'; end
  defun(:f, Integer, Integer) do |n,g| 3; end

  assert_equal 1, f(10)
  assert_equal '2', f('')
  assert_equal 3, f(1,1)
  assert_raise NoMethodError do f('1', 2); end

lazy:
  require 'ludy/lazy'
  Y = lambda{|f|
    lambda{|x| lazy{f[x[x]]} }[lambda{|x| lazy{f[x[x]]} }]
  }

y_combinator:
  require 'ludy/y_combinator'
  fact = Y[lambda{|this|
    lambda{|n| n==1 ? 1 : n*this[n-1]}
  }]
  assert_equal(3628800, fact[10])

paginator:
  pager = Ludy::RailsPaginator.new(Topic)
  pager = Ludy::ArrayPaginator.new(TestPaginator.data)
  # or the most flexible paginator:
  pager = Ludy::Paginator.new(
  lambda{ |offset, per_page|
    # if for rails,
    # Data.find :all, :offset => offset, :limit => per_page
    TestPaginator.data[offset, per_page]
  }, lambda{
    # if for rails,
    # Data.count
    TestPaginator.data.size
  })
  pager.per_page = 10

  pager.page(1)
  pager[1] # same as above
  pager.page(2).next.prev.each{|e| e} # you can enumerate
  pager[3].map{|e| e*2}
  pager.size # number of pages
  pager.inject(0){|r, i| r += i.inject &:+ } # total sum of all data

ludy tasks:


header_guard:
  require 'ludy/tasks/erb_cpp/header_guard'
  Project.name = 'header_sample' # remember to set project name

  # in utils/SimpleTest.hpp.erb
  <% header_guard do %>
  class C;
  <% end %>

  # run preprocessing task
  $ rake preprocessing

  # produce:
  #ifndef _HEADER_SAMPLE_UTILS_SIMPLETEST_
  #define _HEADER_SAMPLE_UTILS_SIMPLETEST_
  class C;
  #endif

attr_builder:
  require 'ludy/tasks/erb_cpp' # it would require all erb_cpp tasks.

  # in MapSetting.hpp.erb
  class MapSetting{
  <%= accessor :int, :frequency %>
  <%= accessor :double, :speed, :damage_factor %>
  <%= reader :int, :width, :height, :size %>
  };

  # run preprocessing task
  $ rake preprocessing

  # produce:
  class MapSetting{
  public:
      int frequency() const{ return frequency_; }
  public:
      MapSetting& frequency(int const& new_frequency){ frequency_ = new_frequency; return *this; }
  private:
      int frequency_;

  public:
      double speed() const{ return speed_; }
      double damage_factor() const{ return damage_factor_; }
  public:
      MapSetting& speed(double const& new_speed){ speed_ = new_speed; return *this; }
      MapSetting& damage_factor(double const& new_damage_factor){ damage_factor_ = new_damage_factor; return *this; }
  private:
      double speed_, damage_factor_;

  public:
      int width() const{ return width_; }
      int height() const{ return height_; }
      int size() const{ return size_; }
  private:
      int width_, height_, size_;
  };

template_forward_parameters:
  require 'ludy/tasks/erb_cpp/template_forward_parameters'

  # in test.hpp.erb
  <% for_template_parameters_within(1..5, []){ |args_list| %>
      template <%= template_parameters args_list %>
      static element_type create(<%= forward_parameters args_list %>){
          return element_type(SPool::Instance().construct(<%= arguments args_list %>), Deleter());
      }
  <% } %>

  # run preprocessing task
  $ rake preprocess

  # one of the produce: (can't list all...)
  template <class T0, class T1, class T2, class T3>
  static element_type create(T0 const& a, T1 const& b, T2 & c, T3 const& d){
      return element_type(SPool::Instance().construct(a, b, c, d), Deleter());
  }

== REQUIREMENTS:

* ruby 1.8/1.9 (1.9 is prefered...)
* rake in some features
* erb in task preprocess:erb
* gem erubis if you are using preprocess:erubis
* gem facets is recommended if you are using puzzle_generator
* gem ZenTest if you are running multiruby.sh in test

== INSTALL:

* sudo gem install ludy

== LICENSE:

Apache License 2.0

Copyright (c) 2008, Lin Jen-Shin (godfat)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library, especially for functional programming.

Resources

License

Stars

Watchers

Forks

Packages

No packages published