Live data from Hacker News

... because Ruby isn't terse enough yet

weblog.raganwald.com

1–10 of 28 posts

Re: ... because Ruby isn't terse enough yet

#2
In 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.)

Re: ... because Ruby isn't terse enough yet

#3
post #2

In 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!"

Re: ... because Ruby isn't terse enough yet

#4
post #3
post #2

In 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!"

The Erlang version is unnecessarily verbose (and also semantically different) because it uses 2 processes. It can be rewritten as

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

#7
post #2

In 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.)

This is shorter than both the Ruby and the Arc versions:

{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

#8
post #3
post #2

In 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!"

In ML you can get a similar terseness to that of Haskell, but with support for imperative programming. If we allow the increment function to be predefined (as the Arc example does):

 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

#9

The Perl Golf anti-pattern.

I tend to agree with you. It's obvious to me that the following code evaluates to 6:

  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

#10
post #2

In 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.)

For comparison, the original Ruby version:

  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?

Post reply on HN