Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Alternatives to sed + awk



On 11 March 2011 13:58, Stephen J. Turnbull <stephenjturnbull@example.com> wrote:

> On Fri, Mar 11, 2011 at 3:52 PM, Josh Glover <jmglov@example.com> wrote:
>
>> I do as well in Python and C (heh heh); it just turns out that you
>> never need them in Ruby. I actually don't use functions at all in my
>> Ruby code.
>
> I meant to include "methods", not just bare functions.  So, you don't
> use functions like, say, sin()?  Yow!  (pi/4).sin, is that it? :-)

Math.sin(Math.pi / 4)

http://www.ruby-doc.org/core/classes/Math.html

> def logistic(x)
>    return 3.82*x*(1-x)
>
> simple_chaos = (logistic,0.5)
>
> while True:
>    print (simple_chaos())

logistic = Proc.new {|x| 3.82 * x * (1 - x) }
simple_chaos = Proc.new { logistic 0.5 }
puts simple_chaos.call while true

> Au contraire, it's surely makes sense to pass around a bound method
> (ie, a method which knows which object it's attached to); a special case
> of a closure.

It does, and I imagine Ruby provides a way to do that. I just can't
think of a time when *I* needed it. I'd probably just pass a Proc that
makes the method call; an actual closure. :)

Cheers,
Josh

PS: Sorry about the dup, Steve. Stupid Gmail respecting your Reply-to. ;)


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links