Javaã«variantåãå®è£ ãã
æè¿Hadoopã使ãããã«5ã6å¹´ã¶ãã«Javaãããã£ã¦ãã¾ãã
ããã§ãã¡ãã£ã¨ã°ããèããããããã§ãã
ä¾ãã°ãããã¡ãªä¾é¡ãæããã¨ã
["google", "æ¤ç´¢","éçº"]ã®ãããªã¿ã°(æåå)ã®ãªã¹ã(ã§ãé åã§ããªãã§ããã)ãåãåã£ã¦
[ {tag=>"google", enc=>'google'}, {tag=>"æ¤ç´¢", enc=>'%E6%A4%9C%E7%B4%A2'}, {tag=>"éçº", enc=>'%E9%96%8B%E7%99%BA'} ]ã®ãããªããã·ã¥ãã¼ãã«ã®ãªã¹ãã«å¤æããªããã
ãã ããã¼ã»ã³ãã¨ã³ã³ã¼ãã£ã³ã°ãè¡ãé¢æ°(ã§ãã¡ã½ããã§ããªãã§ããã) uri_encodingã¯ä¸ãããã¦ãããã®ã¨ããã
ãããªãã¨ãWebã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãããããããªãã§ããã
ãã§ãå®éPerlãªããã§ã¯çµæ§ç°¡åã«æ¸ãã¦
#my @tags = ("google", "æ¤ç´¢","éçº"); ã¯ã¢ãã«ã¨ãããåå¾ my @ret = map{ { tag=>$_,enc=>uri_encoding($_) } } @tags;
ã¾ããããªæããããªãã§ããã
ãããJavaã§æ¸ãã¨ãããªããªãã¾ãã
//List<String> tags; ã®ä¸èº«ã¯ã¢ãã«ã¨ãããåå¾ List<Map<String,String>> result = new LinkedList<Map<String,String>>(); Iterator<String> i = tags.iterator(); while(i.hasNext()){ String tag = i.next(); Map<String,String> m = new HashMap<String,String>(); m.put("tag", tag); m.put("enc", uri_encode(tag)); result.add(m); }
ã¹ãã³ã®ã¾ã¾çã¾ããã¯ã½ãã«ããããï¼ãããã¨ãåªåãã¦ãããªã£ãã®ãï¼ åã6å¹´ã¶ãã«Javaãæ¸ãããã§ãã¾ãæ¸ãæ¹ããããªããããããªåé·ãªãã§ããããã
ã§ãã
ãããªã«ãã»ã»ï¼ï¼
ãããªã«ãè¦ããã®ãªãã°åãªã©ããã¬ï¼ï¼
ã¨ãæé»é¢ã«è½ã¡ããã«ãªã£ã¦ãã¾ãã¾ããã
ãã以å¤ã«ãWebã¢ããªã±ã¼ã·ã§ã³ãªããã ã¨ã¯ã¨ãªã¼ãå ¨é¨æååã§æ¥ããã©ã妥å½æ§æ¤è¨¼ã®ããã«intã«å¤æãã¦intã¨æ¯è¼ã¨ãããã®ãJavaã ã¨ã¯ã½é¢åã§ããï¼ä¾ãã°ä»è¡¨ç¤ºãã¦ãã0件ç®ãã¼ã¸ã®æ¬¡ã®100件ã表示ããããã«offset=100ã¨ããGETãã©ã¡ã¿ã§åãåãã¨ãããããå ´åãããããã®ã¯ãã¬ã¼ã ã¯ã¼ã¯ãå¸åãã¦ããããã§ããããï¼)
ããã§ãJavaã®ãªãããªã¨ãã¦ããªã¢ã³ãåãä½ã£ã¦ã¿ã¾ããã
ã©ããWebã¢ããªã±ã¼ã·ã§ã³ã®ã³ã³ããã¼ã©ã¨ãHadoopã§ãããããªããã¹ãå¦çã ã¨ã使ãåã¯ããããæååãæ´æ°ãæ¥ä»ããªã¹ããããã·ã¥ããã³ãããã®çµã¿åããã¨ç¸äºå¤æãªããã§ãã
ããããç°¡åãªãã¨ã¯ç°¡åã«æ¸ããããã«ãããããå ¨é¨ã¤ã£ãããvarã¯ã©ã¹ãä½ã£ã¦ãä¾ãã°ãã£ãã®åé¡ãªããããªé¢¨ã«æ¸ããããã«ããã®ãã´ã¼ã«ã§ãã(lambdaã¯ãã¡ã³ã¯ã¿ã®ããã®æ½è±¡ã¯ã©ã¹ã$ã¯mapã¨ãã®é¢æ°çãªã¯ã©ã¹ã¡ã½ãããå ¥ãã¦ããããã®ã¯ã©ã¹ã)
var tags = $.list("Google", "æ¤ç´¢ã¨ã³ã¸ã³", "éçº"); lambda tag2hash = new lambda(){var f(var tag){ return $.hash( "tag", tag, "enc", uri_encode(tag) ); }}; var result = $.map(tag2hash, tags);
ãã§ãæ¸ããã®ãã³ã¬(var.java)ã
1ãã¡ã¤ã«ã«ã¾ã¨ããããã«ç¡çããpublicãããªãå é¨ã¯ã©ã¹ã大éã«ä½¿ã£ã¦ã¾ããæ°ã«ããªãã§ãã ããã
varã¯ã©ã¹(ã¯ã©ã¹åã大æåã§å§ã¾ããªããã©åå¼ãã¦ãï½)ã«mainã¤ãã¦ã¾ãããããJavaã½ã¼ã¹ã«ã¯è¦ãã¾ããï½
Javaã§hackããã¨ããããJavaãFxxkãã¦ãæ°åã«ãªãã¾ããã
public class var { public static void main(String[] args){ lambda square = new lambda(){var f(var v){ return new $(v.i() * v.i()); }}; lambda say = new lambda(){var f(var v){ System.out.println(v.display()); return var.NIL; }}; //æåå var name = new $("James"); say.apply(name); //æååã¨æ°å¤ã®æ··åãªã¹ã var ls = $.list(1, "2", 3, 4, 5); //ãªã¹ãã®åè¦ç´ ã2ä¹ãããªã¹ããè¿ã(æ°å¤ã¯èªåå¤æ) say.apply($.map(square, ls)); //cdr(ç¬) say.apply(ls.cdr()); //å ¥ãåã®ããã·ã¥ãã¼ãã« var hash = $.hash( "John", $.hash("sex", "male", "age", 20), "Eva", $.hash("sex", "female", "age", "unknown"), "Abe", $.hash("sex", "unknown", "age", "25") ); say.apply(hash.get("John").get("sex")); say.apply(hash.get("Nobita").get("sex")); say.apply(hash.keys()); say.apply(hash); } }
ãã®mainãå®è¡ããã¨ãããªæãã
$ java variant/var
"James"
(1 4 9 16 25)
("2" 3 4 5)
"male"
nil
("John" "Abe" "Eva")
(("John" => (("age" => 20)("sex" => "male")))("Abe" => (("age" => "25")("sex" => "unknown")))("Eva" => (("age" => "unknown")("sex" => "female"))))