meeting3 log languages

Toshiaki Katayama edited this page Mar 25, 2017 · 2 revisions

オープンバイオ対決 というテーマで考えていたもののうち、「関数/メソッド比較表」の部分の作成を行ってみました。これの元のアイデアは、高林さんのブログ「配列操作の比較表: Ruby, Python, JavaScript, Perl, C++」です。

配列

文字列

スペースがダメダメですがあとで表に直します。orz

文字列           Ruby                            Python                          Perl
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
リテラル         str = "abc"                     str = "abc"                     $str = "abc";
                -------------------------------------------------------------------------------−−−−−-----
                str = %Q[a"bc]                  ???                             $str = qq/a"bc/;
                str = %q[ab'c]                  ???                             $str = q/ab'c/;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
変数展開         str = "a#{var}c"                'abc %s' % (x)                  $str = "a${var}c";
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
つなぐ           x = "abc"; y = "de"             x = "abc"; y = "de"             $x = "abc"; $y = "de";
                str = x + y                     str = x + y                     $str = $x . $y;
------------------------------------------------------------------------------------------−−−−−−−−−−-----
ふやす           str = x * 10                    ???                             $str = $x x 10;
------------------------------------------------------------------------------------------−−−−−−−−−−-----
改行を取る        str.chomp                       ???                             chomp($str);
                -------------------------------------------------------------------------------−−−−−-----
最後の文字        str.chop                                                        chop($str);
                -------------------------------------------------------------------------------−−−−−-----
                rna = dna.dup                   ???                             $rna = $dna;
                str[0..-2]                      str[:-1] (or str[0:-1])         substr($str, 0, -2);
                -----------------------------------------------------------------------------------------
指定の文字       str.chomp("x")                  ???                             ???
------------------------------------------------------------------------------------------−−−−−−−−−−-----
slice           str[m, n]                       ???                             substr($str, $m, $n);
------------------------------------------------------------------------------------------−−−−−−−−−−-----
reverse         rev = str.reverse               ???                             $rev = reverse($str);
------------------------------------------------------------------------------------------−−−−−−−−−−-----
complement      rev.tr("atgc, "tacg")                                           $rev =~ tr/atgc/tacg/;
------------------------------------------------------------------------------------------−−−−−−−−−−-----
置換             rna = dna.gsub("t", "u")        ???                             ???
                -----------------------------------------------------------------------------------------
                rna = dna.dup                   ???                             $rna = $dna;
                rna.gsub!("t", "u")                                             $rna =~ s/t/u/g;
                -------------------------------------------------------------------------------−−−−−-----
                str.sub(">", "> ")                                              ???
                -------------------------------------------------------------------------------−−−−−-----
                str.sub!(/^>/, "> ")                                            $str =~ s/^>/> /;
                -------------------------------------------------------------------------------−−−−−-----
                str.sub!(/^>?S+/) {|x| x.downcase}
------------------------------------------------------------------------------------------−−−−−−−−−−-----
マッチ           str[/re/]
                -----------------------------------------------------------------------------------------
                str =~ /re/                                                     $str =~ /re/;
                -----------------------------------------------------------------------------------------
                s = str[/re/]                                                   $s = /(re)/ for $str;
                                                                                ($s) = $str =~ /(re)/;
------------------------------------------------------------------------------------------−−−−−−−−−−-----
upcase          str.upcase                      ???                             uc($str);
------------------------------------------------------------------------------------------−−−−−−−−−−-----
downcase        str.downcase                    ???                             lc($str);
------------------------------------------------------------------------------------------−−−−−−−−−−-----

ハッシュ

Hash            Ruby                                    Python                          Perl
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
リテラル         h = {}                          h = {}                          %h = ();
                -------------------------------------------------------------------------------−−−−−-----
                h = {"a" => 1, "b" => 2}        h = {a:1, b:2}                  %h = (a => 1, b => 2);
                -------------------------------------------------------------------------------−−−−−-----
                                                                                @h{"a", "b"} = (1, 2);
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
初期値           h = Hash.new(0)
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
値の代入         h["a"] = 1                      h["a"] = 1                      $h{a} = 1;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
取り出し         v = h["a"]                      v = h["a"]                      $v = $h{a};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
オブジェクト      a = [1, 2, 3]                   a = [1, 2, 3]                   @a = (1, 2, 3);
                b = [4, 5]                      b = [4, 5]                      @b = (4, 5);
                h[a1] = b2                      ???                             $h{?@a} = ?@a2;
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
キーだけ         h.keys                          h.keys()                        keys %h
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
値だけ           h.values                        h.values()                      values %h
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
順に処理         h.each do |k, v|                for v h.values():               for (keys %h) {
                  sum += v                        sum += v                        ???
                end                                                             }
                -------------------------------------------------------------------------------−−−−−-----
                h.inject(0) {|sum, k, v| sum+= v}
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
ソート           h.sort.each do |k, v|           ???                             for (sort keys %h) {
                  puts "#{k} -> #{v}"                                             ???
                end                                                             }
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
値でソート        h.sort_by{|x| x[1]}.each {}     ???                             ???
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
逆順             h.sort.reverse.each {}          ???                             for (sort $h{$a} <=> $h{b} keys %h) {}
                h.sort{|x,y| y[1] <=> x[1]}
−−−−−−−−−−−−−−−−-−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
値を消去         h.delete(k)                     ???                             delete $h{k};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−-----
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.