Re: Clojure regexs
bah! good catch. (let [[_ year month day]] (re-find date-regex line)) fixed! On Thu, Jan 13, 2011 at 9:03 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Jan 13, 2011 at 9:54 PM, Alex Baranosky alexander.barano...@gmail.com wrote: I see. So I may have to use some kind of clunky syntax instead of a nice $1, $2, $3 syntax. I can handle that I guess :) Hey, it's a Lisp! You can use almost any syntax you want. How about %1, %2, %3: (defn re-do [f regex input] (apply f (rest (re-find regex input (re-do #(do-stuff-with %3 %1 %2) regex input) Or even (defmacro re-let [names regex input body] `(let [[_ ~@names] (re-find ~regex ~input)] ~@body)) (re-let [year month day] date-regex line (do-something-with year month day)) This one doesn't even have the bug that gaz jones's let has. ;) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure regexs
lol oh noes! i should really stop doing this while watching 30rock... On Thu, Jan 13, 2011 at 9:38 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Jan 13, 2011 at 10:22 PM, gaz jones gareth.e.jo...@gmail.com wrote: bah! good catch. (let [[_ year month day]] (re-find date-regex line)) fixed! Oh, gaz. I'm so so sorry. :( -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: When to use #'
its a reader macro equivalent to the var special form: (var symbol) The symbol must resolve to a var, and the Var object itself (not its value) is returned. The reader macro #'x expands to (var x). from: http://clojure.org/special_forms#var On Wed, Jan 12, 2011 at 9:11 PM, Alex Baranosky alexander.barano...@gmail.com wrote: Hi, I find it extremely hard to google this to learn more! I'd like to know some good sources of further information on when to use #' . It is a bit mysterious to me at this point. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: which IDEs are you all using?
i wrote this recently about how i edit clojure in emacs, listing some features i find especially useful: http://blog.gaz-jones.com/post/2501842155/interactive-clojure-development-in-emacs-with-leiningen i used to use vimclojure as vim was my favourite editor but decided to take the plunge and learn emacs after seeing stuart halloway use it on some screen casts and being impressed with the flow. very glad i did, its great (i still use vim for ruby though :D). hope that helps, gaz On Sun, Jan 9, 2011 at 1:01 PM, Alex Baranosky alexander.barano...@gmail.com wrote: Hi, I'm most used to using Intellij, since it is what I use everyday at work programming in Java. So my first forays into Clojure have been using LaClojure. Some things I like about using Intellij for Clojure development are: I can click on a piece of code and have Intellij take me to the file where that code is defined, even if I didn't write it; this means I can click right through into clojure.core and read the source. It also has a nice rainbow parens feature which I find helps with visually parsing the Clojure code. And of course Intellij has a LOT of keyboard shortcuts to help with manipulating the text. I also like to change the color scheme, I assume emacs allows you to use a self-created color scheme? I've been considering switching to Emacs because it seems to be the de facto standard for the community. Does emacs have the equivalent of these four features? If not, does it have their equivalents? On another note, I'd also love to hear what features Emacs would give me that LaClojure doesn't enable. All the Best, Alex -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: which IDEs are you all using?
hey, did it fail to install or was it just a warning? you can check if it installed with M-x package-list-packages and seeing if it is in the installed list (should be at the bottom of the buffer marked as installed). you get quite a lot of warnings with some of those packages on install but they're usually not a problem. try restarting emacs and opening a clojure file and if 'Clojure' is in your mode bar then it is all good... On Sun, Jan 9, 2011 at 10:00 PM, Alex Baranosky alexander.barano...@gmail.com wrote: Hi Gaz, I followed your blog and when I used Emacs to install the package syou suggested (clojure-mode, slime etc) I go this error output. I'd love to know if this means anything to anyone, I'm a total newbie to Emacs: Compiling file /home/alex/.emacs.d/elpa/clojure-mode-1.7.1/clojure-mode-pkg.el at Sun Jan 9 22:44:07 2011 Compiling file /home/alex/.emacs.d/elpa/clojure-mode-1.7.1/clojure-mode.el at Sun Jan 9 22:44:07 2011 clojure-mode.el:69:1:Warning: cl package required at runtime In clojure-mode: clojure-mode.el:179:34:Warning: reference to free variable `paredit-mode' clojure-mode.el:179:51:Warning: reference to free variable `paredit-version' In clojure-font-lock-extend-region-def: clojure-mode.el:250:33:Warning: reference to free variable `font-lock-beg' -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure job scheduler
the work library has a function which it describes as 'cron for clojure functions': https://github.com/clj-sys/work.git cant say i have used it, but i noticed it in there recently whilst looking for other things. here is the function: (defn schedule-work schedules work. cron for clojure fns. Schedule a single fn with a pool to run every n seconds, where n is specified by the rate arg, or supply a vector of fn-rate tuples to schedule a bunch of fns at once. ([f rate] (let [pool (Executors/newSingleThreadScheduledExecutor)] (.scheduleAtFixedRate pool (with-log f) (long 0) (long rate) TimeUnit/SECONDS) pool)) ([jobs] (let [pool (Executors/newSingleThreadScheduledExecutor)] (doall (for [[f rate] jobs] (schedule-work pool f rate))) pool))) hope that is useful, cheers gaz On Fri, Jan 7, 2011 at 11:13 AM, Trevor tcr1...@gmail.com wrote: What's the best way to kick off Clojure code at scheduled times? I have some that would run once a day. Some that might run 2 or 3 times a day based upon a test being met. 1. I could write a function that sleeps an interval, check the time differential to perform a time-box triggered function, but would that consume too much memory?, cause long term problems? 2. I could use quartz, but that seems like overkill. 3. I could set a job-schedule using the OS to run a clojure script. I'd rather not, I would like to do things like send emails / check status via web app (making option 1 more appealing). I'm looking for input/guidance. What are your experiences? Thanks, -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: osx + clojure + emacs + leiningen blog posts
nope not related, i can add a paragraph there to avoid confusion. On Mon, Jan 3, 2011 at 12:44 AM, Bill Robertson billrobertso...@gmail.com wrote: Hi, One thing worth noting about emacs-starter-kit is that it tries to source a file of your own customizations on startup. This file defaults to your username.el so the easiest thing to do is create that file inside of ~/.emacs.d. One thing you really should add to this is a function to fix the path issues inside of Emacs: Is fixing the path related to the information about ~/.emacs.d/ username.el? If not then I would suggest a new paragraph. If it is, then will you please explain how? Thanks, Bill Robertson On Dec 28 2010, 11:31 pm, gaz jones gareth.e.jo...@gmail.com wrote: thanks for the feedback, i will update it tomorrow. cheers, gaz On Tue, Dec 28, 2010 at 8:44 PM, Phil Hagelberg p...@hagelb.org wrote: On Dec 28, 2:32 pm, gaz jones gareth.e.jo...@gmail.com wrote: i put together a couple of blog posts around how i use clojure + emacs + leiningen on OSX (but applies to linux too) in the hope it may help someone get up and running faster: Looks good. I should mention that installing the elisp for swank- clojure is actually no longer necessary. Also it's a little more convenient to use C-c C-k instead of C-c C-l to compile the current file. It might be nice to link to the Leiningen tutorial for further reference since it goes into more detail: https://github.com/technomancy/leiningen/blob/master/TUTORIAL.md very nice, Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: osx + clojure + emacs + leiningen blog posts
hey, you're welcome. many thanks to phil, his work has made developing clojure in (and out of) emacs pretty awesome. btw i also did another small post on creating simple command line apps: http://blog.gaz-jones.com/post/2528825514/command-line-applications-in-clojure cheers, gaz On Mon, Jan 3, 2011 at 8:38 PM, Bill Robertson billrobertso...@gmail.com wrote: Yes. Very helpful. Thanks Gaz. Also, thanks to Phil for all of his hard work. -Bill On Jan 3, 10:50 am, Neo neo@gmail.com wrote: Very useful info, really thanks for that. Will try later and give feedback. gaz jones wrote: oh hi, i put together a couple of blog posts around how i use clojure + emacs + leiningen on OSX (but applies to linux too) in the hope it may help someone get up and running faster: http://blog.gaz-jones.com/post/2486737162/setting-up-clojure-developm... http://blog.gaz-jones.com/post/2501842155/interactive-clojure-develop... suggestions for improvements / things im doing crazy are welcome! cheers gaz -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
osx + clojure + emacs + leiningen blog posts
oh hi, i put together a couple of blog posts around how i use clojure + emacs + leiningen on OSX (but applies to linux too) in the hope it may help someone get up and running faster: http://blog.gaz-jones.com/post/2486737162/setting-up-clojure-development-on-osx-using-emacs-and http://blog.gaz-jones.com/post/2501842155/interactive-clojure-development-in-emacs-with-leiningen suggestions for improvements / things im doing crazy are welcome! cheers gaz -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Automatically unmapping unit tests from namespaces
you can also move to the failed test and press C-c ' and it will show them in the mini-buffer On Tue, Dec 21, 2010 at 11:47 PM, Michael Ossareh ossa...@gmail.com wrote: On Tue, Dec 21, 2010 at 21:36, Michael Ossareh ossa...@gmail.com wrote: On Tue, Dec 21, 2010 at 16:16, Phil Hagelberg p...@hagelb.org wrote: It also highlights failures in the test buffer for better feedback. when there is a failure where are the details of the failure printed out to? I love that the highlight shows me which test have errors, but since I've moved over to the emacs starter kit (thanks!!) I've lost the error output and have to switch to a terminal to run lein test. The answer: the repl buffer. I've no idea why they weren't - but they are now. I'll take it :) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ah-hah! Clojure is a Lisp
sha-wing? :D On Sun, Dec 19, 2010 at 5:41 PM, javajosh javaj...@gmail.com wrote: Can you articulate it any better than ah hah!? On Dec 19, 11:33 am, Tim Daly d...@axiom-developer.org wrote: There have been discussions, here and elsewhere, about whether Clojure is a Lisp. Lots of discussion centers around facts like homoiconicity, or the REPL, or the debate of Rich's redefinition of lisp primitives, etc. These are arguments about the paint on the palace. I have struggled with this question and I believe I found the answer that satisfies me that Clojure is a Lisp. The answer is that getting Clojure involves an ah-hah! moment. The most fundamental thing about Lisp is that there is this universal but personal event when you suddenly get it. This does not seem to happen with other languages. There is a distinct before vs after when you suddenly internalize the language and IT changes YOU. I recently felt that moment with Clojure. Did anyone else experience the ah-hah!? Tim Daly -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Moderately off-topic: installing emacs on OSX
homebrew installs a mac application to: /usr/local/Cellar/emacs/23.2/Emacs.app/ by default which you can run from there, or copy to your /Applications folder to run. running from the terminal doesnt seem to work so well in my experience. On Mon, Dec 13, 2010 at 8:43 PM, javajosh javaj...@gmail.com wrote: Ok, I decided to nuke ports, fink, and delete every package they ever installed. I successfully installed emacs 23.2 via homebrew (there's a good overview of homebrew here http://ascarter.net/2010/02/22/homebrew-for-os-x.html). I started the emacs it installed, but I didn't know how to access the scratch buffer, so I started the tutorial. Exit worked (C-x C-c). Scroll forward did not (C-v). Needless to say, I couldn't complete the elpa instructions. Additionally, emacs pops up a new colorful window but keeps the terminal in place. That's not the behavior I personally want. Perhaps I will try installing without the --cocoa option. Also tried the elpa self-install script in Aquamacs (where the scratch buffer comes up first thing), but C-j (the 'eval' keystroke) had no discernible effect. I tried M-x package-list-packages but it said [No Match]. So I assume nothing happened. Sorry to say but I'm rather annoyed with emacs. I find futzing around with package managers and this stuff to be utterly exhausting. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
command line options parser
oh hi, i needed (well, wanted) a command line parser more like opt parser in ruby so i threw one together: https://github.com/gar3thjon3s/clargon thought i would share in case anyone else finds it useful. im aware of with-command-line but it didnt quite do what i wanted as i needed functions that parse things and i generally want the config as a map. suggestions for improvements welcome. cheers, gaz Example: (clargon args (required [-p --port the port for the server] #(Integer. %) (optional [--host hostname of server :default localhost]) (optional [--verbose run in chatty mode :default true]) (optional [--log-directory where you put logs :default /some/path]))) with args of: '(-p 8080 --no-verbose --log-directory /tmp) will produce a clojure map with the names picked out for you as keywords: {:port 8080 :host localhost :verbose false :log-directory /tmp} A flag of -h or --help is provided which will currently give a documentation string: Usage: Switches Desc Default Required --- -p, --port the port for the server Yes --host hostname of server localhost No --verboserun in chatty mode trueNo --log-directory where you put logs /some/path No -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Moderately off-topic: installing emacs on OSX
brew install emacs --cocoa worked pretty well for me. and then my fork of emacs-starter-kit if that is useful to anyone: https://github.com/gar3thjon3s/emacs-starter-kit my default-profile.el has a few settings for making the brew installed emacs work better with os x. by the way thanks for the set-exec-path-from-shell-PATH function, that is awesome. If you have issues with emacs failing to pick up the right executables, you can use the following nifty trick to ensure Emacs' $PATH matches the one you've configured for Bash in Terminal: (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 (if window-system (set-exec-path-from-shell-PATH)) On Fri, Dec 10, 2010 at 8:39 PM, Mike Meyer mwm-keyword-googlegroups.620...@mired.org wrote: On Sat, 11 Dec 2010 01:07:51 + Alec Battles alec.batt...@gmail.com wrote: I don't use OS X so I can't comment on such a consensus, but while I appreciate the sentiment, it's actually harmful to some degree to have lots of blog posts scattered around everywhere that all have slightly different advice, especially since that advice usually becomes outdated within the year. Speak for yourself. Whenever I need to install SCIM on someone's computer I pull up three conflicting blog posts and just combine elements of all of them. I do that as well. And then, after a couple of days trying all the various combinations and having none of them work, I give up and ask the on the list to get an answer that actually works with the current versions of all the tools. Of course, if a typical howto was more than a recipe of steps with no explanations, but actually documented why you wanted to take each step and what it achieved, then you might have a chance of figuring out how to mix them to be right for your environment. I strongly suggest improving the docs on the Clojure wiki instead; that way errors can be fixed by the community. Why does the one preclude the other? Much as I hate wiki's, an up-to-date wiki is *much* better than a collection of out of date blog entries. It makes the reading the out-of-date blog entries that google returns a waste of time. If the wiki isn't up to date, then it just becomes a part of the trial-and-error process that's the norm for getting things done in the Linux world. Also, if people aren't going to blog about Clojure, what future does it have? If people can't figure out how to get Clojure installed because all they can find on the web is out of date blog entries, what future does it have? There's *lots* of good thing in clojure to blog about without writing yet another howto that's going to be out of date in a few months. You can write about what you're doing with it: how the Java interop helps with that, how the nifty data structures and functions that work with them assist the process of creating a program, etc. Basically, it's a simple choice - do you help yourself by writing an entry for your blog, or do you help the clojure community by writing an entry for the wiki? I claim the subject matter should determine which: if you're documenting how to use clojure, put it on the wiki. If you're documenting how you're using clojure, put it in your blog. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: string interpolation
you could use format or cl-format? http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/format http://clojure.github.com/clojure-contrib/pprint-api.html#clojure.contrib.pprint/cl-format On Sat, Nov 20, 2010 at 5:00 PM, HiHeelHottie hiheelhot...@gmail.com wrote: I think ruby has nice string interpolation. You can put the following in a textfield that a user can modify This is a #{adjective} string. Then, you can take that string, put it in quotes and have ruby evaluate it as a string. What is the clojure way of doing something similar. Presenting something like This is a adjective string and then wrapping that in (str ) before evaluating it in clojure seems less attractive. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: apply a function to a list and another parameter
you could do something like: (map str [hello1 hello2 hello3] (repeat world)) there is also a time macro: (time (println oh hi)) On Fri, Oct 22, 2010 at 5:48 AM, Marc von Bihl mvonb...@googlemail.com wrote: Hello, I am new to fucntional programming and have 2 questions: How can I apply a function to each element from a list and a second parameter? (def lstr '(Hello1 Hello2 Hello3)) (defn addtoString [s1 s2] (str s1 s2)) (apply (addtoString lstr World)) - I need it for the following example (pseudo code). How would you realize this in Clojure?: function testit [times, function, list, s] for (0 to times) def start = System.nanoTime() def results = [] for (i = 0 to list.length()) results.add(function(listelement(i), s)) def end = System.nanoTime() println run took end-start ns println results are: results.each { result = println result } -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: question regarding macro (ab)usage
thanks for the reply, you are right! and in fact my real implementation is more like this, i thought that by showing them both as macros in the post it would be easier for people to just skim read the post and compare them side by side. probably just confused the issue, sorry. the thing im really interested to know is if binding the functions the way i have (in either example) is considered 'bad form', and if a protocol and reify is the more idiomatic solution, or if there is another solution to this problem. On Tue, Sep 28, 2010 at 2:41 AM, Nicolas Oury nicolas.o...@gmail.com wrote: I hadn't time to read the whole post, but, I I understand it well, this snipset (defmacro with-context [options body] `(let [context# (create-context options) thread# (create-thread context) sources# (atom {}) receivers# (atom {})] (binding [init-receiver (partial init-receiver-on context# receivers#) init-source (partial init-source-on context# sources#) publish (partial publish-on context# sources#) receiver (partial receive-on context# receivers#)] (try (do ~...@body) (finally ... close stuff, cleanup) can be written more or less: (defn with-context [options action] (let [context ..]) (binding [init-receiver .] (try (action) (finally ))) That can be called with (with-context options #(body)) You can then wrap this call in a macro to remove the #(). I am not sure it is a good idea, but it is always good to know for which precise feature you need the macro. Here tou need it to prevent to have to pass some code around as a function. That's one frequent usage of macro, it can help readability and (very little) performance. But depending of the situation. you might want to trade these advantages for composability and ease of programming. Best, Nicolas. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
question regarding macro (ab)usage
hi, apologies if this is a long question, i would appreciate some guidance here. i am creating a clojure wrapper around a rather verbose low latency messaging framework. the main things you can do are publish messages, receive messages, initialize sources and receivers etc. all are done through a 'context'. i have ended up with this (silly example): (with-context [:some parameter] (init-receiver some-topic :some option) (init-source some-topic :on-disconnect #(println client disconnected)) (publish some-topic some-message :other option) (receive some-topic (fn [o m] (println received: (.dataString m) which i am fairly happy with. it is all wrapping up access to underlying java objects (eg a context object, lists of sources, receivers, threads and so on). the implementation (somewhat simplified for clarity) is like: ;; these will be bound later (def init-receiver nil) (def init-source nil) (def publish nil) (def receive nil) ;; real impls with more args than i want to have to pass around (defn init-receiver-on [context receivers topic] ...boring java stuff) (defn init-source-on [context sources topic] ...boring java stuff) (defn publish-on [context sources topic message] ...boring java stuff) (defn receive-on [context receivers topic func] ...boring java stuff) (defmacro with-context [options body] `(let [context# (create-context options) thread# (create-thread context) sources# (atom {}) receivers# (atom {})] (binding [init-receiver (partial init-receiver-on context# receivers#) init-source (partial init-source-on context# sources#) publish (partial publish-on context# sources#) receiver (partial receive-on context# receivers#)] (try (do ~...@body) (finally ... close stuff, cleanup) so i am binding those functions to partial applications which use the lexically scoped context, thread etc when you use the macro. is this reasonable? a prior implementation i had was like: (defmacro with-context [options body] `(let [context# (create-context options) thread# (create-thread context#)] sources# (atom {}) receivers# (atom {})] (letfn [(~'publish [topic# msg# options#] (publish-on context# sources# topic# msg# options#)) (~'receive [topic# callback# options#] (receive-on context# receivers# topic# callback# options#)) (~'init-source [topic# options#] (init-source-on context# sources# topic# options#)) (~'init-receiver [topic# options#] (init-receiver-on context# receivers# topic# options#))] (try (do ~...@body) (finally ... cleanup)) which seems like a bit of an abuse, creating an anaphara for each of the functions. the problem i had with this was the anaphara werent available when i was outside of my macro (eg in any other function called from the macro): (defn start-server [] (receiver topic (fn [o m] (println this is full of fail (with-context [] (start-server)) i also tried implementing it using a protocol and reify, which worked rather well and felt the 'cleanest' solution, the impl of which is probably fairly obvious so i wont bother typing it in here. however i didnt like having to pass an object around everywhere to call methods on. my question is simply, what is the most idiomatic solution? im guessing the protocol and reify, but is the first solution also reasonable? again, sorry for the long question - i also typed it all from memory so apologies for any obvious typos / mistakes, i dont have the code available on the machine i am using. any insight would be appreciated. thanks, gareth -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en