# Ruby Murray - Sub::Curry on Ruby Acid

**URL:** <https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296>\
**Category:** Ruby\
**Created:** [February 21, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296 "2006-02-21T16:11:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/1 "2006-02-21T16:11:47Z")

</div>

Ruby Murray, a Ruby port of Perl’s Sub::Curry (with added Ruby  
goodness), is now available in it’s first 0.1.2 release.

Ruby Murray allows block arguments to be supplied prior to calling (to  
be ‘curried’) and also supports a range of features that allow arguments  
to be populated in arbitrary order and with complex processing.

Out now: [http://rubymurray.rubyforge.org/](http://rubymurray.rubyforge.org/) or ‘gem install rubymurray’

(yes, it’s my solution to quiz 64, I thought it might be nice to release  
it but only just got round to it).

---

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/2 "2006-02-21T18:14:31Z")

</div>

cool naming, nice functionality, easy using.  
AFAIK this is a instantiation of the Design Pattern called “Command” by  
the Gang of Four.  
i can not imagine a problem where i needed such flexible argument list.  
can anyone provide a motivation example in ruby?  
i’d suggest to add a small sample of usage to the docs.  
– henon

---

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/3 "2006-02-21T18:29:47Z")

</div>

On 2006-02-21 12:08:22 -0500, “henon” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> cool naming, nice functionality, easy using.  
> AFAIK this is a instantiation of the Design Pattern called “Command” by  
> the Gang of Four.  
> i can not imagine a problem where i needed such flexible argument list.  
> can anyone provide a motivation example in ruby?  
> i’d suggest to add a small sample of usage to the docs.  
> – henon

I’m not entirely sure where you’d use this sort of feature either, but  
for the uninformed (such as myself)…

1. A snazzy article on Currying in Wikipedia \>\>  
[Currying - Wikipedia](http://en.wikipedia.org/wiki/Currying)
2. The “Command” design pattern \>\>  
[http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/command.htm](http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/command.htm)

James

---

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/4 "2006-02-21T19:15:59Z")

</div>

> Oh, I never said it was _useful_ 🙂  
> in fact it is very useful for most elegantly implementing undo/redo  
> commands. i was just curious about other applications.

thank’s for the link to the cookbook. i did only find the link to the  
perl version at first.  
– Henon

---

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/5 "2006-02-21T18:41:56Z")

</div>

On Wed, 2006-02-22 at 02:13 +0900, henon wrote:

> cool naming, nice functionality, easy using.  
> AFAIK this is a instantiation of the Design Pattern called “Command” by  
> the Gang of Four.  
> i can not imagine a problem where i needed such flexible argument list.  
> can anyone provide a motivation example in ruby?  
> i’d suggest to add a small sample of usage to the docs.  
> – henon

Oh, I never said it was _useful_ 🙂

Actually, I don’t think there’s anything in Ruby that can’t be done  
(better) some other way, but currying is one of those higher-order  
things that every (decent) language should have ;).

Most of the examples I could contrive are in the docs - not sure if it’s  
linked prominently enough but did you see  
[http://rubymurray.rubyforge.org/files/doc/currybook\_rdoc.html](http://rubymurray.rubyforge.org/files/doc/currybook_rdoc.html)  
?

James Edward G. II also came up with a good example in the quiz  
summary, based on his LazySpice spice (included in this release):

```
    # Lazy Evaluation meets Currying...
    class LazySpice < Curry::SpiceArg
      def initialize( &promise )
        super("LAZYSPICE")

        @promise = promise
      end

      def spice_arg( args ) # called to provide the missing 

```

argument  
[@promise.call]  
end  
end

```
    logger = lambda do |time, message|
      puts "[#{time.strftime('%I:%M:%S %p %m/%d/%y')}] #{message}"
    end

    log_now = logger.curry(LazySpice.new { Time.now })

    log_now["First Message."] # => [12:47:53 PM 02/01/06] First 

```

Message.  
sleep 3  
log\_now[“Second Message.”] # =\> [12:47:56 PM 02/01/06] Second  
Message.

Again, not something that’s difficult to do by other means (default  
argument values for example) but, well, there you go.

---

<div class="post-metadata">

**Author:** ![ross\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@ross\_b](https://www.ruby-forum.com/u/ross_b)\
**Post date:** [February 21, 2006, 7:55pm UTC](https://www.ruby-forum.com/t/ruby-murray-sub-curry-on-ruby-acid/71296/6 "2006-02-21T19:55:47Z")

</div>

On Wed, 2006-02-22 at 03:13 +0900, henon wrote:

> > Oh, I never said it was _useful_ 🙂  
> > in fact it is very useful for most elegantly implementing undo/redo  
> > commands. i was just curious about other applications.

Ahh, well, looks like I spoke too soon there.

Thanks for your kind comments 🙂
