$30 off During Our Annual Pro Sale. View Details »

Re-find: discover functions with spec

Re-find: discover functions with spec

Re-find is an app and a library that lets you interactively discover Clojure functions based on example in- and output values or predicates. In this talk we will see how it works and how it is implemented, using clojure.spec as the driving force.

About the speaker: Michiel Borkent is a software developer and Clojurian. He can be found as @borkdude in various places on the web.

This presentation was given at Dutch Clojure Days 2019:

https://clojuredays.org/#Re-find:%20discover%20functions%20with%20spec

Michiel Borkent

April 06, 2019
Tweet

More Decks by Michiel Borkent

Other Decks in Programming

Transcript

  1. re-find
    Michiel Borkent

    @borkdude

    Dutch Clojure Days

    2019-04-06

    discover functions with spec

    View Slide

  2. View Slide

  3. View Slide

  4. View Slide

  5. ?

    View Slide

  6. View Slide

  7. ?

    View Slide

  8. View Slide

  9. rationale for re-find
    • You are learning Clojure and don't know the names or
    even the existence of functions

    • You know a function exists, but forgot the order of
    arguments it takes

    View Slide

  10. https://re-find.it

    View Slide

  11. How does it work?
    • re-find searches within spec’ed functions

    • so it needs a collection of specs (speculative, but could
    be other specs for core or self-defined functions)

    View Slide

  12. Why not just try everything
    without using spec?

    View Slide

  13. Why use spec for this?
    Recommend only idiomatic functions


    View Slide

  14. Spec validation
    (s/fdef clojure.core/inc
    :args (s/cat :x number?)
    :ret number?)
    {:args [1]

    :ret 1}

    View Slide

  15. Spec validation
    (s/fdef clojure.core/inc
    :args (s/cat :x number?)
    :ret number?)

    View Slide

  16. Spec validation
    (s/fdef clojure.core/inc
    :args (s/cat :x number?)
    :ret number?)
    But (inc 1) is not equal to 1...

    View Slide

  17. Spec validation
    (s/fdef clojure.core//
    :args (s/cat :numerator number?
    :denominators (s/* number?))
    :ret number?)
    (= 1 (/ 1 1)) ;; true

    View Slide

  18. spec + exact
    match

    View Slide

  19. spec + type
    match

    View Slide

  20. permutation of
    args

    View Slide

  21. Finitize

    View Slide

  22. Stack
    • Self-hosted CLJS

    • Low operational cost (just static HTML + JS)

    • No security risks (evaluation on server)

    • CodeMirror + parinfer layer

    • automatic paren matching, closing, highlighting

    • CLJC: re-find lib works in Clojure and (self-hosted) CLJS

    View Slide

  23. web + lib/CLI + JavaFX

    View Slide

  24. Thank you!
    Questions or suggestions?

    @borkdude

    View Slide