Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Chaining Operator in Climb

vjeux
December 21, 2011

Chaining Operator in Climb

vjeux

December 21, 2011
Tweet

More Decks by vjeux

Other Decks in Programming

Transcript

  1. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Chaining Operator in Climb Christopher Chedeau LRDE Laboratoire de Recherche et D´ eveloppement d’EPITA July 3, 2011 http://lrde.epita.fr/ 1 / 19 Christopher Chedeau
  2. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction Method Chaining jQuery Method Chaining Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion 2 / 19 Christopher Chedeau
  3. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion jQuery Old browsers are full of compatibility issues jQuery1 is a [...] JavaScript Library that simplifies HTML document traversing 1http://jquery.com/ 3 / 19 Christopher Chedeau
  4. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Method Chaining Intuitive API Heavily rely on Method Chaining $(”a”) .addClass(”external”) .attr(”target”, ” blank”) .click(function () { /∗ analytics call ∗/ }) 4 / 19 Christopher Chedeau
  5. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Method Chaining in Javascript function Object() {} Object.prototype = { methodA: function () { // do something return this; }, methodB: function () { // do something return this; } }; var obj = new Object(); obj.methodA().methodB(); It works in any Object Oriented language: C++ Java PHP C# ... 5 / 19 Christopher Chedeau
  6. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Extended Chaining HTML Document Traversing $(”li”) .has(”ul”) .eq(1) .parent() // li: List Item // ul: Unordered List 6 / 19 Christopher Chedeau
  7. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Extended Chaining HTML Document Traversing $(”li”) .has(”ul”) .eq(1) .parent() // li: List Item // ul: Unordered List SQL Query SQL(”select”) .field(”∗”) .table(”users”) .limit(10) 6 / 19 Christopher Chedeau
  8. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Extended Chaining HTML Document Traversing $(”li”) .has(”ul”) .eq(1) .parent() // li: List Item // ul: Unordered List SQL Query SQL(”select”) .field(”∗”) .table(”users”) .limit(10) Asynchronous Tasks $(”<div/>”) .fetch(”navigation.html”) // Asynchronous .addClass(”column”) .appendTo(”#side”) 6 / 19 Christopher Chedeau
  9. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Image processing Image processing chains can be expressed through method chaining Image(”lena.jpg”) .togray() .otsu() .opening(8 connectivity) .save(”lena opening.png”) 7 / 19 Christopher Chedeau
  10. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Straight Common Lisp Implementation Common Lisp methods do not belong to classes (let ((img (load ”lena.jpg”))) (setf img (togray img)) (setf img (otsu img)) (setf img (opening img (8-connectivity))) (save img ”lena opening.png”)) 8 / 19 Christopher Chedeau
  11. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Straight Common Lisp Implementation Common Lisp methods do not belong to classes (let ((img (load ”lena.jpg”))) (setf img (togray img)) (setf img (otsu img)) (setf img (opening img (8-connectivity))) (save img ”lena opening.png”)) The temporary variable is written 8 times 8 / 19 Christopher Chedeau
  12. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Without Temporary Variable (save (opening (otsu (togray (load ”lena.jpg”) ) ) (8−connectivity)) ”lena opening.png”) 9 / 19 Christopher Chedeau
  13. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Without Temporary Variable (save (opening (otsu (togray (load ”lena.jpg”) ) ) (8−connectivity)) ”lena opening.png”) Functions executed last are written first 9 / 19 Christopher Chedeau
  14. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Without Temporary Variable (save (opening (otsu (togray (load ”lena.jpg”) ) ) (8−connectivity)) ”lena opening.png”) Functions executed last are written first Arguments are far away from function name 9 / 19 Christopher Chedeau
  15. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction of Dollar $ Macro Dollar $ Macro ($ (load ”lena.jpg”) (togray) (otsu) (opening 8−connectivity) (save ”lena opening.png”)) Method Chaining Image(”lena.jpg”) .togray() .otsu() .opening(8 connectivity) .save(”lena opening.png”) It takes a sequence of actions 10 / 19 Christopher Chedeau
  16. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction of Dollar $ Macro Dollar $ Macro ($ (load ”lena.jpg”) (togray ) (otsu) (opening 8−connectivity) (save ”lena opening.png”)) Method Chaining Image(”lena.jpg”) .togray() .otsu() .opening(8 connectivity) .save(”lena opening.png”) It takes a sequence of actions The result of each action is passed as first argument on the next Rewritten either with or without temporary variable Can express all the method chaining features 10 / 19 Christopher Chedeau
  17. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Modifiers Not everything fits in the chaining pattern ($ (action) ’(print ”Something”) (action)) 11 / 19 Christopher Chedeau
  18. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Modifiers Not everything fits in the chaining pattern ($ (action) ’(print ”Something”) (action)) We introduce the quote ’ modifier 11 / 19 Christopher Chedeau
  19. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Modifiers Normal behavior (before) (action arg) (after ) 12 / 19 Christopher Chedeau
  20. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Modifiers Normal behavior (before) (action arg) (after ) Quote ’ Modifier (before) $1, $2 ... ’(action arg $1) (after ) 12 / 19 Christopher Chedeau
  21. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Modifiers Normal behavior (before) (action arg) (after ) Quote ’ Modifier (before) $1, $2 ... ’(action arg $1) (after ) Sharp # Modifier (before) $1, $2 ... #(action arg $1) (after ) 12 / 19 Christopher Chedeau
  22. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Grouped Actions Image(”lena.png”) .preprocess() .background() .fill(red) .foreground() .fill(green) . 13 / 19 Christopher Chedeau
  23. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Grouped Actions Image(”lena.png”) .preprocess() .background() .fill(red) .end() .foreground() .fill(green) .end() . [lena] [lena, proc] . [lena, proc, background] [lena, proc, background] [lena, proc] . [lena, proc, foreground] [lena, proc, foreground] [lena, proc] Feels more like a hack Hard to know which methods push to the stack Elements in the stack cannot be garbage collected 13 / 19 Christopher Chedeau
  24. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction of // Macro ($ (load ”lena.png”) (preprocess) (// ((background) (fill red)) ((foreground) (fill green)))) 14 / 19 Christopher Chedeau
  25. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction of // Macro ($ (load ”lena.png”) (preprocess) (// ((background ) (fill red)) ((foreground ) (fill green)))) Explicit dispatch of the value 14 / 19 Christopher Chedeau
  26. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Introduction of // Macro ($ (load ”lena.png”) (preprocess) (// ((background) (fill red)) ((foreground) (fill green))) (combine )) Explicit dispatch of the value Last value of branch can be collected 14 / 19 Christopher Chedeau
  27. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example Otsu Sauvola 1 Sauvola 5 Otsu - Sauvola 1 Otsu - Sauvola 5 Sauvola 1 - 5 15 / 19 Christopher Chedeau
  28. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) 16 / 19 Christopher Chedeau
  29. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// 16 / 19 Christopher Chedeau
  30. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) 16 / 19 Christopher Chedeau
  31. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) 16 / 19 Christopher Chedeau
  32. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) 16 / 19 Christopher Chedeau
  33. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 16 / 19 Christopher Chedeau
  34. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 16 / 19 Christopher Chedeau
  35. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 (’(timer−start) (sauvola (box2d 5)) ’(timer−print ”Sauvola 5”) (save ”sauvola5.png”))) ; $3 16 / 19 Christopher Chedeau
  36. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 (’(timer−start) (sauvola (box2d 5)) ’(timer−print ”Sauvola 5”) (save ”sauvola5.png”))) ; $3 (// (#(diff $1 $2) 16 / 19 Christopher Chedeau
  37. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 (’(timer−start) (sauvola (box2d 5)) ’(timer−print ”Sauvola 5”) (save ”sauvola5.png”))) ; $3 (// (#(diff $1 $2) (save ”diff1.png”)) 16 / 19 Christopher Chedeau
  38. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 (’(timer−start) (sauvola (box2d 5)) ’(timer−print ”Sauvola 5”) (save ”sauvola5.png”))) ; $3 (// (#(diff $1 $2) (save ”diff1.png”)) (#(diff $1 $3) (save ”diff2.png”)) (#(diff $2 $3) (save ”diff3.png”)))) 16 / 19 Christopher Chedeau
  39. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Example ($ (load ”lenagray.png”) (// (’(timer−start) (otsu) ’(timer−print ”Otsu”) (save ”otsu.png”)) ; $1 (’(timer−start) (sauvola (box2d 1)) ’(timer−print ”Sauvola 1”) (save ”sauvola1.png”)) ; $2 (’(timer−start) (sauvola (box2d 5)) ’(timer−print ”Sauvola 5”) (save ”sauvola5.png”))) ; $3 (// (#(diff $1 $2) (save ”diff1.png”)) (#(diff $1 $3) (save ”diff2.png”)) (#(diff $2 $3) (save ”diff3.png”)))) ; Otsu: 101ms ; Sauvola 1: 263ms ; Sauvola 5: 3407ms 16 / 19 Christopher Chedeau
  40. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Conclusion Chaining Operator • Ease of use • Entire API has to be rethought Related Work • Implementation of two Component Tree algorithms ([NC04], [BGL+07]) • Overhaul of Value representation • Rationalization of Site Set interface Next Steps • New design patterns from dynamic languages • Explore image processing in the browser 17 / 19 Christopher Chedeau
  41. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Questions ? 18 / 19 Christopher Chedeau
  42. Chaining Operator in Climb Introduction Method Chaining jQuery Method Chaining

    Extended Climb Image Processing Implementation Attempts Dollar macro Extensions Modifiers Parallel Example Conclusion Bibliography Christophe Berger, Thierry G´ eraud, Roland Levillain, Nicolas Widynski, Anthony Baillard, and Emmanuel Bertin, Effective component tree computation with application to pattern recognition in astronomical imaging, Proceedings of the IEEE International Conference on Image Processing (ICIP) (San Antonio, TX, USA), vol. 4, September 2007, pp. IV–41–IV–44. L. Najman and M. Couprie, Quasi-linear algorithm for the component tree, IS&T/SPIE Symposium on Electronic Imaging, In Vision Geometry XII, 2004, pp. 18–22. 19 / 19 Christopher Chedeau