News for hackers. Stuff that matters.
Re:Typesafe raises $14M to commercialize Scala by taligent on Wednesday August 22, 2012 @09:09AM (#4417143)
5th search result for Closure in Google:

http://freegeek.in/blog/2011/06/10-clojure-one-liners/

Tell me that is not Perl all over again.

Re:Typesafe raises $14M to commercialize Scala by espeed on Wednesday August 22, 2012 @09:29AM (#4417209)
Clojure is on the opposite end of the spectrum from Perl.
Re:Typesafe raises $14M to commercialize Scala by jonathansizz on Wednesday August 22, 2012 @03:08PM (#4419008)
You mean Clojure is unsuitable for writing quick scripts that get things done with the minimum of fuss?

The Perl one-liners that actually resemble line-noise get far more done than any of the examples given above. Perl one-liners that do the same as the above examples are actually quite legible.

Re:Typesafe raises $14M to commercialize Scala by draegtun on Wednesday August 22, 2012 @10:56AM (#4417635)
They look fine to me and it also look good written in Perl :)

  use List::Util qw(sum max min);

  # 1
  map { $_ * 2 } 1..10;

  # 2
  sum 1..1000;

  # 3
  my @wordlist = ("scala", "akka", "play framework", "sbt", "typesafe");
  my $tweet = "This is an example tweet talking about scala and sbt.";
  grep { $tweet =~ m/\b$_\b/ } @wordlist;

  # 4
  my $file_text = do { local $/ = undef; open my $fh, '<', 'data.txt'; <$fh> };
  chomp( my @file_lines = do { open my $fh, '<', 'data.txt'; <$fh> } );

  # 5
  say "Happy Birthday " . ($_ == 3 ? "dear Barry" : "to You") for 1..4;

  # 6
  my ($passed, $failed) = do { 
    my @p; \@p, [map { $_ > 60 ? push(@p, $_) && () : $_ } (49,58,76,82,88,90)]
  };

  # 8
  min(14, 35, -7, 46, 98);
  max(14, 35, -7, 46, 98);
Re:Typesafe raises $14M to commercialize Scala by xyzzyz on Wednesday August 22, 2012 @11:20AM (#4417774)

  my $file_text = do { local $/ = undef; open my $fh, '<', 'data.txt'; <$fh> };
I have absolutely no idea what this line does. local? undef? '<'?, <$fh>? This is how you read a file in Perl?
Re:Typesafe raises $14M to commercialize Scala by draegtun on Wednesday August 22, 2012 @11:24AM (#4417803)
> This is how you read a file in Perl?

Nope. I use Path::Class from CPAN...

  use Path::Class 'file';
  my $file_text = file('data.txt')->slurp;
Re:Typesafe raises $14M to commercialize Scala by chromatic on Wednesday August 22, 2012 @12:49PM (#4418270)
I have absolutely no idea what this line does.

If you don't know Perl, why should you expect to? I didn't know that #(...) represented a lambda in Scala until a moment ago.

Re:Typesafe raises $14M to commercialize Scala by AnswerAndForget on Wednesday August 22, 2012 @01:11PM (#4418377)
'Knowing Perl' is a rather hard thing to do when the list of completely ad-hoc implicit variables and hidden context-sensitive surprises is seemingly endless.
Re:Typesafe raises $14M to commercialize Scala by chromatic on Wednesday August 22, 2012 @01:27PM (#4418457)
Your grasp of English seems to include subject-verb number agreement, and I suspect you can handle pronouns. You'd do just fine with Perl.

Yes, lots of tutorials explain it badly, and yes, lots of people say "Why should a programming language take cues from natural language?", but implicit variables and context are concepts that primary school children have mastered. They're not that difficult.

Re:Typesafe raises $14M to commercialize Scala by AnswerAndForget on Wednesday August 22, 2012 @02:40PM (#4418878)
Yeah, that was not my point. These aren't but idiosyncrasies of Perl's design, and to model itself on constructs which evolved without direction and which take years to master, just to save a keystroke or two once in a blue moon, is a rather questionable road to take.

Seriously, in what other language don't you ever finish discovering what's on the default namespace, what side-effects any given statement, or hell, expression has, or which syntactic forms are supported, and on and on?

Well, PHP, but we know what the connotations of that are.

And by the way, I'm doing rather 'fine' in Perl, if not for the ever-present worrying about type mismatches (particularly arrays), the frustration of how dirty many operations are (unless you are using a recent version, regex substitution must mutate a variable), the laboriousness of the stock error handling mechanisms (make your own stack trace!) and so on.

Re:Typesafe raises $14M to commercialize Scala by Inufu on Wednesday August 22, 2012 @01:29PM (#4418469)
It represents a lambda in Clojure.
Re:Typesafe raises $14M to commercialize Scala by chromatic on Wednesday August 22, 2012 @01:44PM (#4418559)
You're right. I typed Clojure the first time, then for some reason uncorrected it.
Re:Typesafe raises $14M to commercialize Scala by batista on Wednesday August 22, 2012 @09:24AM (#4417194)
It's not Perl all over again. Have you even _read_ those one-liners?

Those are neither line-noise, nor fickle one-line imperative solutions.

On the contrary, they are elegant and easy to read --you just have to understand the basics of functional programming, map, reduce, filter and the like (which, in themselves are trivial concepts).

Stuff like those in the article:

(pmap process-line lines)

(dotimes [n 4] (println "Happy Birthday " (if (= n 2) "dear Rich" "to You")))

(reduce max [14 35 -7 46 98])

(def file-text (slurp "data.txt"))

(partition-by #(> % 60) [49 58 76 82 88 90])

(clojure.xml/parse "http://search.twitter.com/search.atom?&q=clojure)

are so easy and clutter-free that what I cannot even begin to comprehend how someone would accuse them of the bad readability that characterises the "Perl one-liner".

Re:Typesafe raises $14M to commercialize Scala by Chris_Newton on Wednesday August 22, 2012 @10:13AM (#4417412)
To be fair, comparing something like this:

    (partition-by #(> % 60) [49 58 76 82 88 90])
to so-called line noise code seems reasonable enough. As with Perl, if you immediately know what all the punctuation means and what the underlying structure of the language is, it’s concise, but if you don’t, it’s quite a mess of random-looking symbols.

For comparison, here’s a Haskell version, which in this case has a more intuitive syntax, IMHO:

    filter (>60) [49, 58, 76, 82, 88, 90]
And here’s a version in Scala, with a more explicit function value:

    List(49, 58, 76, 82, 88, 90).filter(n => n > 60)
Re:Typesafe raises $14M to commercialize Scala by kenko on Wednesday August 22, 2012 @12:38PM (#4418220)
Really? There's only two bits of punctuation there, and they don't take much to explain: #(...) is an anonymous function; % is the argument to that function. (I'm not counting > because ... it's just the greater-than sign.)

The Haskell version doesn't actually do the same thing. The Haskell returns [76, 82, 88, 90]; the Clojure returns ((49 58) (76 82 88 90))---it groups the input according to the result of the function, it doesn't just filter it.

Re:Typesafe raises $14M to commercialize Scala by Chris_Newton on Wednesday August 22, 2012 @01:18PM (#4418410)
It’s not an ideal example of partition-by anyway, because this particular input has all the values where the predicate returns true together. As you have shown, the result in this case is just to divide the list into the values that match the predicate and those that don’t. This is actually what the “partition” function does in some languages, including Haskell and Scala. However, in general, partition-by in Clojure does more than that and is more like a kind of split algorithm, which this example didn’t demonstrate.

In any case, my point here was about syntax, so I used a standard and easily recognisable function in the other languages instead of getting bogged down in trying to reproduce the exact same behaviour. Apologies if this wasn’t clear.

Re:Typesafe raises $14M to commercialize Scala by Dn_Ab on Wednesday August 22, 2012 @12:23PM (#4418150)
I know this is a discussion on syntax but I can't help pointing out that the semantics of paritition-by and filter are very different.
Re:Typesafe raises $14M to commercialize Scala by Chris_Newton on Wednesday August 22, 2012 @12:58PM (#4418311)
True enough, but I figured filter was widely known and partition-by was perhaps a little esoteric. The syntactic argument would be exactly the same if you used an equivalent of partition-by in the other languages.
Re:Typesafe raises $14M to commercialize Scala by wtetzner on Wednesday August 22, 2012 @10:52AM (#4417610)
>(partition-by #(> % 60) [49 58 76 82 88 90])

Yeah, a less noisy way to do it in Clojure would be

(partition-by (partial < 60) [49 58 76 82 88 90])

Re:Typesafe raises $14M to commercialize Scala by swuecho on Wednesday August 22, 2012 @11:47AM (#4417926)
You are right.

in Perl:

grep { $_ > 60 } ( 49, 58, 76, 82, 88, 90)

Re:Typesafe raises $14M to commercialize Scala by etaty on Wednesday August 22, 2012 @12:04PM (#4418027)
Scala : List(49, 58, 76, 82, 88, 90).filter( _ > 60 )
Re:Typesafe raises $14M to commercialize Scala by yarrel on Wednesday August 22, 2012 @09:51AM (#4417312)
I still hate the square brackets and the slashes.

Sorry, hate is such a strong word.

I mean that I still find the language's typographic irregularities hopelessly distracting to the point where I won't touch it with a bargepole.

They compare to perl one liners more than they do to Lisp one-liners due to their greater syntactic cruft.

Re:Typesafe raises $14M to commercialize Scala by pivo on Wednesday August 22, 2012 @11:56AM (#4417972)
I initially disliked the square brakets as well, but I got over it quickly because of the utter happiness I get from writing Clojure code in general.

FYI, the square brackets are not an arbitrary deviation from lisp syntax. Square brackets are Clojure's vector syntax, the use of square brackets in function and macro definitions reflects the fact that they are actually vectors.

Not sure what you meant with your objection to slashes though.