[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6619] closures (rb vs lisp?)

From: peter.wood@...
Date: 2000-11-29 11:16:55 UTC
List: ruby-talk #6619
Hi

I am trying to figure out how to do closures in Ruby. In CL I can do
this :
-------------------------------------------------------
(defun shop-list (the-list)
  #'(lambda (action item)
      (case action
	(buy (setf the-list (adjoin item the-list)))
	(cancel (setf the-list (remove item the-list)))
	(see the-list))))

---------------------------------------------------------
And use it like this:

* (setf week1 (shop-list ()))
=>
#<Interpreted Function "LAMBDA (THE-LIST)" {4813D789}>
* (funcall week1 'buy 'cornflakes)
=>
(CORNFLAKES)
* (funcall week1 'buy 'potatoes)
=>
(POTATOES CORNFLAKES)
* (setf week2 (shop-list ()))
=>#<Interpreted Function "LAMBDA (THE-LIST)" {481487C1}>
* (funcall week2 'buy 'beer)
=>
(BEER)

I have just started "Programming Ruby", and I know the answer is there
somewhere.  I need to use "blocks" and "proc".  The Array class has
all the methods I need for the list (uniq! etc) I just don't know how
to set it out.  Thanks in advance.

Peter

In This Thread

Prev Next