Last active
January 4, 2016 14:59
-
-
Save dkinzer/8637554 to your computer and use it in GitHub Desktop.
Multiple steps in a (do..) expression do not have the same effect as a (doseq...) that look like they should behave the same way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; repl-options init using (do) form | |
; Wrapping the individual (ns...) expressions in a (do) form results in | |
; the expected behavior; the REPL recognizes functions defined in koan-engine.core etc. | |
(defproject clojure-koans "0.5.0-SNAPSHOT" | |
:repl-options { | |
:init-ns koan-engine.runner | |
:init (do | |
(ns koans.12-creating-functions (:use koan-engine.core)) | |
(ns koan-engine.runner (:use koan-engine.core)))) | |
; repl-options :init using (doseq) form | |
; In this cqse when I load the repl from inside the project, | |
; the repl does not recognize functions in koan-engine.core or others. | |
; Note: wrapping with do (i.e. (do (doseq...)) does not change behavior. | |
; Neither does (doall... (for..)) | |
(defproject clojure-koans "0.5.0-SNAPSHOT" | |
:repl-options { | |
:init-ns koan-engine.runner | |
:init | |
(doseq [n [`koans.02-lists `koan-engine.runner]] | |
(ns n (:use koan-engine.core)))) | |
; Simply adding the (ns) expressios directly to the koans files only works halfway. | |
; The file doesn't throw on being able to evaluate the symbol meditations; but does throw | |
; on trying to evaluate any other sub-expression.... | |
; However, the following works. Add two namespace expressions to top of koan files... | |
; The order matters (why?) | |
(ns koan-engine.runner) | |
(ns koans.01-equalities (:use koan-engine.core)) | |
; The following does not work; even though it looks like it should. | |
; It's a variation of something I saw on StackOverflow: | |
; http://stackoverflow.com/a/5261744/256854 | |
(defproject clojure-koans "0.5.0-SNAPSHOT" | |
:repl-options { | |
:init-ns koan-engine.repl | |
:init (init-namespace) | |
; init-namesapce eventually run the followign code. | |
; That looks like it should work right? | |
(defmacro build-ns-koans | |
"Wraps multiple (ns) expressions for the koans with a (do) form." | |
[koans] | |
(cons 'do | |
(for [n koans] | |
`(ns ~n (:use koan-engine.core))))) | |
; Fortunately the following works too. | |
(defproject clojure-koans "0.5.0-SNAPSHOT" | |
:repl-options { | |
:init-ns koan-engine.repl | |
:init (init-namespace-2) | |
; Where (init-namespace-2) is defined as: | |
(defn init-namespace-2 [] | |
(do | |
(ns koans.12-creating-functions (:use koan-engine.core)) | |
(ns koan-engine.runner (:use koan-engine.core)))) | |
; Just for kicks I tried the following, which does not work either. | |
(def koans-filenames (get-koan-filenames (:koan-root default-koan-map))) | |
(def koans-ns (get-koan-ns-from-filenames koans-filenames)) | |
(defn do-ns-koans | |
[] | |
(doseq [n koans-ns] | |
(ns n (:use koan-engine.core)))) | |
; OK the thing that finally worked was to call this: | |
(def koans-filenames (get-koan-filenames (:koan-root default-koan-map))) | |
(def koans-ns (get-koan-ns-from-filenames koans-filenames)) | |
(defmacro do-ns-koans | |
"Wraps multiple (ns) expressions for the koans with a (do) form." | |
[] | |
(cons 'do | |
(for [n (apply vector koans-ns)] | |
`(ns ~n (:use koan-engine.core))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment