[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Need examples comparing Ruby to Python
From: Tobias Nurmiranta <spyck () lysator ! liu ! se>
Date: 2004-02-24 22:37:34
Message-ID: Pine.GSO.4.51L2.0402242316170.25026 () nazgul ! lysator ! liu ! se
[Download RAW message or body]
Hi,
On Wed, 25 Feb 2004, Hal Fulton wrote:
> If I do:
>
> def func(word)
> consonants = word.gsub(/[aeiou]/,"")
> puts consonants
> end
>
> words.each {|word| func(word) }
>
> then I have still used a block, one that happens to call a function
> (with a name) that will only be used once.
A difference between ruby and python is that functions can easily be
passed as arguments in python. For example a function that returns the
composition of two functions applied to a value. (An artificial example :)
def compose(f, g, x):
return f(g(x))
But then this is even more nicer i scheme.
(defun (compose f g)
(lambda (x) (f (g x))) ;; returns a function, that can be applied later.
((compose 1+ 1+) 1) => 3
In ruby you have to create a Method instance first, and then pass it as an
argument. (newbie warning. :)
, Tobias
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic