Skip to content

Instantly share code, notes, and snippets.

package drools
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
import example.drools.*;
@mrrodriguez
mrrodriguez / gist:8046814
Last active December 31, 2015 21:29
Macro returning fn objects with closures
;;; case 1
(defn get-map-of-fn [x] (fn [] x))
;= #'user/get-map-of-fn
(defmacro map-of-fn [arg] (get-map-of-fn arg ))
;= #'user/map-of-fn
(map-of-fn 1)
;= #<user$get_map_of_fn$fn__9648 user$get_map_of_fn$fn__9648@47020d4>
I have some Clojure clj files in a jar called A.jar.
This jar is started up, and I see that all of the clj files are loaded by the Application ClassLoader, along with the rest of the classes in the jar.
At runtime a new jar is added to the classpath, with some clj files that `require`s some of the clj files already loaded by the App ClassLoader.
What I have observed is that, when this newly added jar's clj files are being loaded, the `require`s they have on already loaded clj classes, are causing them to be reloaded.
The issue is that if these files that are reloaded, have something like `defrecord` in them, they load a new "version" of the same class, with a different classloader.
user> (defrecord MyRec [x])
user.MyRec
user> (def m (->MyRec 5))
#'user/m
user> (instance? MyRec m)
true
user> (eval (defrecord MyRec [x]))
user.MyRec
user> (def m2 (->MyRec 5))
#'user/m2
@mrrodriguez
mrrodriguez / gist:5498087
Last active December 16, 2015 21:10
Personal Emacs configuration.
(setq mac-option-modifier 'control)
(setq mac-command-modifier 'meta)
;; fix the PATH variable
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -i -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))