... because Ruby isn't terse enough yet
weblog.raganwald.com
... because Ruby isn't terse enough yet
1–10 of 28 posts
Re: ... because Ruby isn't terse enough yet
#2 foo = 'n -> x -> n += x'.to_proc
f = foo[4]
f[2] # => 6
f[2] # => 8
(This would be even terser: foo = &'n -> x -> n += x'
but the ampersand syntax is only allowed after a method call.)Re: ... because Ruby isn't terse enough yet
#3In Paul Graham's Accumulator Generator comparison ( http://www.paulgraham.com/accgen.html ) Ruby is now terser than any language except Arc. foo = 'n -> x -> n += x'.to_proc f = foo[4] f[2] # => 6 f[2] # => 8 (This would be even terser: foo = &'n -> x -> n += x' but the ampersand syntax is only allowed after a method call.)
putStrLn "Don't do that, you nimwit!"Re: ... because Ruby isn't terse enough yet
#4In Paul Graham's Accumulator Generator comparison ( http://www.paulgraham.com/accgen.html ) Ruby is now terser than any language except Arc. foo = 'n -> x -> n += x'.to_proc f = foo[4] f[2] # => 6 f[2] # => 8 (This would be even terser: foo = &'n -> x -> n += x' but the ampersand syntax is only allowed after a method call.)
I think Haskell is overall terser than Ruby. The trouble with the accgen test is that it's imperative, and Haskell isn't meant to be. Here's the Haskell implementation that I would submit: putStrLn "Don't do that, you nimwit!"
Foo = fun(N) -> put(var, N), fun(X) -> V = get(var) + X, put(var, V), V end end.
It's not as concise as Ruby or Arc, but it's a one liner. However, similar to Haskell, this style of programming is discouraged in Erlang.
Re: ... because Ruby isn't terse enough yet
#5Re: ... because Ruby isn't terse enough yet
#6Re: ... because Ruby isn't terse enough yet
#7In Paul Graham's Accumulator Generator comparison ( http://www.paulgraham.com/accgen.html ) Ruby is now terser than any language except Arc. foo = 'n -> x -> n += x'.to_proc f = foo[4] f[2] # => 6 f[2] # => 8 (This would be even terser: foo = &'n -> x -> n += x' but the ampersand syntax is only allowed after a method call.)
{x set y+eval x}
It's in q, a verbose version of a language called k.
Applying it to a symbol/variable `n will give you a functional projection you can apply to any i.
Re: ... because Ruby isn't terse enough yet
#8In Paul Graham's Accumulator Generator comparison ( http://www.paulgraham.com/accgen.html ) Ruby is now terser than any language except Arc. foo = 'n -> x -> n += x'.to_proc f = foo[4] f[2] # => 6 f[2] # => 8 (This would be even terser: foo = &'n -> x -> n += x' but the ampersand syntax is only allowed after a method call.)
I think Haskell is overall terser than Ruby. The trouble with the accgen test is that it's imperative, and Haskell isn't meant to be. Here's the Haskell implementation that I would submit: putStrLn "Don't do that, you nimwit!"
let inc a b = a := !a +/ b; !a
then foo becomes: let foo n = inc (ref n)
or, with the help of the composition operator: let (Re: ... because Ruby isn't terse enough yet
#9The Perl Golf anti-pattern.
r = 2
foo = lambda {|x| x * r}
foo.call(3)
And it's obvious to me that the following code raises an ArgumentError: foo = lambda {|x,r| x * r}
foo.call(3)
But what does this do? r = 2
bar = 'x*r'.to_proc
bar(3)
Do I get the 6, or do I get the ArgumentError? UPDATE: I presume the answer is "ArgumentError" (because the alternative appears to be positively evil), and that what I really need to do is this:
r = 2
bar = 'x -> x*r'.to_proc
bar(3)
Why is this such an improvement over lambda? Couldn't these folks just fix lambda (e.g. to remove the need for that annoying .call method every time I use the result) rather than deciding that every Ruby programmer needs to learn yet another argument syntax?
Re: ... because Ruby isn't terse enough yet
#10In Paul Graham's Accumulator Generator comparison ( http://www.paulgraham.com/accgen.html ) Ruby is now terser than any language except Arc. foo = 'n -> x -> n += x'.to_proc f = foo[4] f[2] # => 6 f[2] # => 8 (This would be even terser: foo = &'n -> x -> n += x' but the ampersand syntax is only allowed after a method call.)
def foo (n)
lambda {|i| n += i } end
It's five characters longer, but approximately 350% more readable. Of course, a lot of that is because I'm more familiar with standard Ruby syntax than I am with this hack... but doesn't that tend to prove my point?