Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 544566f7ee740731ca69
...
compare: da4fcae5f3afe6cc9e6c
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 16, 2010
@jColeChanged jColeChanged I added a plugin which seaches through clojure.core's functions to fi…
…nd a function which, given the users supplied inputs, returns the users supplied outputs. Much thanks to amalloy, he helped tremendously at every stage.
ae065f3
@amalloy amalloy Move findfn into the clojure plugin, and make it search several of th…
…e core namespaces
da4fcae
Showing with 43 additions and 2 deletions.
  1. +43 −2 src/sexpbot/plugins/clojure.clj
View
45 src/sexpbot/plugins/clojure.clj
@@ -5,7 +5,11 @@
[sexpbot.utilities :only [verify transform-if on-thread]]
[sexpbot.plugins.shorturl :only [is-gd]]
[sexpbot.gist :only [trim-with-gist]])
- (:require [clojure.string :as string :only [replace]])
+ (:require [clojure.string :as string :only [replace]]
+ ; these requires are for findfn
+ clojure.string
+ clojure.set
+ clojure.contrib.string)
(:import java.io.StringWriter
java.util.concurrent.TimeoutException
(java.util.regex Pattern)))
@@ -136,6 +140,32 @@ Return a seq of strings to be evaluated. Usually this will be either nil or a on
trimmed)) " " (execute-text bot-name user f protocol)))
forms))))
+(def findfn-ns-set
+ (map the-ns '#{clojure.core clojure.set clojure.string
+ clojure.contrib.string}))
+
+(defn fn-name [var]
+ (symbol (string/join "/"
+ ((juxt (comp ns-name :ns)
+ :name)
+ (meta var)))))
+
+(defn find-fn
+ [in out]
+ (map (comp fn-name second)
+ (filter
+ (fn [x]
+ (try
+ (= out
+ (binding [*out* java.io.StringWriter]
+ (apply
+ (if (-> (second x) meta :macro)
+ (macroexpand `(second x))
+ (second x))
+ in)))
+ (catch Exception _ false)))
+ (mapcat ns-publics findfn-ns-set))))
+
(defplugin
(:hook
:on-message
@@ -159,4 +189,15 @@ Return a seq of strings to be evaluated. Usually this will be either nil or a on
(fn [{:keys [com bot channel args] :as com-m}]
(if-let [line-url (get-line-url (first args))]
(send-message com-m (str (first args) " is " line-url))
- (send-message com-m "Source not found.")))))
+ (send-message com-m "Source not found."))))
+
+ (:cmd
+ "Finds the clojure fns, which given your input, produce your ouput."
+ #{"findfn"}
+ (fn [{:keys [bot args] :as com-m}]
+ (let [[user-in user-out :as args] (with-in-str (string/join " " args)
+ [(read) (read)])]
+ (send-message com-m (-> `(find-fn ~user-in ~user-out)
+ sb
+ vec
+ str))))))

No commit comments for this range

Something went wrong with that request. Please try again.