2011-02-13
| 00:02 | _Vi | (defmacro qqq [] '(method-name [this] "qqq")) (reify Qqq (qqq)) ;; NullPointerException How to use macros inside reify/defobject? |
| 00:08 | _Vi | In general, how to feed output of my macros to a system macros (without of writing a wrapper). |
| 00:08 | _Vi | s/\./?/ |
| 00:08 | sexpbot | <_Vi> In general, how to feed output of my macros to a system macros (without of writing a wrapper)? |
| 00:12 | _Vi | How to make my macros stronger than usual macros and expand before usual macros see it? |
| 00:28 | _Vi | (deftype Qqq [var1] ...) ;; How to mention "var1" in macro? It says it not found in the namespace. Also referring it by #' fails. |
| 00:40 | jkdufair | how would i evaluate a string representation of a class name to a class |
| 00:42 | incandenza | (Class/forName "...") perhaps |
| 00:44 | jkdufair | thank you! |
| 00:44 | incandenza | np |
| 00:54 | alex_boisvert | n00b question: I want call "max" on a list |
| 00:54 | alex_boisvert | e.g. |
| 00:54 | alex_boisvert | (def xs [ 1 2 3]) |
| 00:54 | alex_boisvert | (max xs) ; doesn't work, need to splat the list; don't know how .. |
| 00:54 | brandnewmath | clj |
| 00:54 | gregh | (apply max xs) |
| 00:54 | brandnewmath | ...doh, sorry |
| 00:55 | alex_boisvert | gregh: ah, ok, thanks! |
| 03:59 | kumarshantanu | is there a shorter way to transform keys in a map than this? -- (zipmap (map transform-fn (keys m)) (vals m)) |
| 04:00 | brehaut | (into {} (map (fn [[k v]] [(transform k) v]) m)) |
| 04:02 | replaca | (into {} (for [[k v] m] [(transform k) v]) |
| 04:02 | replaca | by a few chars :) |
| 04:04 | kumarshantanu | berhaut: replace: which is supposed to be faster? |
| 04:04 | replaca | kumarshantanu: dunno. I think they're about the same |
| 04:04 | brehaut | ((comp (partial into {}) (partial map (juxt (comp inc first) (comp transform-fn second)))) m) |
| 04:05 | replaca | brehaut: now you're just being whacky! |
| 04:05 | brehaut | church of point free! |
| 04:06 | replaca | yeah, in haskell it would be beautiful :) |
| 04:06 | brehaut | yeah sadly not so much here |
| 04:07 | Scriptor | haskell, in theory at least, curries every function call, so it's natural :) |
| 04:08 | brehaut | i think that map is a tiny bit faster than for but the difference is less important than the readability |
| 04:09 | brehaut | kumarshantanu: if you really need to know how fast something is |
| 04:09 | brehaut | use time and dotimes |
| 04:09 | kumarshantanu | brehaut: replaca: i am writing a function to do this, so i guess i will go for performance |
| 04:09 | replaca | no - I'd love to see a syntax that combined what was beautiful in clojure with what was beautiful in haskell. Rich made some compelling arguments one night about why he though it wasn't possible |
| 04:09 | brehaut | kumarshantanu: that is basicly entirely the wrong answer |
| 04:09 | replaca | kumarshantanu: I'm with brehaut on this one :) |
| 04:10 | replaca | unless it's in an inner loop, the difference won't matter |
| 04:10 | brehaut | kumarshantanu: hard numbers and real stats after profiling, or use the nice code |
| 04:10 | kumarshantanu | you guys mean i should prefer readability even if i am wrapping this inside a function? |
| 04:10 | replaca | yup |
| 04:10 | brehaut | absolutely |
| 04:11 | replaca | in 6 months when you look at your code again to debug it, the quickness that you can absorb it with would be most important |
| 04:11 | kumarshantanu | hmm |
| 04:11 | replaca | if it were a 2x difference, then performance *might* be the deciding issue |
| 04:12 | kumarshantanu | i meant to say -- i am writing a function 'map-keys' that will do just this -- but yeah readability is a bigger gain since the perf difference will be tiny |
| 04:12 | replaca | but unless it's in an inner loop, it's unlikely to make more than a couple tenths of a percent difference in your runtime. |
| 04:13 | kumarshantanu | i agree |
| 04:13 | replaca | I found "for" to be very unreadable when I came to Clojure, but it's long since been second nature |
| 04:14 | brehaut | replaca: where did you come from? |
| 04:14 | replaca | everywhere :) |
| 04:14 | brehaut | haha |
| 04:15 | replaca | of course I'd used list comprehension in Python before but something about the difference in the form blocked the mapping in my brain for a couple of months |
| 04:15 | brehaut | kumarshantanu: heres a question: why do you think there is no map-keys in the standard lib? |
| 04:15 | replaca | map is the same as most every language that has it (esp. CL), so it was easy |
| 04:16 | brehaut | replaca: huh thats really interesting |
| 04:17 | replaca | yeah, dunno why. It seems so obvious now that the block is broken |
| 04:20 | LauJensen | Morning guys |
| 04:20 | brehaut | Morning Lau |
| 04:22 | Scriptor | morning LauJensen |
| 05:25 | _ulises | morning |
| 05:29 | _ulises | anybody doing hadoop stuff with clojure? anybody got any recommendations regarding which libs to use, etc.? |
| 05:32 | LauJensen | _ulises: I blogged about one lib, 1) http://bestinclass.dk/index.clj/2010/01/hadoop-installation.html 2) http://bestinclass.dk/index.clj/2010/01/hadoop-feeding-reddit-to-hadoop.html |
| 05:33 | _ulises | thanks LauJensen :) |
| 05:33 | _ulises | I was just trying to run the examples of the clojure-hadoop lib (alex ott's fork) but I get weird errors unfortunately, will read your posts, ta |
| 05:39 | cpfr | _ulises, cascalog |
| 05:39 | _ulises | cpfr: I did see that one, however I want to do plain hadoop for the moment but thanks anyway |
| 06:09 | _ulises | is any of the clojure-hadoop libs on clojars the preferred one? according to LauJensen's post they are broken? |
| 06:10 | cpfr | i used stuart's lib |
| 06:25 | _ulises | right, I tried one of the forks but it didn't quite work for me; perhaps I should try Stuart's lib then |
| 07:14 | xkb | hello |
| 07:14 | xkb | Is anyone here using clj-oauth with delicious? |
| 08:16 | bulters | g'day all |
| 08:48 | _ulises | does anybody know how I can pass -XmxNNN to lein swank? |
| 08:50 | _ulises | ah, found it, nm |
| 08:54 | Dranik | _ulises, how did you manage that? |
| 08:54 | _ulises | Dranik: JVM_OPTS=-Xmx1024M lein swank |
| 08:55 | _ulises | from https://github.com/technomancy/leiningen/blob/stable/resources/script-template |
| 08:55 | Dranik | thanks |
| 08:56 | _ulises | np |
| 09:12 | _ulises | hrm, I'm having a hard time making this clojure-hadoop thing work. If I run from the repl (run job) (where job was defined with defjob as per the wordcount examples) the jobs run fine, but the minute I try running a job from the command line with java -cp it all blows up, anybody got experience with this lib and is willing to give me a hand? :) |
| 09:15 | raek | is there any documentation for the contract of the .equiv method of clojure.lang.IPersistentCollection? |
| 09:48 | khaliG | is there a way to wrap a var on a struct? |
| 09:55 | khaliG | dont know if my last message went through but i'm wondering if it's possible to wrap a Var on a struct. Otherwise i'm guessing you'd have to use an atom and access the fields in a sync block thing. |
| 09:57 | Cozey | is there something like (get-in ) but for vectors as well? |
| 09:59 | opqdonut | get-in works for vectors |
| 09:59 | opqdonut | ,(get-in [[0 1 2] [3 4 5]] [1 1]) |
| 09:59 | clojurebot | 4 |
| 10:03 | raek | khaliG: what do you mean by "wrap a Var on a struct"? |
| 10:03 | raek | could you give an example on what you want to do? |
| 10:04 | khaliG | i mean (ref <a-struct>) |
| 10:04 | Chousuke | and? |
| 10:04 | Chousuke | that works just fine |
| 10:04 | Chousuke | though in most use cases you'll probably want a record instead of a struct |
| 10:05 | khaliG | ok |
| 10:06 | Chousuke | though I'm suspicious now. are you sure you need refs at all? |
| 10:07 | Chousuke | using refs just because you think you need to mutate something is usually wrong :) |
| 10:07 | khaliG | it's possible i'm wrong :) |
| 10:07 | Chousuke | that is, there might be a solution that doesn't require mutation at all |
| 10:07 | Chousuke | and you should prefer those |
| 10:08 | Chousuke | The less "mutable" elements your design contains, the easier life will be. |
| 10:08 | Chousuke | hmm, fewer* |
| 10:08 | khaliG | understood, though i dont know if i could do this without mutation, i'm accumulating some values |
| 10:09 | Chousuke | reduce? |
| 10:09 | raek | sounds like a job for reduce |
| 10:09 | Chousuke | your accumulator does not have to be mutable |
| 10:11 | khaliG | yea let me think but my gut feelign is it's not possible to do without mutation here |
| 10:11 | Chousuke | describe what you're trying to do and maybe we can help |
| 10:12 | khaliG | Ok. i have an exercise model which consists of tables of values for each exercise (sets, reps weight etc), and a workout model which consists of exercises and a few other datums. The data is entered by the user via a Swing UI, and i store the imputs in clojure structs and vectors |
| 10:13 | khaliG | could i do away with mutation or do i need to provide more information? |
| 10:13 | Chousuke | so you need to update the models? |
| 10:13 | khaliG | correct |
| 10:13 | Chousuke | right, for that part, you'll need a ref or something |
| 10:14 | Chousuke | but that's only for the final storing of the updated value |
| 10:14 | Chousuke | most of the related code you can write without mutation |
| 10:14 | khaliG | yes i have written it that way :) |
| 10:14 | Chousuke | sounds like you're on the right track then |
| 10:15 | khaliG | atm i have this call (send data conj model) which would work fine if data was a vector, but its not a struct and that's where i got stuck |
| 10:15 | Chousuke | you can use update-in |
| 10:15 | khaliG | it worked fine before though as long as my data was in that vector (data) |
| 10:15 | khaliG | ooh, let me read about update-in |
| 10:15 | Chousuke | (send data update-in [:key] conj whatever) |
| 10:15 | khaliG | that sounds perfect! |
| 10:16 | Chousuke | I like the chaining aspect of update functions |
| 10:17 | khaliG | i was unwittingly seeking somethign like that, now that've mentioned it |
| 10:17 | Chousuke | there's also assoc-in |
| 10:17 | khaliG | thank you |
| 10:21 | bulters | what's the current-easiest-way of doing the whole emacs-clojure-repl dance these days? |
| 10:21 | bulters | I keep losing track of which guide to read ;-) |
| 10:22 | khaliG | bulters, on which platform? |
| 10:22 | bulters | os x |
| 10:23 | khaliG | not sure about os x, but linux was painless using the emacs package installer thing. i had problems on windows though |
| 10:24 | _ulises | bulters: do you mean installing or running/devving? |
| 10:24 | bulters | _ulises: well, already got clojure installed (via leiningen) |
| 10:25 | _ulises | I usually add swank-clojure to my :dev-dependencies |
| 10:25 | _ulises | and I just discovered a super-neat trick of leiningen, which is to have a checkouts/ dir in your project with symlinks to other projects you're hacking in parallel |
| 10:26 | _ulises | leiningen picks those up automatically so you don't need to restart your swank server, etc. etc. |
| 10:26 | bulters | And I guess installing the swank-clojure and slime packages might help as well... |
| 10:27 | _ulises | yup, that's how I do it. I've tried eclipse but I'm sort of used to using emacs in my daily routine so... |
| 10:27 | khaliG | pretty much, and then you start swank in your clojure project, and M-x slime-connect in emacs |
| 10:27 | bulters | _ulises: you add them as git (or s/ by your favorite scm) submodules? |
| 10:27 | _ulises | bulters: atm I'm issuing lein jar as I'm testing launching my app through java |
| 10:27 | _ulises | and that rebuilds the dependencies, etc. |
| 10:29 | bulters | cool |
| 10:30 | _ulises | if I have an fn [ args ] how can I detect if args is iterable/seqable? say I can either pass it a map or an fn? |
| 10:30 | _ulises | there's fn? for that, but for maps? |
| 10:31 | bulters | oh this is nice... :D thanks for the quick pointer... |
| 10:31 | _ulises | ,(doc map?) |
| 10:31 | clojurebot | "([x]); Return true if x implements IPersistentMap" |
| 10:31 | _ulises | bleh |
| 10:31 | _ulises | bulters: sure, np :) |
| 10:41 | rlb | I was looking at the tutorial posted here the other day (http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html), and for some reason, the POST handler isn't receiving any form arguments. They're {}. Any idea what I might be doing wrong? |
| 11:05 | raek | bulters: install clojure-mode, slime, slime-repl in emacs with package.el, :dev-dependencies [[swank-clojure "1.2.1"]] in project.clj, lein deps, lein swank and then M-x slime-connect from emacs |
| 11:06 | raek | most importantly: do not use the deprecated swank-clojure _emacs_ package |
| 11:07 | khaliG | hm so don't install swank-clojure at all? |
| 11:07 | khaliG | i've got 1.1.0 installed |
| 11:07 | raek | bulters: using technomancy's clojure-starter-kit gives you package.el with correct settings. see the docs on http://github.com/technomancy/swank-clojure/ |
| 11:07 | raek | khaliG: the clojure lib or the emacs package? |
| 11:07 | khaliG | emacs package |
| 11:07 | raek | no. |
| 11:07 | khaliG | oops, okay |
| 11:07 | raek | it is from pre-leiningen ties |
| 11:07 | raek | *times |
| 11:08 | raek | use durendal (another project of technomancy's) if you want a quick way of launching the swank server from emacs |
| 11:48 | bulters | raek: thanks, I've tried the starter kit; but decided to roll my own... part of the emacs learning process :P |
| 11:51 | bulters | durendal looks nice though... |
| 12:27 | xkb | Is anyone here using clj-oauth with delicious-api? |
| 12:28 | xkb | or anything requiring Authentication headers |
| 12:34 | thorwil | i'm trying to follow https://github.com/gcv/appengine-magic#readme. but how do i get into my applications core namespace on the repl? |
| 12:35 | raek | thorwil: you mean something like (in-ns 'the-namespace)? |
| 12:36 | thorwil | i guess with in-ns, but the right argument to not trigger a no-source eludes me |
| 12:36 | raek | (C-c M-p in emacs) |
| 12:36 | raek | ah, you need to load it first (require 'the-namespace) |
| 12:36 | raek | (C-c C-k in emacs) |
| 12:37 | raek | (doto 'the-namespace require in-ns) is a nice combo |
| 12:37 | thorwil | ah, not sure what "lein repl" does or doesn't, in that regard |
| 12:37 | thorwil | but i was also missing the ' |
| 12:37 | raek | all it does is to launch clojure with the correct classpath. it does not load any namespaces except clojure.core |
| 12:38 | raek | yeah, they are functions, so you have to quote the symbol. |
| 12:38 | raek | (unlike the corresponding :require and :use features of 'ns') |
| 12:38 | thorwil | i know in principal, but i'm just starting with my first lisp here ;) |
| 12:39 | thorwil | thanks! |
| 12:39 | raek | np. |
| 12:40 | xkb | aargh again wrong signature.. hmm oauth is bleh |
| 12:40 | raek | xkb: have you tried asking at the clojure or clojure-web-dev google groups? |
| 12:43 | xkb | raek: not yet, will keep on tinkering for about 1 hour. And if that fails, Ill ask :) |
| 12:43 | xkb | the fault is prob. in the encoding of the uri/params |
| 12:45 | raek | ring has some utility functions for param encoding in uris |
| 12:45 | khaliG | aw, slurp/spit wont work with Java Dates? :/ |
| 12:46 | raek | khaliG: they operate on strings |
| 12:46 | khaliG | k |
| 12:46 | raek | so you need to do the string <-> date conversion yourself |
| 12:46 | khaliG | understood |
| 12:46 | khaliG | its the only object remaining which isn't a readable string afaik |
| 12:47 | khaliG | (in my code i mean) |
| 12:47 | raek | for clojure data structure, you can just use read-string and pr-str |
| 12:48 | khaliG | nice |
| 12:48 | raek | spit will call str (which corresponds to java's toString method) on its argument, which does not work for all kinds of data |
| 12:49 | khaliG | seems Date has a toString method |
| 12:49 | khaliG | but i can't see a fromString |
| 12:49 | raek | ,(str (lazy-seq [1 2 3])) |
| 12:49 | clojurebot | "clojure.lang.LazySeq@7861" |
| 12:49 | raek | ,(pr-str (lazy-seq [1 2 3])) |
| 12:49 | clojurebot | "(1 2 3)" |
| 12:50 | khaliG | maybe i can use a different time structure, lets see if there are any clojure libs for that |
| 12:50 | raek | khaliG: Joda time is a much better lib for working with dates in java. the clojure port is called clj-time |
| 12:50 | khaliG | oh nice! |
| 12:52 | khaliG | hm perhaps i can just write my dates as longs and then read them back |
| 12:53 | khaliG | i'd rather not do any sort of marshalling though |
| 12:53 | khaliG | i'll explore jodatime |
| 12:53 | khaliG | thanks raek |
| 12:53 | raek | yeah, milliseconds since the epoch (in UTC time) as a long is a pretty universal representation |
| 13:35 | khaliG | i love how i'll make a change to a running swing program, move to restart it after making a change and realising i just need to recompile the changed method |
| 13:46 | pppaul | hey, i'm getting an error with spit |
| 13:46 | pppaul | java.lang.Exception: Cannot change an open stream to append mode.' |
| 13:46 | pppaul | i'm using conrtib/append-spit |
| 13:53 | raek | pppaul: is the file writable? also, you can use spit from clojure core since 1.2: (spit "file.txt" the-string :append true) |
| 13:53 | pppaul | oh, thanks |
| 13:53 | pppaul | that's much cleaner |
| 13:53 | pppaul | spit is making the file |
| 13:54 | pppaul | i'll change my code to your suggestion |
| 13:56 | pppaul | i don't get the error now |
| 14:53 | thorwil | is that normal that the repl in emacs doesn't react anymore after i started a jetty server (via appengine-magic)? |
| 14:56 | rlb | It looks like none of the :input parameters from the example are making it to the POST handler. Can I get jetty (or clojure) to be more verbose wrt the actual POST? |
| 14:56 | rlb | s/clojure/compojure/ |
| 14:56 | sexpbot | <rlb> It looks like none of the :input parameters from the example are making it to the POST handler. Can I get jetty (or compojure) to be more verbose wrt the actual POST? |
| 15:06 | brehaut | rlb is there a logging middleware you could use? |
| 15:13 | bobo | what is a good way to do something that should run every 5sek in clojure? should i use executors and such from java? |
| 15:15 | brehaut | (doto (Thread. (fn [] (while true (let [t (calc time now)] (do-action) (Thread/sleep (- 5000 (- now t))))))) .start) |
| 15:15 | brehaut | pretty blunt |
| 15:16 | brehaut | i guess you could use an agent |
| 15:16 | brehaut | instead of an explicit thread |
| 15:17 | bobo | Thread feels very blunt, then exexutors feels nicer |
| 15:20 | brehaut | (defn tick (agent nil)) (defn act [v] (do-something) (Thread/sleep 5000) (send tick act)) |
| 15:20 | brehaut | thats with agents and minus the math to make it a bit more precise |
| 15:20 | raek | bobo: there is a executor class for scheduling repeating tasks |
| 15:21 | raek | http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.html |
| 15:22 | raek | http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newScheduledThreadPool(int) |
| 15:22 | raek | bobo: also, cron4j works wonderfully when you need to schedule tasks as you would with unix cron |
| 15:23 | rlb | brehaut: don't know -- I was just trying the example posted here the other day. I'm not all that familiar with compojure/hiccup/ring/etc. yet. |
| 15:24 | rlb | the POST comes in, but :params is {}. |
| 15:25 | raek | thorwil: I don't know exactly how appengine-magic starts the jetty server, but if you start jetty manually, you can give it the :join? false option to not block until the server is shut down |
| 15:27 | raek | cron4j example (I just love how simple it is): |
| 15:27 | raek | (defonce scheduler (doto (it.sauronsoftware.cron4j.Scheduler.) (.schedule "30 16 * * 1-5" #'my-fn) (.start))) |
| 15:28 | raek | this executes my-fn 4:30 PM every monday-friday |
| 15:28 | bobo | raek: yeh i know they ar ein java :-) just thought if there was something nice in clojure. but il use the java stuff then |
| 15:28 | brehaut | rlb: what middleware do you have running? |
| 15:29 | _Vi | Why when I issue "(ns ...)" in REPL I lose access to "doc" function? |
| 15:29 | rlb | brehaut: ring.adapter.jetty? Starting it like this: (run-jetty #'main/app {:port 8080}) |
| 15:29 | brehaut | rlb thats your adapter rather than middleware |
| 15:29 | replaca | raek: do you have the leiningen :depends line for cron4j handy? |
| 15:30 | brehaut | i dont know of compojure automatically includes ring.middleware.params or similar |
| 15:30 | rlb | brehaut: Other than that, just using compojure and hiccup. See here: |
| 15:30 | brehaut | hiccup isnt relevant here |
| 15:30 | rlb | http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html |
| 15:31 | raek | bobo: well, I made a library that does some of these stuff (not the Scheduled vareity of executors though) by some pretty redundant functions: https://github.com/raek/lcug-concurrency/blob/master/src/se/raek/lcug/concurrency.clj#L208 |
| 15:31 | rlb | I adjusted the POST handler like this: (POST "/" x (prn x) ...) |
| 15:31 | raek | replaca: I found this: [org.clojars.ghoseb/cron4j "2.2.1"] |
| 15:31 | rlb | so I could see x, and I can see that params is {} |
| 15:32 | bobo | raek: il take a look! |
| 15:32 | raek | iirc, it wasn't in the maven repo, but someone had pushed it to clojars |
| 15:32 | rlb | (on stdout) |
| 15:32 | rlb | I just wondered if that example might be stale somehow, i.e. the form set up wrong or whatever... |
| 15:32 | raek | bobo: basically, all the fns look like this: (defn submit [exe task] (.submit exe task)) |
| 15:33 | brehaut | rlb im not an expert on compojure sorry |
| 15:33 | raek | I'm thinking about generating clojure/autodoc-style docs from javadocs |
| 15:33 | raek | so that people don't miss what's directly usable from java... |
| 15:34 | raek | bobo: also, did you see my post re executors in clojure? |
| 15:34 | brehaut | raek: that would be handy for the not-from-java people like me |
| 15:34 | bobo | raek: i dont think i did? |
| 15:34 | raek | http://blog.raek.se/2011/01/24/executors-in-clojure/ |
| 15:35 | rlb | brehaut: np, and thanks. |
| 15:37 | brehaut | rlb may i suggest putting together a simple middleware to print out the entire request before it goes into compojure? |
| 15:37 | brehaut | there is an example in the tutorial you are working through that shows how to install ring middleware with compojure |
| 15:38 | brehaut | your middleware will be approximately (defn log-request [handler] (fn [req] (prn req) (handler req))) |
| 15:53 | mreynolds | newb question : I'm doing (doseq (keys map) ...) and I'm getting this error : error: java.lang.IllegalArgumentException: doseq requires a vector for its binding (core.clj:12) |
| 15:53 | mreynolds | Do I have to wrap the returned seq in a vector (or convert it?)? |
| 15:54 | opqdonut | (doseq [k (keys map)] ...) |
| 15:54 | opqdonut | now the variable k will get bound to each key of the map in turn |
| 15:54 | mreynolds | duh |
| 15:54 | mreynolds | Thanks |
| 15:59 | thorwil | raek: seems :join? did the trick. strange how without, some operations work and other just hang there. thanks! |
| 16:00 | rlb | brehaut: ok, thanks again. |
| 16:15 | rlb | brehaut: post prints as {... "application/x-www-form-urlencoded" ... :body #<Input org.mortbay.jetty.HttpParser$Input@5f4f5a31>} |
| 16:18 | brehaut | rlb can you put the ring.middleware.params/wrap-params middleware in before your logging middleware? |
| 16:23 | rlb | brehaut: like this? (def app (-> #'handler (wrap-params) (log-request))) |
| 16:23 | rlb | |
| 16:24 | brehaut | swap wrap-params and log-request |
| 16:24 | shortlord | are there any simple RPC frameworks for clojure? (I just need something to call clojure functions remotely on client and server) |
| 16:25 | brehaut | shortlord: what kind of RPC? |
| 16:25 | raek | rlb: the last middleware will be the one that sees the request first and the response last |
| 16:25 | raek | moustache reverses this in its syntax |
| 16:26 | raek | ...since it becomes the outermost wrapping middleware |
| 16:27 | brehaut | shortlord: if its not for real work then i have an xml-rpc library that works with ring and provides both sides of the rpc stack, but i dont like xml-rpc and wouldnt recommend it for a real world system |
| 16:27 | shortlord | brehaut: I have an application that I need to split into a server and a client that renders the server contents and calls some server functions depending on user input. Nothing fancy, simply calling clojure functions remotely (both client and server are clojure-based) would be enough (similar to java RMI) |
| 16:28 | technomancy | shortlord: try clojure.contrib.server-socket/socket-repl |
| 16:28 | shortlord | brehaut: priority is not performance, but fast and easy integration into existing non-distributed code |
| 16:28 | technomancy | though I guess you would rather have socket-rep |
| 16:28 | rlb | brehaut, raek: thanks - that fixed it. I was starting with the first example on that page, and it doesn't use middleware (wrap-params, etc.). |
| 16:29 | brehaut | shortlord: github.com/brehaut/necessary-evil |
| 16:29 | brehaut | if technomancy's solution doesnt work for you |
| 16:29 | brehaut | shortlord: but i wouldnt recommend it |
| 16:30 | shortlord | brehaut: ok, thx a lot |
| 16:31 | shortlord | I've thought about using a simple remote repl, but it would be quite insecure to pass any kind of string and evaluate it. So I guess I would have to build a custom check that only allows the execution of predefined functions, right? Does something like that already exist? |
| 16:32 | brehaut | shortlord: if you use a repl yeah you'd have restrict it somehow. cljail might help there |
| 16:33 | brehaut | you need to explicitly expose functions with necessary-evil |
| 16:35 | shortlord | brehaut: searching for cljail does not give me any results, do you mean clj-sandbox? |
| 16:35 | brehaut | shortlord: honestly im not sure. whatever raynes and amalloy's project is called |
| 16:36 | brehaut | https://github.com/Raynes/clojail |
| 16:38 | mreynolds | More newbness : What's the idiomatic way to lookup data from nested maps? Like {:a {:b "b" :c "c"}}, where I want to get :c's value. |
| 16:39 | brehaut | ,(get-in [:a :c] {:a {:b "b" :c "c"}}) |
| 16:39 | clojurebot | nil |
| 16:39 | raek | making a custom interpreter for a limited command set (possibly using the clojure reader) sound much more secure |
| 16:39 | shortlord | brehaut: cool, thx a lot for the link |
| 16:40 | mreynolds | nice, thanks! |
| 16:40 | brehaut | ,(get-in {:a {:b "b" :c "c"}} [:a :b]) |
| 16:40 | clojurebot | "b" |
| 16:40 | brehaut | mreynolds: if i got it round the right way :P |
| 16:40 | mreynolds | brehaut: No worries, I'm still mapping out functions, so just having the pointer is good enough |
| 16:40 | brehaut | mreynolds: its part of a family including assoc-in and update-in |
| 16:41 | brehaut | mreynolds: clojuredocs.org/quickref/Clojure%20Core |
| 16:41 | mreynolds | brehaut: I'll go check those out. I bought clojure in action and joy of clojure and I've been piece-meal making my way through them. |
| 16:44 | mreynolds | brehaut: I sort of wish the clojure docs would have an alternate structure similar to how the code is laid out. I find myself looking at the source often and seeing the functions that are "similar" to that function (as you mentioned, assoc-in and update-in are right next to each other), but aren't in the docs |
| 16:47 | brehaut | mreynolds: projects using marginalia have that |
| 16:47 | mreynolds | brehaut: Haven't used that yet, I'll go look at it |
| 17:14 | mreynolds | Similar question : I'm building a data structure to allow people to specify files to "watch" in special ways. I was building nested data structures ({:stuff {:type "dir", :other-type "otherdir}}) and get-in let me get those nested pieces of data easily. I now want to, basically, walk the data structure, looking at the "dir"s and replace them with actual File objects. I thought about doing this with zippers, but I wanted to ask |
| 17:16 | chouser | zippers would work |
| 17:17 | chouser | mreynolds: you might also try clojure.walk |
| 17:17 | mreynolds | chouser: I'll look at both, thanks for the pointers |
| 17:18 | mreynolds | chouser: Walk looks pretty damned perfect |
| 17:18 | mreynolds | chouser: Thanks |
| 17:18 | chouser | np |
| 18:00 | replaca | raek: belated thank you! |
| 18:03 | rata_ | hi |
| 18:07 | aleksander | hi |
| 18:09 | michaeljaaka | hi |
| 18:09 | michaeljaaka | is there anyone live? |
| 18:10 | brehaut | michaeljaaka: probably |
| 18:10 | michaeljaaka | :) thanks, I thought that i have something wrong configuration |
| 18:10 | michaeljaaka | no welcome message, no activity messages |
| 18:10 | michaeljaaka | etc. |
| 18:48 | _Vi | Is there somewhere official use case lists for Atoms, Agents and Refs? E.g. a task where only Atom suits (but not Agent or Ref), a task for Agent... |
| 18:50 | jacortinas | _Vi: afraid not, but that would be pretty awesome resource |
| 18:52 | _Vi | For example logging somewhere from multiple threads. Agents are OK, but atoms and refs are likely not. |
| 19:08 | gfrlog | I wonder if agents are implemented with atoms |
| 19:26 | _Vi | Why "alter" and "send" do not end with exclamation point, but "swap!" does? |
| 19:27 | pdk` | it's just a typical little idiosyncracy i guess |
| 19:27 | _Vi | Having trailing "!" makes feeling of some unsafety. |
| 19:28 | pdk` | i dunno why there can't just be some sort of update! function that works on refs/atoms/agents all alike |
| 19:28 | Chousuke | alter and send are safe in dosync |
| 19:28 | pdk` | maybe have a keyword arg for it when you need send-off style behavior or something |
| 19:28 | Chousuke | swap! isn't |
| 19:29 | _Vi | When I writing my own functions, when should I finish their names with "!"? Is there some convention there? |
| 19:31 | pdk` | ! implies that the function is destructive or carries side effects beyond returning a value |
| 19:32 | pdk` | it's an old convention from scheme where the functions that did destructive stuff with lists had ! |
| 19:32 | pdk` | and since refs/agents/atoms are the only mutable forms of data you'll be working with often in clojure outside of java interop well |
| 19:33 | _Vi | pdk`, For example, should some "printDebugLog" be "printDebugLog!"? |
| 19:33 | pdk` | it doesn't seem necessary there |
| 19:33 | pdk` | though note that lisp function naming convention would favor print-debug-log over printDebugLog |
| 19:34 | Chousuke | well actually |
| 19:34 | _Vi | Is the rule like "put ! if it have side effects and it is not obvious"? |
| 19:34 | Chousuke | the convention is to use ! if the function is unsafe in dosync and it's not obvious |
| 19:34 | pdk` | you'd be fine with that route i think |
| 19:35 | pdk` | in scheme ! was basically a warning that the function you were using could modify the list you passed to it in-place without any other advance warning |
| 19:35 | Chousuke | eg. spit etc. are unsafe, but it's obvious so there is no bang |
| 19:35 | _Vi | (BTW should it be "unsafely-check-some-condition?!" or "unsafely-check-some-condition!?") |
| 19:35 | pdk` | and in clojure none of the basic data structures are mutable outside of storing them in refs/agents/atoms |
| 19:36 | Chousuke | but swap! has the bang because you might not think that it's unsafe in dosync forms |
| 19:36 | Chousuke | _Vi: have two functions? :P |
| 19:36 | Chousuke | (predicate? (some-unsafe-stuff!)) |
| 19:37 | _Vi | Chousuke, Means the "predicate" with side effects. |
| 19:37 | Chousuke | predicates shouldn't have side-effects :/ |
| 19:37 | pdk` | the idea he's getting at is to have a function that does the unsafe stuff and returns some value |
| 19:37 | pdk` | then checking that value against a safe predicate |
| 19:38 | _Vi | Also: Should I consider the function side effects free if it actually have debug-only side effects (such as printing in some log or incrementing statistics counter)? |
| 19:38 | Chousuke | no |
| 19:39 | Chousuke | unless you can disable that behaviour in production code |
| 19:39 | _Vi | For example, when debugging is switched off (release version) it becomes truly side-effects-free. |
| 19:40 | Chousuke | you'll get some funky debug output if you use such functions in transactions though :) |
| 19:40 | dnolen | _Vi: ! is really to indicate changing a "place" in a way that that doesn't specify any "time management" strategy. alter doesn't need it, they are inside dosync. agents imply uncoordinated concurrency. |
| 19:41 | Chousuke | dosync handles sends specially, which is why send doesn't have the bang |
| 19:43 | pdk` | i wouldn't bother if it doesn't change anything that's relevant to an outside caller of the function |
| 19:43 | pdk` | if it's closed over some counter that's just there for debugging and doesn't affect the behavior of any functions or modify other outside state then whatever basically |
| 19:46 | Chousuke | well, yeah. |
| 19:46 | Chousuke | as long as the side-effect is inconsequential to the program it's fine I guess :P |
| 19:47 | _Vi | Chousuke, So I can add "invocation counter" statistics without fear being bad guy. |
| 19:47 | _Vi | s/fear/fear of/ |
| 19:47 | sexpbot | <_Vi> Chousuke, So I can add "invocation counter" statistics without fear of being bad guy. |
| 19:48 | Chousuke | _Vi: it's just a bit dirty, but I guess you can. |
| 19:48 | Chousuke | _Vi: at least use a macro or something you can easily disable :) |
| 19:49 | Chousuke | then when you ship a release version, just define the macro to return nil or something :P |
| 19:49 | Chousuke | in essence making it a comment |
| 19:55 | _Vi | What should I do if I want to have a macro that expands in two (or more) forms? (and I cannot use "(do ...)" because of it is not a code) |
| 19:56 | brehaut | _Vi, use do |
| 19:56 | _Vi | brehaut, This is not a code. It is either data or some internals of "reify" or "let" or whatever. |
| 19:57 | brehaut | then use functions |
| 19:58 | _Vi | The only not-so-nice solution I see is to wrap containing for in macros that will handle this duplication. |
| 19:59 | johnhunter | hi, I have a noob question |
| 19:59 | brehaut | johnhunter: you are welcome to ask it |
| 20:00 | johnhunter | thanks, i am writing a swing app, and i want in a text field to let the user write some clojure code - a dsl if you will |
| 20:00 | johnhunter | when I get the text, i call (eval text) |
| 20:01 | johnhunter | it seems eval runs from the clojure.core namespace, not my app's namespace |
| 20:01 | johnhunter | so none of my def'd data values are found |
| 20:01 | _Vi | johnhunter, Example: |
| 20:01 | _Vi | (eval (read (java.io.PushbackReader. (java.io.StringReader. "(+ 4 5)")))) |
| 20:02 | johnhunter | yes, thanks, that is roughly what i am doing, and it works for (+ 4 5) |
| 20:02 | brehaut | johnhunter: there is a with-ns function defined somewhere |
| 20:03 | johnhunter | oh.. let me look that one up |
| 20:03 | brehaut | just cant workout where 'somewhere' is |
| 20:04 | johnhunter | http://richhickey.github.com/clojure-contrib/with-ns-api.html |
| 20:04 | brehaut | that would be it |
| 20:07 | johnhunter | the only thing is eval seems to start from clojure.core, and it knows nothing about with-ns from contrib |
| 20:07 | johnhunter | i'm very fuzzy on all this namespace stuff |
| 20:07 | brehaut | i would have assumed that (with-ns namespace (eval ...)) would have fixed that? |
| 20:07 | brehaut | alternatively |
| 20:08 | johnhunter | oh, i think you might be right... i just have to include that contrib in my main app |
| 20:08 | johnhunter | i'll try that, thanks |
| 20:08 | brehaut | (eval (concat (list with-ns namespace exp))) |
| 20:08 | brehaut | wait madenes |
| 20:08 | brehaut | (eval (list 'with-ns namespace exp)) |
| 20:09 | philipo | clojure |
| 20:18 | johnhunter | it doesn't seem to resolve with-ns shouldn't i get it by including clojure-contrib in my project.clj like ... :dependencies [[org.clojure/clojure "1.2.0"] |
| 20:18 | johnhunter | [org.clojure/clojure-contrib "1.2.0"]] |
| 20:18 | brehaut | have you got a use or require in your ns? |
| 20:18 | johnhunter | :require |
| 20:20 | johnhunter | how do i check if it is in clojure.contrib 1.2? |
| 20:20 | brehaut | are you referencing with-ns with the fully qualified project? |
| 20:20 | brehaut | it is |
| 20:21 | johnhunter | nope, just (with-ns myns.core (eval ....) |
| 20:21 | brehaut | there you go then; with a require you need to qualify any functions in that namespace |
| 20:21 | brehaut | so if you have bare require, you need clojure.contrib.with-ns/with-ns |
| 20:21 | brehaut | if you have an :as require |
| 20:22 | johnhunter | ah... |
| 20:22 | brehaut | (eg (:require [clojure.contrib.with-ns :as with-ns])) |
| 20:22 | brehaut | you do just with-ns/with-ns |
| 20:22 | johnhunter | and what if i just want to call (with-ns ... ? |
| 20:22 | johnhunter | :use ? |
| 20:22 | brehaut | use use |
| 20:23 | brehaut | IMO - dunno if its considered idiomatic - you should prefer requires to uses, and if you do decided to use a use, you should qualify all the imports with only |
| 20:23 | johnhunter | ok, for some reason this namespace stuff won't stick in my brain |
| 20:23 | brehaut | eg (:use [clojure.contrib.with-ns :only [with-ns]]) |
| 20:25 | brehaut | i generally use aliased requires except for some operators or forms that are cleaner (and clear where they from) when used |
| 20:43 | gfrlog | brehaut: now that I've waited a day, do I get to hear what you were thinking of? |
| 20:43 | brehaut | declare |
| 20:43 | brehaut | perhaps with a with-ns ? |
| 20:43 | gfrlog | yes, I think that would do it |
| 20:44 | gfrlog | I tried it with a fully qualified symbol but I don't think that works |
| 20:44 | brehaut | however, given ive had a day, i think that probably i was wrong given your requirement to declare something in another ns |
| 20:44 | gfrlog | wrong how? |
| 20:44 | gfrlog | that hiredman wasn't thinking of that? |
| 20:44 | brehaut | that it might not work? |
| 20:44 | brehaut | both |
| 20:45 | gfrlog | I'll see if it works... |
| 20:45 | brehaut | hiredman is much better at this than i am |
| 20:45 | brehaut | absolutely worth a shot |
| 20:45 | gfrlog | do you think either you or him were suggesting that it's better code than my eval version? Or just that eval isn't strictly necessary? |
| 20:46 | brehaut | using eval is a fairly good sign somethings been overlooked |
| 20:46 | brehaut | its more of an implementation tool than a usage tool |
| 20:46 | gfrlog | so you prefer several lines of non-eval code over one line of eval code? |
| 20:46 | brehaut | yeah typically |
| 20:47 | brehaut | im not convinced you should need to fire up the compiler for small things |
| 20:47 | brehaut | those couple of lines could be abstracted to declare-with-ns or soemthing and become a library function |
| 20:47 | tomoj | how do you avoid eval? |
| 20:47 | gfrlog | that's a good point |
| 20:48 | gfrlog | tomoj: apparently by using with-ns and declare |
| 20:48 | gfrlog | but actually I'm sure that wildly depends on what you're using it for |
| 20:48 | brehaut | tomoj: thats a guess on my part. i think hiredman was sure of a good way to do it though |
| 20:48 | gfrlog | ,(eval "2893") |
| 20:48 | clojurebot | DENIED |
| 20:48 | gfrlog | ,(Integer. "2893") |
| 20:48 | clojurebot | 2893 |
| 20:49 | brehaut | yeah your not going to get to execute arbitrary code in the bots |
| 20:49 | gfrlog | (eval '(println "DENIED")) |
| 20:49 | gfrlog | ,(eval '(println "DENIED")) |
| 20:49 | clojurebot | DENIED |
| 20:49 | brehaut | haha |
| 20:49 | tomoj | there were ways with sexpbot recently |
| 20:50 | tomoj | there may still be |
| 20:50 | gfrlog | brehaut: I had not thought of what I was doing as "firing up the compiler" until you put it that way |
| 20:51 | gfrlog | now I am a better man |
| 20:51 | brehaut | bbs coffee |
| 20:52 | tomoj | how would either of with-ns or declare help? |
| 20:54 | gfrlog | tomoj: that was specific to my case |
| 20:55 | gfrlog | for your question, you have to show how you're using eval first |
| 20:55 | tomoj | I believe I remeber your case |
| 20:55 | gfrlog | okay, well for my case... |
| 20:55 | tomoj | and don't see how it would help |
| 20:55 | gfrlog | he thought that the specific var whose value I wanted to execute could be created before the library is loaded |
| 20:56 | gfrlog | by... (with-ns 'my.namespace (declare go)) |
| 20:56 | gfrlog | I just tried that on my code and got strange results |
| 20:57 | tomoj | I didn't actually remember your case |
| 20:57 | gfrlog | so apparently it doesn't do the same thing as ((var-get (find-var 'my.namespace/go))) |
| 20:57 | tomoj | since you were talking about eval too I thought you were the one eval'ing gui input |
| 20:57 | gfrlog | oh, no |
| 20:57 | gfrlog | my case is from yesterday |
| 20:57 | gfrlog | I have a program where most of the code is loaded at runtime |
| 20:58 | gfrlog | the entry point to that code is where I call (my.namespace/go) |
| 20:58 | gfrlog | but the compiler won't let me do that since it doesn't know about the namespace yet |
| 20:58 | gfrlog | so I was doing (eval '(my.namespace/go)) |
| 20:58 | gfrlog | which worked just fine |
| 20:58 | gfrlog | but offended everybody's sense of decency |
| 20:58 | tomoj | right, I see |
| 20:59 | gfrlog | I'm still doing the (find-var) thing |
| 21:04 | rata_ | gfrlog: I think it's not the compiler that doesn't know about the namespace |
| 21:04 | gfrlog | rata_ my being wrong would not surprise me, as the whole issue of the clojure compiler gets me fogged up -- what would you say that it is? |
| 21:05 | rata_ | the evaluator |
| 21:05 | rata_ | (if that's the name for what executes your code at runtime) |
| 21:05 | gfrlog | hmm |
| 21:06 | gfrlog | but my code should work at the time it's evaluated |
| 21:06 | rata_ | and I thought yesterday hiredman was referring to the (intern ns name) fn |
| 21:06 | gfrlog | ,(doc intern) |
| 21:06 | clojurebot | DENIED |
| 21:06 | gfrlog | ew |
| 21:06 | rata_ | do you get your error when compiling your code? |
| 21:06 | gfrlog | "lein compile" you mean? |
| 21:06 | rata_ | ~(doc intern) |
| 21:06 | clojurebot | gitdoc is http://github.com/Lau-of-DK/gitdoc/tree/master |
| 21:07 | rata_ | gfrlog: for example... or (compile ...) |
| 21:07 | gfrlog | I'll try lein compile |
| 21:07 | rata_ | or C-c C-k en slime |
| 21:09 | gfrlog | rata_ my religion doesn't permit me to use slime |
| 21:09 | rata_ | ok np |
| 21:09 | gfrlog | rata_: lein compile gives the expected ClassNotFoundException |
| 21:09 | rata_ | ok, so it's the compiler effectively |
| 21:09 | rata_ | my fault |
| 21:10 | gfrlog | np |
| 21:11 | gfrlog | rata_: when I try intern at the repl using symbols, it complains that the not-yet-existing namespace isn't found |
| 21:11 | rata_ | then intern won't solve the problem either |
| 21:11 | gfrlog | I don't see it as a problem. Just a mystery of what hiredman was thinking of. |
| 21:12 | rata_ | intern is a fn so it won't solve anything at compile-time I think |
| 21:12 | gfrlog | var-get and find-var are both fns, I assume, and they sufficed |
| 21:14 | rata_ | yes, but you use them to not have to evaluate the symbol... you give the symbol quoted |
| 21:15 | rata_ | (is that proper english?) |
| 21:15 | gfrlog | right -- you're hoping to find something that allows the symbol unquoted? |
| 21:15 | rata_ | yes |
| 21:15 | gfrlog | sure looked like english to me |
| 21:15 | gfrlog | yeah, I guess a macro could work that out pretty easily. I guess then you're looking for an existing macro in clojure.core or something? |
| 21:18 | rata_ | when I compile code that mentions a non-existent var or a non-existent namespace, it doesn't give me a ClassNotFoundException |
| 21:19 | gfrlog | ,(why.wont.this/work?) |
| 21:19 | clojurebot | java.lang.ClassNotFoundException: why.wont.this |
| 21:19 | gfrlog | like that? |
| 21:20 | rata_ | hmmm strange I don't get that |
| 21:20 | rata_ | perhaps an slime thing, but I don't think so |
| 21:22 | rata_ | aha... I have tried with something like (a/b) but not (a.b/c) |
| 21:22 | gfrlog | ,(a/b) |
| 21:22 | clojurebot | java.lang.Exception: No such namespace: a |
| 21:22 | gfrlog | yeah |
| 21:22 | gfrlog | I get results based on that too |
| 21:23 | rata_ | so I think the problem is the namespace, not the var |
| 21:25 | gfrlog | ,(clojure.core/rata_) |
| 21:25 | clojurebot | java.lang.Exception: No such var: clojure.core/rata_ |
| 21:25 | gfrlog | so you think that would compile? |
| 21:26 | gfrlog | (but not eval of course) |
| 21:26 | rata_ | no, but that gives another error |
| 21:26 | rata_ | java.lang.Exception |
| 21:26 | gfrlog | even at compilation? |
| 21:27 | rata_ | yes |
| 21:28 | rata_ | I have just compiled it and gave me that error |
| 21:28 | gfrlog | this is an interesting contrast to other dynamic languages |
| 21:28 | gfrlog | ruby will let you call whatever made up function you want and doesn't object until it executes |
| 21:29 | rata_ | perhaps the solution is (refer ...) |
| 21:29 | rata_ | have you tried that? |
| 21:29 | rata_ | (refer your.ns) |
| 21:29 | gfrlog | ,(doc refer) |
| 21:29 | clojurebot | "([ns-sym & filters]); refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude list-of-symbols :only list-of-symbols :rename map-of-fromsymbol-tosymbol ... |
| 21:30 | gfrlog | ,(refer rata.gfrlog) |
| 21:30 | clojurebot | java.lang.ClassNotFoundException: rata.gfrlog |
| 21:30 | gfrlog | so I'd probably get that? |
| 21:31 | rata_ | yes =( |
| 21:31 | rata_ | ,(doc load-string) |
| 21:31 | clojurebot | DENIED |
| 21:33 | rata_ | I'm reading here http://clojure.org/Namespaces |
| 21:33 | rata_ | ,(resolve a.b) |
| 21:33 | clojurebot | java.lang.ClassNotFoundException: a.b |
| 21:34 | rata_ | ,(create-ns a.b) |
| 21:34 | clojurebot | java.lang.ClassNotFoundException: a.b |
| 21:34 | rata_ | ,(create-ns 'a.b) |
| 21:34 | clojurebot | #<Namespace a.b> |
| 21:34 | rata_ | haaa |
| 21:34 | rata_ | ,(resolve 'a.b) |
| 21:34 | clojurebot | java.lang.ClassNotFoundException: a.b |
| 21:34 | gfrlog | clojurebot probably resets state every time |
| 21:35 | rata_ | yes... just checking if the absence of the quote was significant before |
| 21:35 | rata_ | gfrlog: try (create-ns 'your.ns) |
| 21:36 | gfrlog | okay |
| 21:39 | gfrlog | rata_: still get the classNotFoundException |
| 21:39 | gfrlog | yes, am quoting the ns name in create-ns |
| 21:40 | rata_ | and you get the exception at the create-ns line or at the other line? |
| 21:40 | gfrlog | the other line |
| 21:40 | gfrlog | after create-ns |
| 21:43 | rata_ | mmmm strange... I don't get that |
| 21:43 | rata_ | (do (create-ns 'b.c) (b.c/a)) works for me |
| 21:43 | rata_ | *compiles for me |
| 21:43 | gfrlog | maybe slime is "ruby mode" |
| 21:44 | rata_ | hahaha could be |
| 21:44 | gfrlog | clojure: everything is dynamic at runtime, unless you do anything the normal way |
| 21:46 | rata_ | load-string isn't at all normal I think |
| 21:46 | gfrlog | nope |
| 21:46 | gfrlog | but calling functions using symbols literals is |
| 21:47 | rata_ | gfrlog: putting (create-ns a.b) (a.b/c) in a file and then executing that from the command line gives me a java.lang.Exception, not the ClassNotFoundException |
| 21:47 | rata_ | the problem here is load-string |
| 21:47 | gfrlog | but the error happens before I ever use load-string |
| 21:49 | rata_ | what?? then why are you calling something you haven't loaded yet? |
| 21:50 | gfrlog | the code doesn't get executed until the lib is loaded |
| 21:50 | gfrlog | but the code offends the compiler before the lib is loaded |
| 21:52 | gfrlog | (defmacro lenient-compiler [& forms] `(eval (do ~@forms))) |
| 21:52 | gfrlog | whoops |
| 21:52 | gfrlog | (defmacro lenient-compiler [& forms] `(eval '(do ~@forms))) |
| 21:52 | gfrlog | there we go |
| 21:52 | rata_ | and did you put the create-ns thing before the offending code? |
| 21:52 | gfrlog | yes I did |
| 21:52 | gfrlog | you can imagine why it wouldn't make a difference: |
| 21:53 | gfrlog | the compiler doesn't execute create-ns |
| 21:53 | gfrlog | so it doesn't know whether or not it will actually result in the relevant namespace being created |
| 21:53 | gfrlog | all it knows is it still hasn't heard of that namespace |
| 21:54 | rata_ | mmmm but for some reason when I execute (create-ns 'a.b) (a.b/c) it doesn't say anymore ClassNotFound |
| 21:55 | gfrlog | what context are you executing them in? |
| 21:55 | rata_ | did you put it at the beginning of the file, after the ns macro? |
| 21:55 | gfrlog | no, just before the relevant statement |
| 21:55 | rata_ | that's the whole file (create-ns 'a.b) (a.b/c) |
| 21:55 | gfrlog | does the second line in isolation still throw an error? |
| 21:55 | rata_ | vim asdf.clj, put that, then execute |
| 21:55 | gfrlog | how do I "execute" it? |
| 21:56 | gfrlog | should I still call it asdf.clj if I use a dvorak keyboard? |
| 21:56 | rata_ | java -cp clojure.jar clojure.main asdf.clj |
| 21:57 | rata_ | gfrlog: yes, asdf is a beautiful combination of letters =P |
| 21:57 | rata_ | when I put the second line alone it gives a ClassNotFoundException |
| 21:57 | gfrlog | lesse |
| 21:57 | gfrlog | lesee |
| 21:57 | gfrlog | let's see |
| 21:58 | gfrlog | so I get "no such var" -- which is what you get too? |
| 22:00 | rata_ | yes |
| 22:00 | gfrlog | clojure is weird. |
| 22:02 | gfrlog | clojurebot: were you developed in a hammock? |
| 22:02 | clojurebot | Pardon? |
| 22:10 | rata_ | gfrlog: well... a little step, but too little I think |
| 22:10 | gfrlog | what step? |
| 22:11 | rata_ | to get a "no such var" instead of a ClassNotFound |
| 22:11 | gfrlog | well presumably the "no such var" is a runtime error rather than compile time |
| 22:11 | gfrlog | so in my context it wouldn't get thrown, since by runtime the var actually would exist |
| 22:11 | rata_ | then try it |
| 22:11 | gfrlog | well I did and it doesn't compile |
| 22:11 | gfrlog | that's the whole weird thing about it |
| 22:12 | rata_ | =( |
| 22:12 | rata_ | yes weird |
| 22:12 | gfrlog | try executing your file with a (ns) at the top |
| 22:12 | gfrlog | for a different ns |
| 22:12 | rata_ | ok |
| 22:13 | rata_ | no such var |
| 22:14 | gfrlog | then add (load-string "(ns a.b) (defn c [] nil)") on the second line |
| 22:24 | rata_ | gfrlog: works fine =) |
| 22:24 | gfrlog | clojure-version? |
| 22:24 | gfrlog | wait that shouldn't matter |
| 22:24 | rata_ | 1.2 |
| 22:24 | gfrlog | me too |
| 22:25 | rata_ | but it works without create-ns too |
| 22:25 | gfrlog | ah |
| 22:25 | gfrlog | so we're all confused now |
| 22:26 | gfrlog | I think clojure probably has about 7 different ways it can execute your code |
| 22:27 | rata_ | no... the thing is when you load-string, the namespace becomes available |
| 22:27 | rata_ | and the var too |
| 22:27 | gfrlog | oooh I know |
| 22:27 | gfrlog | put both the load-string and the (a.b/c) in separate functions |
| 22:28 | gfrlog | then after they've both been defined, call them in order |
| 22:28 | rata_ | for example (ns d) (load-string "(ns a.b) (declare c)") (defn e [] (a.b/c)) (load-string "(ns a.b) (defn c [] nil)") (e) |
| 22:28 | rata_ | works |
| 22:29 | gfrlog | what about without the first load-string? |
| 22:30 | rata_ | it doesn't compile... that load-string is required |
| 22:32 | gfrlog | that's strange |
| 22:33 | gfrlog | I guess the statements are executed in some sense |
| 22:33 | rata_ | yeah |
| 22:33 | gfrlog | if you delayed execution of the load-string statement until after (defn e...) had been processed, it probably wouldn't work |
| 22:34 | gfrlog | anyhow, I gotta drop out for the night |
| 22:34 | gfrlog | thx for the sleuthin |
| 22:34 | rata_ | ok |
| 22:34 | rata_ | good night |
| 22:53 | mreynolds | More newbism : I'm trying to create a configuration file for my app, but I like the idea of having it be code (a la, most of the time it's convention, but if I need to, I can write an anonymous function). I've looked at leiningen's implementation and it seems... hard due to the limitations of load-file. Is there a better/simpler way of doing this? I'm about to start down the road of building a DSL, but that seems complex as wel |
| 22:54 | brehaut | the simplest way is just to have a settings namespace |
| 22:55 | brehaut | if it doesnt need to be reloaded while the program is running its by far the easiest |
| 22:55 | mreynolds | brehaut: It doesn't. Can you give me more details for that? Is that just a matter of me including a namespace that is defined separately? |
| 22:56 | brehaut | yeah its just like any other clojure file in your project |
| 22:56 | brehaut | i have as myproject.settings |
| 22:56 | brehaut | and i def the settings to be clojure structures |
| 22:56 | mreynolds | brehaut: Ahh, heh. I've yet to actually use more than one ns (still learning). I'll dork around with that. Thanks! |
| 23:34 | chouser | wow, lazy-test's failure reports are *so much nicer* than clojure.test's. |
| 23:35 | chouser | sexpbot: tell stuartsierra |