Skip to content

Instantly share code, notes, and snippets.

View yvern's full-sized avatar

Yuri Vendruscolo da Silveira yvern

  • Deutsche Bank
  • London, UK
  • 13:36 (UTC)
View GitHub Profile
{:linters {:defrule/hidden-flow {:level :error}}
:hooks {:analyze-call {clara.rules/defrule hooks.defrule/defrule}}
:lint-as {clara.rules/defrule clj-kondo.lint-as/def-catch-all
clara.rules/defquery clj-kondo.lint-as/def-catch-all}}
(ns hooks.defrule)
(def clara-inserts
"The forms we care about, capable of inserting facts."
#{'insert! 'insert-all!})
(def descend*
"Transducer to descend into inner forms, looling for those we care about, the ones that insert facts.
Unfortunately we can't really figure out if someone defines another function that calls `insert!`."
(comp (map macroexpand)
(ns yvern.test-rules
(:require [clara.rules :refer [defrule insert!]]
[yvern.defrule :as check]))
(check/defrule
(defrule ok
[:a]
=>
(insert! {:fact-type :b})))
(ns yvern.defrule)
(def clara-inserts
"The forms we care about, capable of inserting facts."
#{'insert! 'insert-all!})
(def descend*
"Transducer to descend into inner forms, looping for those we care about, the ones that insert facts.
Unfortunately we can't really figure out if someone defines another function that calls `insert!`."
(comp (map macroexpand)
(defrule not-ok
[:a]
=>
(when (< 0.5 (rand))
(insert! {:fact-type :b})))
(defrule overflow?
[?middle <- :middle]
[:or [?max <- :top] [?max <- :right]]
[:test (<= ($ ?max) ($ ?middle))]
=>
(insert! {:fact-type :overflow!}))
(defrule underflow?
[?middle <- :middle]
[:or [?min <- :bottom] [?min <- :left]]
(ns yvern.hard-rule
(:require [clara.rules :refer [defrule insert!]]))
(def $ (comp val first))
(defrule all-together
[?middle <- :middle]
[:or
[:and [?max <- :top] [?min <- :bottom]]
[:and [?min <- :left] [?max <- :right]]]
(defmacro no-bangs!
[forms]
(if (->> forms
flatten
(filter symbol?)
(some (comp (partial re-find #"\!") name)))
(throw (ex-info "/(•̀o•́)ง No bangs!" {}))
forms))
(no-bangs!
@yvern
yvern / dont.clj
Created January 20, 2023 18:44
Break clojure compilation
(defmacro dont
[& _]
(throw (ex-info "(╯°□°)╯︵ ┻━┻" {})))
(dont
(defn add [a b] (+ a b)))
@yvern
yvern / keybase.md
Created June 15, 2020 20:36
keybase.md

Keybase proof

I hereby claim:

  • I am yvendruscolo on github.
  • I am yorggen (https://keybase.io/yorggen) on keybase.
  • I have a public key ASDJQ4AZlhKlr9FQlguETvKkODjY6Xox0-ShNaE9beqXrwo

To claim this, I am signing this object: