ã¯ããã«
æ°æ¥åãç§ã¯ãã°ãããClojure YPãçºèŠããŸãããããã¯ããã«ãã¹ã¬ããããŒã«ã®é©åãªå®è£ ãjvmãã€ãã³ãŒããžã®ã³ã³ãã€ã«ãjavaã©ã€ãã©ãªã®äœ¿çšãjitã³ã³ãã€ã«ãªã©ã®æ©èœãåãããææ°ã®Lispæ¹èšã®1ã€ã§ãã ããšãã°ã ãã㧠Clojureã«ã€ããŠèªãããšãã§ããŸã ã ãã ãããã®èšäºã§ã¯ã¡ã¿ããã°ã©ãã³ã°ã«ã€ããŠèª¬æããŸãã Lispã¯ããã®äžã®ããŒã¿ãšã³ãŒããåäžã«ãªãããã«èšèšãããŠããŸãã é¢æ°å®£èšããã¯ããé¢æ°åŒã³åºãããã¯ãå±é-Lispã§ã¯ããããã¯ãã¹ãŠåãªããªã¹ãã§ããããã¹ããããŠããå¯èœæ§ããããŸãã
(defn square [foo] (* foo foo)) (defmacro show-it [foo] `(println ~foo))
ãã®ãããªã³ãŒããšããŒã¿ã®çµ±äžã¯ãã¡ã¿ããã°ã©ãã³ã°ã®åŒ·åãªæ©äŒãæäŸããŸããã³ãŒããæžãã³ãŒããã³ãŒããæžãã³ãŒããã³ãŒããæžãã³ãŒããªã©ã§ãã -ããã¯ãLispã§ã®ããã°ã©ãã³ã°ã®æãäžè¬çãªã±ãŒã¹ã§ãã ã³ã³ãã€ã«æã«ãèšèªã®ãã¹ãŠã®æ©èœã«å®å šã«ã¢ã¯ã»ã¹ã§ããŸããé¢æ°ãåŒã³åºãããããã¯ããå±éãããã§ããŸãã ããšãã°ããã®ãã¯ããå®çŸ©ããå ŽåïŒ
(defmacro recurs [foo bar] (println "hello from compiler" foo) (case (<= bar 0) true `(defn foo [] ~foo) false `(recurs ~(- foo 1) ~(- bar 1))))
ãããŠãã³ãŒãã«åŒãæ¿å ¥ããŸã
(recurs 2 1)
次ã«ãã³ã³ãã€ã«äžã«è¡šç€ºãããŸã
hello from compiler 2 hello from compiler 1
ãããŠããã®å Žåã®ãã¯ãã¯ãã¢ãªãã£1ã®é¢æ°fooã®å®çŸ©ã«å±éãããå€1ãè¿ããŸãã
(def user/foo (clojure.core/fn ([] 1)))
ïŒ3 1ãç¹°ãè¿ãïŒãšæžããšãé¢æ°fooã¯å€2ãè¿ããŸãã Lispã®ãã¯ãã¯ãè€éãªããžãã¯ãå¶åŸ¡æ§é ãåçŽãªæ§æã®èåŸã«é ããããã«å¿ããŠèšèªèªäœã®è¡šçŸæ段ãæ¡åŒµããããã®åªããããŒã«ã§ãã å®éã«ã¯ããdefnããã->>ããã->ããªã©ã®å€ãã®èšèªæ§æèŠçŽ ãåãªããã¯ãã§ãã
Lispãã¯ãã¯éåžžã®é¢æ°ã§ãããã³ã³ãã€ã«æã«å®è¡ããããšããå¯äžã®äŸå€ããããããããèšè¿°ãããã¯ããã¯ãç¿åŸããã«ã¯ãååãšããŠæ¬¡ã®4ã€ã®ãç¹æ®åœ¢åŒããã©ã®ããã«æ©èœããããç¥ãã ãã§ååã§ãã
`(expr) '(expr) ~(expr) ~@(expr)
詳现ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã äžèšã§èšãã°-åŒçšç¬ŠïŒ 'ãš `ïŒã®æ§æã¯ãã³ã³ãã€ã©ãŒãžã®åãªãè¡šèšã§ãïŒ"ãã®åŒã¯è©Šãããã¹ãã§ã¯ãããŸãããããã®ãŸãŸè¿ãããã¹ãã§ãã ã³ãŒãã®åœ¢åŒã§ããããã³åŒçšç¬Šãªãã®æ§æïŒãããã³ã@ïŒã¯ããæå®ãããåŒãå®è¡ããã³ãŒãã®ãã®å Žæã«çµæã貌ãä»ãããããšãã»ãŒæå³ããŸãã åœç¶ãunqouteã³ã³ã¹ãã©ã¯ãã¯ãã¯ã©ãŒãã³ã³ã¹ãã©ã¯ãå ã§ã®ã¿æå³ããããŸãã ãããã£ãŠããã¯ãã¯ãåŒæ°ãšããŠåŒçšæ§é ãåããå€ãšããŠåŒçšæ§é ãè¿ããã³ã³ãã€ã«æã«å®è¡ãããé¢æ°ã§ãã
ãã€ããããã³ã°ãå¿ èŠãªçç±
Lispãã¯ãã®åã瀺ãããã«ãLispã®ãã€ããããã³ã°å®è£ ãæžããŸãã ãã€ããããã³ã°ãšã¯ ååã瀺ãããã«ãããã¯2ã€ã®å¶åŸ¡æ§é ã®çµã¿åããã§ãããã€ããšãã¿ãŒã³ãããã³ã°ã§ãã
Clojure PLã®ãã€ãã¯ãåŒæ°ãšããŠnçªç®ã®åŒãåããç¹å®ã®æ¹æ³ã§ãããã®åŒã®æ§æã«å±éããåãªããã¯ãã§ããç°¡åã«èšãã°ã次ã®ããã«ãªããŸãã
ïŒ-> expr1 expr2 expr3 ...ïŒããã§ããã€ã "->"ã¯expr1ãexpr2ã®æåã®åŒæ°ãšããŠæ¿å ¥ãïŒä»ã®ãã¹ãŠã®åŒæ°ã¯å³ã«1ããžã·ã§ã³ç§»åããŸãïŒãçµæã®expr12ã¯expr3ã®æåã®åŒæ°ãšããŠæ¿å ¥ããŸãã äŸ
(-> (func1 "foo") (func2 "bar") (func3 123))
(func3 (func2 (func1 "foo") "bar") 123)
ãããã®2ã€ã®åŒã¯ããŸã£ããåããã®ã§ãã ã³ãŒãã®èªã¿ãããã®åé¡ã¯å¥œã¿ã®åé¡ã§ããããã€ããå¿ èŠã§ããããšã¯å人çã«æããã§ãã ä»ã®ãã€ãããããŸããããšãã°-->>ã¯æšæž¬ããã®ãé£ãããªããåæ§ã«æ©èœããŸã->ããæåã®åŒæ°ã§ã¯ãªãæåŸã®åŒæ°ãæ¿å ¥ããŸãã äžè¬ã«ãããããçš®é¡ã®ãã€ããèšè¿°ã§ããŸãããååãšããŠããã2ã€ãæããã䜿çšãããŸãã
ãã¿ãŒã³ãããã³ã°ã¯æãããªããšã§ããããšãã°ãã¢ãŒã©ã³/ãšãªãã·ã«ãhaskellãmlã¯éçºè ã§ãããç°¡åã«èšãã°èª¬æããã®ã¯ç°¡åã§ã¯ãªãããããæããã¹ãã§ãã éåžžã«é ããpmã¯å²ãåœãŠãšæ¯èŒã®æ§æãšããŠå®çŸ©ã§ããŸãã åå¿è ã¯ãŠã£ãããã£ã¢ã«è¡ããã以åã®èšäºãåç §ããŠãã ããããšãªã¯ãµãŒ/ã¢ãŒã©ã³YPã§ã®pmã®äœ¿çšã«ã€ããŠç°¡åã«èª¬æããŸããã Clojureã«ã¯ãã€ãã£ããã¿ãŒã³ãããã³ã°ã¯ãããŸãããããæ³åã®ãšãããerlangã®pmãšã»ãŒåãpmãã¯ãã䜿çšããŠå®è£ ããã©ã€ãã©ãªããããŸãã ãã®ãããžã§ã¯ãã§ã¯ãè»èŒªãåçºæãããäžèŽãã¯ãã©ã€ãã©ãªã䜿çšããŸãã
ããŠã質åã«æ»ããŸã-ãªãpmãšpipeã1ã€ã®ãã€ãäžèŽãšã³ãã£ãã£ã§æ¥ç¶ããå¿ èŠãããã®ã§ããïŒ ãã¹ãŠã®æ©èœãã¯ãªãŒã³ã§ãããhello worldãã¬ãã«ã®ããã°ã©ã ãäœæããå Žåãå¯äœçšã¯ãªãããã¹ãŠãéåžžã«æ±ºå®çã§ããããããããã¯ããŸãæå³ããããŸããã ããããå®éã®çç£ã§ã¯ãæ±ãæ©èœãªãã§ã¯ã§ããŸããã ããšãã°ããœãŒã·ã£ã«ãããã¯ãŒã¯VKã®ã¢ã«ãã ã«åçãã¢ããããŒãããå¿ èŠããããŸãã ãã®ããã¥ã¡ã³ãã«ãããšãã¢ã«ãã IDãã¢ã¯ã»ã¹ããŒãããã³ããŠã³ããŒãããå¿ èŠãããå®éã®ããŒã¿ãå¿ èŠã§ãã äžè¬çãªèªã¿èŸŒã¿ã¢ã«ãŽãªãºã ã¯æ¬¡ã®ãšããã§ã
url (get-http , json) (post-http , json) (get-http , json)
ãã¡ã€ã«ã®èªã¿åããjsonã®è§£æãhttpãªã¯ãšã¹ãã¯ãã¹ãŠããŒãã£ãªé¢æ°ã§ãã åŒã³åºãäžãäœã§ãèµ·ããåŸãŸã-æå®ãããã¢ãã¬ã¹ã«ãã¡ã€ã«ããããŸãããç¡å¹ãªjsonãå¿ èŠãªãã£ãŒã«ãã®ãªãæå¹ãªjsonãåæããµãŒããŒã¯200ã§ã¯ãªãä»ã®ãã®ãªã©ãšå¿çããŸããã ãããã®åæ©èœã§ã¯ããã¹ãŠãéåžžã«æªãã§ãã ãããŠããã¹ãŠãããŸããããŸããã次ã®åæ©èœã¯åã®æ©èœããã®æ£ããçµæãå¿ èŠãšããŸãã åã ã®é¢æ°ããšã«ãäžè¯ã±ãŒã¹ã®å¥ãèšè¿°ããŠå®è¡ãåé¿ããããšãã§ããŸãããããããã¹ãŠãé£æºãããå¿ èŠããããŸããäœãåé¡ãçºçããå Žåãäœãã©ãã§äœãæ£ç¢ºã«çºçããããç¥ãããã®ã§ãã ããããèªè ã®å€ãã¯ããã®ãããªãã®ãæžããããšæãã§ãããã
ããããããã¯æ®å¿µã§ãïŒããã¯ããµããŒãããã³ãã£ããŒã¹ããã ãã§ãªããåã«èªã¿åã/æžã蟌ã¿/ç解ããã®ãé£ããã§ãã ãã®ãããªç¶æ³ïŒåžžã«åæããŸãïŒã§ã¯ããã€ããããã³ã°ã«ããããã¹ãŠã®è€éãªããžãã¯ãé衚瀺ã«ãªããã³ãŒããéåžžã«åçŽã«ãªããŸãã ãã¯ãã®äŸpipe_matchingããã³pipe_not_matching
(defn nested_process foo bar baz (pipe_matching {:ok some_data} (simple_func1 foo) (simple_func2) (simple_func3 bar) (simple_func4 baz)))
ããã§äœãèµ·ãããïŒnested_processé¢æ°ã¯åŒæ°fooãbarãããã³bazãåãå ¥ããŸãã ãããŠãããŒãã£ãªå¯èœæ§ã®ããé¢æ°simple_func1ãã¢ãªãã£1ã§ãsimple_func2ãã¢ãªãã£1ã§ãsimple_func3ãã¢ãªãã£2ã§ãsimple_func4ãã¢ãªãã£2ã§é£ç¶åŒã³åºãããŸãããéåžžã®ãã€ãã®ããã«ãåã®åŒã®çµæã¯æ¬¡ã®åŒã®æåã®åŒæ°ã§ãã ãããŠä»ãæãéèŠãªããš-ãã¿ãŒã³{ïŒok some_data}ãpipe_matchingãã¯ãã®æåã®åŒæ°ãšããŠèšå®ããŸãã ãã®ãã¿ãŒã³ã®å ŽåãããŒãååšããmapãé©åã§ããä»»æã®å€ã§OKã§ãã ãããŠsimple_funcé¢æ°ã¯ãã®ãã¿ãŒã³ã«é©ããå€ãè¿ããŸããã次ã®é¢æ°ãåŒã³åºãããŸãïŒéåžžã®ãã€ãã®ããã«ïŒã ãã ããsimple_funcé¢æ°ã®äžéšããã®ãã¿ãŒã³ã«é©åããªãå€ãè¿ããšããã«ãnested_processé¢æ°ã®å€ãšããŠè¿ããããã§ãŒã³ã«æž¡ãããŸããã ããšãã°ãsimple_func3ã{ïŒerror "on simple_func3 server ans 500"}ãè¿ãå Žåãsimple_func4é¢æ°ã¯ãŸã£ããåŒã³åºããããnested_processã¯{ïŒerror "on simple_func3 server ans 500"}ãè¿ããŸãã åæ§ã®ãã¯ãpipe_not_matchingãäœæããããšãã§ããŸããããã¯æ¬¡ã®ããã«äœ¿çšã§ããŸã
(defn nested_process foo bar baz (pipe_not_matching {:error some_error} (simple_func1 foo) (simple_func2) (simple_func3 bar) (simple_func4 baz)))
ç§ã¯ãããã©ã®ããã«æ©èœããããèããŸã-ããã¯æèããæããã§ãã ããã§simple_func3ã{ïŒerror "on simple_func3 server ans 500"}ãè¿ãã1çªç®ãš2çªç®ã®é¢æ°ãåã®ãã¿ãŒã³ã«é©åããªãå€ãè¿ãå Žåãçµæã¯åã®äŸãšåãã«ãªããŸãã å®éã«ã¯ãpipe_not_matchingã奜ã¿ãŸãã ãã®çµæãif / else / elseif / case / switchãªã©ã䜿çšããã«ãã¿ã¹ã¯ããžãã¯ãã»ãŒãªãã©ã«ã«ã³ãŒãã«ã·ãªã¢ã«åã§ããŸãã äžè¬ã«ãFPã倧奜ããªãã®ãã¹ãŠ-ã³ãŒãã¯ãäžå¿ èŠãªæœè±¡ãšã³ãã£ãã£ã®ãªãã¿ã¹ã¯ãã®ãã®ã§ãã ãã£ããã ããŠãã»ãã®æ°è¡ã§Lispã§ãã®ãããªãã¯ããæžãæ¹æ³ãèŠãŠã¿ãŸãããã
Lispã®ãã€ããããã³ã°ã®èšè¿°
ãŸããã©ã€ãã©ãªã®åå空éã®äŸåé¢ä¿ãèšè¿°ããŸãããäžèŽããããã¯ãã¯1ã€ã ãã§ãã
(ns pmclj.core (:use [clojure.core.match :only (match)]))
äžè¬ã«ãç®æšã§ãã2ã€ã®ãã¯ããå®çŸ©ããŸã
(defmacro pipe_matching [pattern init_expression & other_expressions ] (pipe_matching_inner {:pattern pattern, :result init_expression, :expressions other_expressions, :continue_on_match true})) (defmacro pipe_not_matching [pattern init_expression & other_expressions ] (pipe_matching_inner {:pattern pattern, :result init_expression, :expressions other_expressions, :continue_on_match false}))
ãã¯ãã¯æåã®åŒæ°ãšããŠãã¿ãŒã³ãåããæ®ãã®åŒæ°ã¯pmèªäœã®åŒã§ããå°ãªããšã1ã€ã®åŒãå¿ èŠã§ãããããinit_expressionãåŒã³åºããŠå¿ èŠãª2çªç®ã®åŒæ°ãèšå®ããŸãã ïŒèšå·ã«æ³šæããŠãã ãã-ããã§ã¯ãother_expressionsã¯ãå¯èœãªåŒæ°ïŒ3çªç®ã4çªç®ãªã©ïŒã§æ§æãããä»»æã®é·ãïŒãããã空ïŒã®ãªã¹ãã§ããããšãæå³ããŸãã ãããã£ãŠããã¯ãã¯ã1ãè¶ ããä»»æã®æ°ã®åŒæ°ã§å±éã§ããŸãã
次ã«ã䟿å®äžãåŒæ°ãã·ãªã¢ã«åããŠããŒïŒpattern ,: result ,: expressions :: continue_on_matchã§ãããããŸãã ããã§ã®çµæã¯ãåã®ã¹ãããã§åŸãããçµæã§ããåŒã¯ãçµæã®ãã¯ãã³ãŒãã«å±éãããªãæ®ãã®åŒã§ããcontinue_on_match-true / falseïŒçµæããã¿ãŒã³ã«äžèŽããå Žåã®åŠçââ-åŒã³åºããã§ãŒã³ãç¶ç¶ããããå€ãè¿ããŸãã
çµæã®ãããã¯pipe_matching_innerååž°é¢æ°ã«æž¡ãããå¿ èŠãªã³ãŒããè¿ãããŸãã ã¯ããããã¯Lispã®çŸããã§ããé¢æ°ãåŒã³åºãæã«ãã§ã«ã³ã³ãã€ã«ãããŠããå Žåã«ã®ã¿ãã³ã³ãã€ã«æã«é¢æ°ãåŒã³åºãããšãã§ããŸãã æ©èœã¯æ¬¡ã®ãšããã§ãã
(defn pipe_matching_inner [{pattern :pattern, result :result, expressions :expressions, continue_on_match :continue_on_match}] (case (or (= expressions nil) (= expressions ())) true result false (let [to_pipe (first expressions) rest_expr (rest expressions)] `(let [~'res ~result] (case (= ~continue_on_match (check_match ~'res ~pattern)) true ~(pipe_matching_inner {:pattern pattern, :result `(-> ~'res ~to_pipe), :expressions rest_expr, :continue_on_match continue_on_match}) false ~'res)))))
ããã¯ããã¯ãæ¬äœã§çæããããããåãå ¥ããŸãã ããã§ãã¡ãªã¿ã«ãClojureã®ãã€ãã£ãpmãäœããã®åœ¢åŒã§ããªãå¥åŠãªæ§æãæã£ãŠããããšãããããŸãã[{ãã¿ãŒã³ïŒãã¿ãŒã³ãçµæïŒçµæãåŒïŒåŒãcontinue_on_matchïŒcontinue_on_match}]ã
ã±ãŒã¹-ããã®åŒã¯æ¬¡ã®ããšãèšã£ãŠããŸãããã¹ãŠã®åŒããã§ã«åŠçããŠããå Žåãçµæãè¿ã以å€ã«äœãããå¿ èŠã¯ãããŸããã ãã以å€ã®å Žåã¯ãåŠçããŸãã 次ã«ãLispèšèªã®éåžžã«éèŠãªç¹å¥ãªåœ¢åŒãletããããŸãã ããã«ã¯ã°ããŒãã«å€æ°ãšå²ãåœãŠã¯ãªããããããŸããããåŒ=>ã·ã³ãã«ã®ç²Ÿç¥ã§ããŒã«ã«ãã€ã³ãã£ã³ã°ãè¡ãããšãã§ããŸãã firsté¢æ°ãšresté¢æ°ã¯ãå®éã«ã¯ãªã¹ãã®æåã®èŠçŽ ãé€ãæåãšãã¹ãŠãè¿ããŸããããã§ã¯ãã¹ãŠãééçã§ããåŠçããããã«æ¬¡ã®åŒãååŸããŸãã
ããã«ãæãèå³æ·±ãã®ã¯ãã³ã³ãã€ã«æã«åçã«çæãããå®éã®ã³ãŒãã§ãã ããã§ã¯ãäœãèµ·ãã£ãŠããã®ããç解ããããã«ããã§ã«å°ã粟ç¥çãªåªåãããªããã°ãªããŸããã åã®åŒã®çµæãresã·ã³ãã«ã«ããŒã«ã«ã«ãã€ã³ãããŸãïŒå®è¡æã«ãã®åŒãè€æ°åå®è¡ãããªãããã«ããŸãïŒã ãã«æ³šæããŠãã ãã-ããã¯ãã³ã³ãã€ã«äžã«æåã察å¿ããåå空éã«ã¢ã¿ããããããšããäºå®ã®ããã®å°ããªããã¯ã§ãããçµã¿åããã 'ã¯ãããããã¿ããããŸããã€ãŸãããã®ã³ã³ããã¹ãã§ã¯ããããã®åé¡ãæãäžããŸããã 以äžã¯ãå®è¡æã«æ£çŽã«å®è¡ãããåŒã§ããã±ãŒã¹ã§ããresããã¿ãŒã³patternãšäžèŽãããã©ããã確èªããŸãã check_match-å®éã«ã¯ãã©ã€ãã©ãªãã¯ãã®äžèŽã«åºã¥ããéåžžã«åçŽãªãã¯ã
(defmacro check_match [obj pattern] `(match ~obj ~pattern true :else false))
ããã«ãcheck_matchåŒãäºæ³ããããã©ããã«å¿ããŠãtrue-pipe_matchingããã³false-pipe_not_matchingã®å ŽåãåŒã³åºãã®ãã§ãŒã³ãç¶ç¶ããããresãæ»ããŸãã åŸç¶ã®äžé£ã®åŒã³åºãããpipe_matching_inneré¢æ°ã®ååž°åŒã³åºãã«ãã£ãŠçŸããæç»ãããŸãã
å®éã«ã©ã®ããã«èŠãããèŠãŠã¿ãŸãããã
ããã¯çŸãããã€ãã®ãããã³ã°ã§ã
(pipe_matching {:ok some} (func1 "foo") (func2 "bar") (func3 123))
å®éã«ã¯ãããã¯ãã®ãããªå°å ã®å°çã«å€ãããŸã
(clojure.core/let [res (func1 "foo")] (clojure.core/case (clojure.core/= true (pmclj.core/check_match res {:ok some})) true (clojure.core/let [res (clojure.core/-> res (func2 "bar"))] (clojure.core/case (clojure.core/= true (pmclj.core/check_match res {:ok some})) true (clojure.core/-> res (func3 123)) false res)) false res))
ãã€ããããã³ã°ãªãã§åãããžãã¯ãæ§ç¯ããã«ã¯ããã®å°çããã¹ãŠèªåã®æã§æžããªããã°ãªããªããšããäºå®ã«æ³šæãåèµ·ãããã§ãïŒ
å®å šãªã³ãŒãã¯ãã¡ãã«ãããŸã ã
çµè«ãšããŠãäžèŠãããšãããLispæ§æã¯ç¢ºãã«ãŠãŒã¶ãŒãã¬ã³ããªãŒã§ã¯ãããŸãããã倧èŠæš¡/è€éãªã·ã¹ãã ã®æ§ç¯ã«ã¯é©ããŠããŸãã ãã¡ãããã¢ãŒã©ã³/ãšãªãã·ã«ã®åŸãããªãã¯otpãªãã§æã䜿ããªãããã«æããŸãããããã¯æéã®åé¡ã ãšç¢ºä¿¡ããŠããŸãã ãšã«ãããããã¯jvmã®ç§ã®æåã®çµéšã§ãããç§ã¯ãããéåžžã«æåãããšæããŸãïŒ
UPDïŒ
ããã€ãã®ãªãã¡ã¯ã¿ãªã³ã°ãè¡ã£ãåŸããã¯ãèªäœã¯ããã»ã©æãèŠããŸããã 圌ã¯ãã³ãã«è³ãåŸããããã«4ã€ã®ãã¯ããè¿œå ããŸããã
pred_matching / pred_not_matchingã¯åãã§ãæåã®åŒæ°ãšããŠã¢ãªãã£1ã®ã©ã ãã®ã¿ãåããŸãã
key_matching / key_not_matchingã¯åãã§ããããŒãæåã®åŒæ°ãšããŠã®ã¿åãå ¥ããå®è¡æã«æå®ãããããŒã®å€ã®åŒã³åºãçµæã調ã¹ãŸããnilãŸãã¯absentã®å Žåãããã¯falseã§ãããã以å€ã®å Žåã¯trueã§ãã
䜿çšäŸ
(defn func1 [arg] {:ok arg}) (defn func2 [arg1 arg2] {:fail (+ (get arg1 :ok) arg2)}) (defn func3 [arg1 arg2] {:ok (+ (get arg1 :ok) arg2)}) (defn example_pred [] (pred_matching #(contains? % :ok) (func1 1) (func2 2) (func3 3))) (defn example_pm [] (pipe_matching {:ok some} (func1 1) (func2 2) (func3 3))) (defn example_key [] (key_matching :ok (func1 1) (func2 2) (func3 3)))
ã¡ãªã¿ã«ãåã®é¢æ°ããæ£ããæ»ãå€ãå¿ èŠãªãµã³ãã«ã³ãŒãã次ã«ç€ºããŸããå ŽæïŒ+ïŒget arg1ïŒokïŒarg2ïŒã«ã¯ãããšãã°geté¢æ°ãnilãè¿ãå Žåãªã©ãå®è¡ãå«ãŸããå¯èœæ§ããããŸãã
äºæ³ã©ããããã®å Žåã3ã€ã®ãµã³ãã«é¢æ°ã¯ãã¹ãŠåãå€ãè¿ããŸãã
(example_pred) {:fail 3} (example_pm) {:fail 3} (example_key) {:fail 3}
ãŸããrkey_matching / rkey_not_matchingãã¯ããè¿œå ããŸãããåæ§ã«æ©èœããæ§é å ã®ããŒãšã³ããªã®ã¿ãååž°çã«æ€çŽ¢ããèŠã€ãã£ãå Žåã¯åŒã³åºããã§ãŒã³ãçµäºããèŠã€ãã£ããšã©ãŒãè¿ããŸãã å®è·µã瀺ããŠããããã«ãããã¯äœ¿ãããã/æ±çšæ§ã®ç¹ã§æã䟿å©ãªãªãã·ã§ã³ã§ãã
å¶åŸ¡æ§é ã®æ®éæ§ã¯ãåœç¶pred_matching> pipe_matching> rkey_matching> key_matchingã§ãã ã©ã¡ãã䜿çšãããã¯ãå人ã®å¥œã¿ãšãæ±ãããŒã¿ã®è€éãã«äŸåããŸãã
çµæã®ã³ãŒãã¯ãã¡ãã§ãã