2012-06-29

どのプログラミング言語が最も美しいか

■ C

for( const char *s="12345"; *s; ++s ) if( '2'<*s&&*s<'5' ) printf( "%d", (*s-'0')*2 );

JavaScript

console.log([1,2,3,4,5].filter(function (i){ return (i > 2 && i < 5 ); }).map(function(i){ return 2 * i; }));

Python

print(map(lambda x: x*2, filter(lambda x: x>2 and x<5, [1,2,3,4,5])))

Ruby

puts [1,2,3,4,5].select{|i| i > 2 and i < 5}.map{|i| i*2}

C#

new{}{ 1,2,3,4,5 }.Where(x => 2 < x && x < 5).Select(x => x*2);

Common Lisp

(print (loop for x in '(1 2 3 4 5) if (< 2 x 5) collect (* x 2)))

Haskell

print [x*2| x <-[1,2,3,4,5], x > 2, x < 5]

■ J

  1. :(((>&2)*.(<&5)) a) # a=:1+i.5

■ R

print((function(){x<-c(1,2,3,4,5);x[2<x&x<5]*2})())</p>

Clojure

(print (for [x [1,2,3,4,5] :when (< 2 x 5)] (* x 2)))

Squeak Smalltalk

(1 to: 5) select: [:x | x between: 3 and: 4] thenCollect: [:x | x * 2]

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん