[Haskell-beginners] Haskell as a useful practical 'tool' for intelligent non-programmers
Michael Orlitzky
michael at orlitzky.com
Sun Apr 29 05:16:39 CEST 2012
On 04/28/2012 10:37 PM, Lyndon Maydwell wrote:
> Your first example is not behaving how you think it is...
>
>
> ruby-1.9.2-p0 :012 > def foo
> ruby-1.9.2-p0 :013?> puts "foo"
> ruby-1.9.2-p0 :014?> end
> => nil
> ruby-1.9.2-p0 :015 > def call_arg(f)
> ruby-1.9.2-p0 :016?> puts "calling"
> ruby-1.9.2-p0 :017?> f
> ruby-1.9.2-p0 :018?> end
> => nil
> ruby-1.9.2-p0 :019 > call_arg(foo)
> foo
> calling
> => nil
>
> Note that "foo" is printed before "calling".
>
Indeed, I tried to make the example cute and botched it. This should be
less screwupy (you have to desugar the 'def...' to make it work properly).
foo = Proc.new { puts "foo" }
bar = lambda { puts "bar" }
def baz
puts "baz"
end
def call_arg(f)
puts "before call"
f.call()
puts "after call"
end
call_arg(foo)
puts ""
call_arg(bar)
puts ""
call_arg(method(:baz))
More information about the Beginners
mailing list