converting an xml database backup to insert statements

2013-02-28 Thread Peter Buckley
Preamble:

I've read some about xml and clojure, and done some mostly trivial things
(reading and writing values from and to xml). Most of the examples I've
seen of parse, zip, etc are very elegant and do a great job at reading a
specific x-path-like value or series of values. But I'm stuck trying to do
what I think is a more involved operation with xml - to the point where I'm
thinking clojure isn't the right tool. But I really enjoy programming in
clojure, and so I'm hoping some folks on the list can help point me in the
right direction. TIA!

Detail:

I have poked around some, read the APIs and examples, and I can even
navigate using something like (- down down right node) but I can't seem to
reconcile or mix that manual navigation of the zipper (that is passing
locs to each fn) and what I think I really want from something like xml-
(which doesn't return a loc, it returns a lazy-seq that's de-loc-ified).

Overview:

I have a backup of a database as xml. It's got a bunch of stuff in it, some
of which I want and some that I want to discard. But I mostly have a
blacklist of this is what I need to discard and I want everything else.
Once I have the parts of the db backup I want, I need to translate them to
insert statements to build the database back up. I'm having some difficulty
wrapping my head around what I haven't even gotten to solving yet - that I
need the list of tags and the value back, when something really nifty like
xml- seems to be designed to only give me the values.

Code (ish):

Sample files below (or gisted https://gist.github.com/pbuckley/5060575).

xml:

config xmlns=some-url
  FAKENAME xmlns=another-url
SomeSettings
  SpecificSettings
FooVAL1/Foo
BarVAL3/Bar
  /SpecificSettings
/SomeSettings
DoNotWant
  SomeEnormousChildren
  /SomEnormousChildren
/DoNotWant
MoreConfig
  Baz20/Baz
  Buz300/Buz
/MoreConfig
  /FAKENAME
/config

And this non-working somewhat pseudo-code (it gets more pseudo the further
you get):

(ns config-backup.confdbackup
  (:require [clojure.xml :as xml]
; I think I need both zip and data.zip?
[clojure.zip :as zip] ; different from clojure.data.zip?
[clojure.data.zip :as zf] ; used to be zip-filter?
[clojure.data.zip.xml :as zx]))

(def my-xml (xml/parse my-db-backup.xml))

(def my-zipped-xml (zip/xml-zip my-xml))

(def this-worked (zx/xml- my-zipped-xml :FAKENAME :SomeSettings
:SpecificSettings :Foo zx/text))

(def with-junk-removed (zip/remove (zx/xml- my-zipped-xml :FAKENAME
:DoNotWant))) ; does not work

(defn transmogrifier
  given the xml, nodes and text, create insert statements for them
  [things]
  (do-some-magic))

(transmogrifier with-junk-removed) ; returns insert FAKENAME SomeSettings
SpecificSettings Foo VAL1 and the stuff from MoreConfig etc




-- 
The king’s heart is like a stream of water directed by the Lord; He guides
it wherever He pleases.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to structure a Clojure day for noobs?

2012-12-17 Thread Peter Buckley
1. install Leiningen and learn the basics
2. get everyone an editing environment, with the option of using either
Emacs, IntelliJ, or Eclipse

I would have people do this in advance, or provide a canned environment
that has a better chance of just working. There's decent odds that these
two steps will eat up a bunch of your time and leave people feeling left
out when their install/editor/integration is not quite right.

Personally I found the C-x-e of evaluating an s-exp in emacs to be the
magic that makes clojure a bajillionty times better than any other
programming language, so I'm partial to something like the emacs starter
kit. But something like labrepl or eclipse+counterclockwise might be easier
for people to start with.

On Mon, Dec 17, 2012 at 3:26 AM, Marko Topolnik marko.topol...@gmail.comwrote:


 I think, however, that there is a risk of a disconnect, where newcomers
 don't really grasp that there is a JVM running and that code is actually
 compiled and injected into it, and that it's for real. They are used to
 mickey mouse interactive tools that don't provide the real thing, and
 struggle to bridge the apparent gap between running code in the REPL and
 properly compiling and running files. There is no gap, but one needs to
 explain that, I think.


 I think this is a pivot point for everything in Clojure. The harder the
 mental switch, the more important to make it right away. Without
 understanding that, it will be very hard to maintain a clear picture of how
 everything fits together, especially when you start changing functions and
 reloading them.

 --
 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




-- 
The king’s heart is like a stream of water directed by the Lord; He guides
it wherever He pleases.

-- 
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: emacs error: Package `clojure-mode' is not available for installation

2012-08-25 Thread Peter Buckley
I had various issues with clojure-mode, swank, slime, etc. with emacs 23 until 
I switched to emacs 24. 

Emacs 24 is much simpler to download now (don't have to compile from source) 
and is likely the quickest solution to all your clojure/emacs issues.

-Original Message-
From: Menelaos Perdikeas mperdik...@gmail.com
Sender: clojure@googlegroups.com
Date: Sat, 25 Aug 2012 22:35:52 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: emacs error: Package `clojure-mode' is not available for installation

I am following the instructions on:

https://github.com/technomancy/clojure-mode/blob/master/README.md

on how to setup emacs with Clojure-mode.
I am running GNU Emacs 23.3.1 in Ubuntu. Launching my Emacs fails with:

error: Package `clojure-mode' is not available for installation 
   

The relevant section of my .emacs file is:

  (if   
  
  (= emacs-major-version 23)
  
  (load package)   
  ) 
  

  
  (progn 
  (require 'package)
  
  (add-to-list 'package-archives
  
   '(marmalade, http://marmalade-repo.org/packages;))
  
  (package-initialize)  
  
  ) 
  

  
  (progn ;; Clojure mode and Paredit
  
  (when (not (package-installed-p 'clojure-mode))   
  
(package-install 'clojure-mode))
  
  (if nil ;; turn Paredit off for now   
  
  (when (not (package-installed-p 'paredit))
  
(package-install 'paredit)  
  
  ) 
  
  (progn ;; Paredit 
  
  ;; (require 'paredit) if you didn't install via package.el
  
  (defun turn-on-paredit () (paredit-mode 1))   
  
  (add-hook 'clojure-mode-hook 'turn-on-paredit)
  
  ) 
  
  ) 
  
  )




-- 
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 

Re: meta-questions - [clojure] in front of Subject line

2012-06-18 Thread Peter Buckley
I'm wasn't saying filtering into folders was superior, I was saying having the 
option to filter by sender was superior to merely having the option to filter 
by subject. 

But it sounds like you already have the option, and that just isn't your 
workflow. Sorry that I misunderstood. 

I don't read the messages in a folder, I primarily follow the list from my 
BlackBerry and the messages can be viewed mixed into my global or individual 
inbox depending on my entry point. My gmail rule auto labels and archives the 
messages so I don't have to deal with them twice.

-Original Message-
From: Brian Marick mar...@exampler.com
Sender: clojure@googlegroups.com
Date: Sun, 17 Jun 2012 23:31:22 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: meta-questions - [clojure] in front of Subject line


On Jun 17, 2012, at 7:23 PM, Peter Buckley wrote:
 I know mac products are designed for non-technical people and leave out most 
 common options, but can't they do something so simple and 1980's-esque as 
 filter on a field other than subject?
 
 I've been using gmail and have had a rule for the clojure group since I 
 signed up. I expect most other folks are likewise all set. No need to 
 inconvenience the N1 people who chose to use superior technology. 

I sent my first email 35 years ago. I know about filtering into folders. I find 
it suboptimal for mailing lists I want to follow closely. 

I'm annoyed that you say filtering into folders is superior. It's a choice 
you make, a choice that is not prevented by a subject-line tag that helps 
people who make a different choice. If you're reading with gmail folders, your 
objection to the proposed change is aesthetic. My objection to the current 
change is functional. In something as mundane as email, I privilege the 
functional over the aesthetic.

The complaint about reading the mailing list on phones is valid. I do wonder 
how many people use phones as their main, workaday interface, and how much an 
extra inconvenience 9 characters is when they're already trying to view the 
world through a keyhole.

-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


-- 
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: meta-questions - [clojure] in front of Subject line

2012-06-17 Thread Peter Buckley
Having [clojure] in front of the subject obscures the subject with redundant 
information. It's wasting valuable space at the front of the subject line that 
could be used for, well, the subject, which I'm actually interested in.

The mail is already from clojure@googlegroups, to clojure@googlegroups, and 
reply-to clojure@googlegroups. 

I know mac products are designed for non-technical people and leave out most 
common options, but can't they do something so simple and 1980's-esque as 
filter on a field other than subject?

I've been using gmail and have had a rule for the clojure group since I signed 
up. I expect most other folks are likewise all set. No need to inconvenience 
the N1 people who chose to use superior technology. 

-Original Message-
From: Brian Marick mar...@exampler.com
Sender: clojure@googlegroups.com
Date: Sun, 17 Jun 2012 18:32:33 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: meta-questions - [clojure] in front of Subject line


On Jun 17, 2012, at 6:22 PM, Phil Hagelberg wrote:

 Have you considered a more capable client?

My client is OSX Mail. I don't think it's a marginal client.

What inconvenience would users of more capable clients suffer if a [clojure] 
were added?

Given that the change to Google Groups is ~3-click (I've done it numerous 
times), which makes more sense:

* that 1 person adjust the group settings
* that N1 list recipients adjust their clients

-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Peter Buckley
Once I got lein swank and slime-connect working in emacs, I essentially stopped 
using the repl directly. The real magic and beauty of writing clojure in emacs 
is that I can write a fn, then C-x C-e to evaluate it right there in the file. 
I can evaluate inner forms, test every line of the file to confirm it works, 
experiment, etc, and the code is all saved in the file. 

I don't want to write anything *other* than clojure because it's such a 
beautiful and effective experience. 

-Original Message-
From: Dave Kincaid kincaid.d...@gmail.com
Sender: clojure@googlegroups.com
Date: Fri, 15 Jun 2012 14:47:10 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Classpath set by lein swank or clojure-jack-in

One of the things that really been holding me back from moving ahead with 
Clojure is the difficulty I have running code that I'm writing using a 
repl. I generally use Emacs to code Clojure and I really don't understand 
how the classpath gets set when I use either lein swank + slime-connect 
or clojure-jack-in. I can't seem to get it to find either any 
dependencies that I've included in the project.clj or any of my own code 
without a lot of hit and miss trial and error. Eventually I can usually get 
it to work by doing all kind of things like compiling the .clj file, 
launching lein swank from different directories, etc. Is there a good 
document that I could read to understand how I should be doing this. It's 
so frustrating that I don't even want to try writing Clojure code most of 
the time eventhough I'm loving the language.

Thanks,

Dave

-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Peter Buckley
Probably over-cautious because of my ignorance, but I don't know if I would 
name the project swank-test as I haven't paid too close attention to what 
seems a slightly confusing rule about dashes in namespaces and underscores in 
filenames - also swank-test might be some sort of existing namespace that 
secretly gets loaded and oddly conflicts. 

I also haven't done much with directory structure under the src/project-name 
folder - do you have the same problems with a project that only has one file, 
or only files in that folder?

Like I said this is mostly based on my ignorance, and getting a handle on the 
namespacing is probably a good idea, but I've never had an issue with my small 
projects with flat/default directory structures. Might workaround it for you in 
the short term. 

-Original Message-
From: Sean Corfield seancorfi...@gmail.com
Sender: clojure@googlegroups.com
Date: Fri, 15 Jun 2012 18:44:46 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: Classpath set by lein swank or clojure-jack-in

Have you tried visiting the project.clj file in Emacs and then doing
M-x clojure-jack-in ? That should start lein swank in the project
directory and pull in all the dependencies as expected.

(you should start lein swank in the project root directory -
containing project.clj - not in a subdirectory)

On Fri, Jun 15, 2012 at 5:10 PM, Dave Kincaid kincaid.d...@gmail.com wrote:
 Sure can. Here is the project.clj:

 (defproject swank-test 0.1
   :source-path src/main/clj
   :test-path test/clj
   :java-source-path src/main/java
   :javac-options {:debug true :fork true}
   :resources-path src/main/resources
   :dependencies [[org.clojure/clojure 1.4.0]
                  [cascalog 1.9.0]
                  [org.apache.hadoop/hadoop-core 0.20.2 :exclusions
 [hsqldb/hsqldb]]])

 I have a file named generator.clj in src/main/clj. When I do a lein swank
 from the directory that project.clj is in then run slime-connect in Emacs
 with the generator.clj file open. Then I try to do (use 'generator) and get

 Could not locate generator__init.class or generator.clj on classpath:
   [Thrown class java.io.FileNotFoundException]


 what am I doing wrong?

-- 
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: defrecord with inheritance

2012-05-20 Thread Peter Buckley
- high-level languages are there to make coding more efficient and effective

- the whole point of high-level
languages is to satisfy our need to express our ideas/logics in a more
natural way

I'd argue that you're in violent agreement with each other :-) 

If I can express my idea/logic in a more natural way, I would expect that to 
make my coding more efficient and effective. 

I don't think there is such a thing as one natural thinking or programming 
pattern. I think what each of us regard as natural has a lot to do with 
different individuals' giftings, background, and experience. 

I think it's valid to say that OO is a bad attempt to force a contrived and 
ill-fitting physical world model on computer programs, and it's totally 
unnatural. That's just a point of view on the natural-ness of the programming 
model for an individual.

Even if most programmers think that OO is an ideal model, that still doesn't 
mean it's the natural one.

-Original Message-
From: Alex Baranosky alexander.barano...@gmail.com
Sender: clojure@googlegroups.com
Date: Sun, 20 May 2012 17:42:10 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: defrecord with inheritance

I'd argue with you over whether that is the whole point of high-level
languages.  I might say that high-level languages are there to make coding
more efficient and effective.

On Sun, May 20, 2012 at 5:16 PM, Warren Lynn wrn.l...@gmail.com wrote:


 I agree familiar is often mixed with natural. But nevertheless
 that does not mean there is no such thing as natural thinking or
 programming pattern. In a broader sense, the whole point of high-level
 languages is to satisfy our need to express our ideas/logics in a more
 natural way, hence the modular design, interface and etc. The
 challenge of a language is how to be natural and powerful at the same
 time, as human being's natural thinking often is not enough to model
 the complexity of the world.

 On May 20, 7:34 pm, David Nolen dnolen.li...@gmail.com wrote:
  FWIW, the first thing I did when I encountered Clojure was built a Tiny
  CLOS like system with inheritance. I've since come to the conclusion it
 was
  a waste of time and Clojure offers an equally good set of tools.
 
  After examining a few powerful paradigms, OO, FP, LP, etc I'm not sure
 what
  natural could possibly mean besides familiar which is a limited
 metric
  in my opinion.
 
  David
 
 
 
 
 
 
 
  On Sun, May 20, 2012 at 6:17 PM, Warren Lynn wrn.l...@gmail.com wrote:
   Thanks for the suggestion. I understand part of the joy (and pain) of
   learning a new language is to change the way of thinking. So I
   probably need to take on something no-trivial but also not
   overwhelming to understand the issue or benefit better.
 
   But eventually, a language cannot meet everybody's needs/tastes. In my
   view, there are certain patterns that are just natural to most
   people (not simply because they were taught like that in school), and
   a language will be more productive for those people to have those
   patterns (maybe with extra enhancements and enlightenment). I am sure
   with maps and multimethods you have actually a superset of any OO
   systems, and certain people find it much productive, but lacking
   direct support of certain natural patterns will lose many capable but
   non-genius programmers (which is nothing wrong if that is not part of
   the language's objectives). Part of my learning here is to find out if
   the language is right for me.
 
   On May 20, 5:37 pm, Bill Caputo logos...@gmail.com wrote:
On May 20, 2012, at 4:23 PM, Warren Lynn wrote:
 
 defrecord, deftype, and defprotocol provide extensible low level
 abstractions like the kind Clojure is built on.
 
 As a Clojure programmer you should only need them rarely.
 
 As a beginner you should never use them.
 Well, I don't want to be a beginner for too long, :-)
 
I am not a clojure beginner (though far from feeling I know all
 there is
   to learn about it). I have been using clojure for almost a year; my
 team
   has rebuilt the central part of our system (which is relied on by just
   about every other team where I work) out of clojure and have had it in
   production for 6 months.
 
I've yet to even learn *how* to use defrecord, deftype  defprotocol.
 
IMO, If you're not doing a lot of java interop (i.e. where your
 clojure
   code is being consumed by java clients) you might never need them.
 
As someone who came from, C++, C#  Ruby (and a little Java) - i.e.
 OO -
   to clojure  FP, I *strongly* recommend that you take a project
 (preferably
   one that you aren't hanging your livelihood on, but trust me it's a
 real
   rush) and try *really* hard to solve your design problems just with
 maps,
   vectors and the other core data structures (I first tried this in
 ruby, btw
   - a great learning experience and gave me a strong appreciation for the
   optimizations that clojure provides 

Re: Clojure cheatsheet with tooltips (alpha)

2012-03-24 Thread Peter Buckley
The tooltips work well on my BlackBerry, thanks!

-Original Message-
From: Rostislav Svoboda rostislav.svob...@gmail.com
Sender: clojure@googlegroups.com
Date: Sat, 24 Mar 2012 13:18:57 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: Clojure cheatsheet with tooltips (alpha)

Hi Andy

On 24 March 2012 11:15, Andy Fingerhut andy.finger...@gmail.com wrote:
 There are still some problems with this, but it is ready for experimental 
 use, at least.  Alex, please don't put this on clojure.org -- it ain't ready 
 yet.

 http://homepage.mac.com/jafingerhut/files/cheatsheet-clj-1.3.0-v1.4-tooltips/cheatsheet-full.html

 Give it a test drive and see what you think.

Slick! :)

I tested the tooltips on chrome, firefox and even on my android. On
chrome I find the tooltip boxes too transparent. On firefox the
transparency is fine but the tooltip font size is bigger than the
font-size used on the page (which IMO could be larger anyway) On the
android, well yea no tooltips appear :) so you need to do this back 
forth clicking as before. Interestingly when you go back then a
tooltip is placed behind the screen edges and it's kind of difficult
to get rid of it. The same appearance like reported here:

 The tooltips themselves seem pretty nice, but on smaller windows, they are
 sometimes placed behind the edges and thus not visible:
 http://i.imgur.com/YA4gF.png

Bost

-- 
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


my first attempt at a macro returns form wrapped in clojure.core/fn

2011-12-15 Thread Peter Buckley
TL;DR I have an extra clojure.core/fn wrapped around the form I want
returned from my macro. This is my first macro and I'm not sure what's
wrong, even though the macro works.

I'm trying my first attempt at a macro by trying to save myself from
having to type sql/with-connection db for every time I want to
invoke a database command. I figure I can type dc (short for
database connection) instead.

I'm doing something wrong but I've tried a few iterations of ', `, ~,
and ~@ the closest I got was this one:

(def db {:classname org.postgresql.Driver
 :subprotocol postgresql
 :subname (str //localhost:5432/shouter)
 :user username
 :password 1234})

(defmacro dc
  [sql-cmd]
  (list 'sql/with-connection 'db
sql-cmd))

This macro works in that it actually invokes the form I want, but when
I run macroexpand on it I have an extra clojure.core/fn wrapped around
my command, and when I compare that output to the when macro (which
does not have the clojure.core/fn wrapper that I can see), I think
I've got it wrong.

user (macroexpand '(when (pos? a) (println positive) (/ b a)))
(if (pos? a) (do (println positive) (/ b a)))

user (macroexpand '(dc (sql/create-table :testing [:data :text])))
(clojure.java.jdbc.internal/with-connection* db (clojure.core/fn []
(sql/create-table :testing [:data :text])))

I've also tried it with  args so I don't have to put my
sql/create-table ... form in parens, but it seems to work even worse
(I've still got the extra clojure.core/fn and now parens are around
the args).

(defmacro dc1
  [sql-cmd  args]
  (list 'sql/with-connection 'db
sql-cmd args))

user (macroexpand '(dc1 sql/create-table :testing [:data :text]))
(clojure.java.jdbc.internal/with-connection* db (clojure.core/fn []
sql/create-table (:testing [:data :text])))

I also tried this variation, which works but instead of returning the
status of the database command (0) as dc did, it returns the last arg
passed in, [:data :text].

(defmacro dc2
  [sql-cmd  args]
  `(sql/with-connection db
~sql-cmd ~@args))

user (macroexpand '(dc2 sql/create-table :testing [:data :text]))
(clojure.java.jdbc.internal/with-connection* user/db (clojure.core/fn
[] sql/create-table :testing [:data :text]))

Any ideas on where I'm specifically going wrong, or where to read
further on macros (preferably simple examples)?

Thanks,
Peter

-- 
The king’s heart is like a stream of water directed by the Lord; He
guides it wherever He pleases.

-- 
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: Thoughts on a polyglot app server?

2011-11-01 Thread Peter Buckley
They announced it today:

http://immutant.org/news/2011/11/01/announcing/

-Original Message-
From: Jason Toy jason...@gmail.com
Sender: clojure@googlegroups.com
Date: Tue, 1 Nov 2011 13:48:54 
To: Clojureclojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: Thoughts on a polyglot app server?

Any more plans or ideas on this?

On Sep 29, 1:48 pm, Jim jcrossl...@gmail.com wrote:
 The TorqueBox[1] team is toying with the idea of exposing to Clojure
 the abstractions we currently expose to Ruby. We're looking for
 feedback from you guys to see what you use now to solve these
 problems, what you'd like to see in a possible Clojure App Server,
 and if you might actually use it.

 If you're not familiar with TorqueBox: it's an application server for
 Ruby apps, allowing you to run them on top of JBossAS[2]. But it goes
 to great lengths to preserve the typical Ruby development experience,
 e.g. no war files or XML.  In addition, it provides the following
 enterprisey features to Ruby, built-in:

 * asynchronous processing (with futures)
 * scheduled jobs
 * XA transactions
 * companion services (daemons)
 * distributed caching
 * messaging (via JMS)

 Coming from a Ruby background, all of the above were pain points for
 us. Do these same pain points exist for Clojure apps?

 TorqueBox also supports clustering, which allows load balancing of the
 web component as well as cache distribution and horizontal scaling of
 async tasks, scheduled jobs, and services. Clojure has built in async
 processing and futures, but they use an in VM thread pool, correct?
 How would you scale that?

 A common TorqueBox idiom is to leverage Ruby in the web tier and Java
 in the services/data tier. Are there any Ring-based frameworks that
 make Clojure more appealing than Ruby in the web tier?

 Or does integrating a Ruby web app with a colocated Clojure service
 make more sense? It should be fairly easy to loosely couple them via
 messaging.

 Speaking of which, if you are using Clojure to process data generated
 by other apps/languages, how is that data communicated? Would language
 agnostic messaging be useful here?

 How do you currently run production code (web apps or otherwise)?

 We'd love to open a dialog about these and other things. Any feedback
 you care to share is appreciated, either here, or in #torquebox on
 Freenode. Toby Crawley and I will be in Raleigh for Clojure/conj as
 well, so we look forward to meeting you there!

 Thanks!

 [1]:http://torquebox.org/
 [2]:http://www.jboss.org/jbossas

-- 
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: Rounding the edges of an Emacs beginner

2011-09-14 Thread Peter Buckley
In emacs you can give a number to preface many commands, e.g. C-37 C-n will 
perform next line 37 times, and C-37 C-p will perform previous line 37 
times. You can setup keybindings for these as well, but I find the basic 
navigation commands like C-v/M-v (up/down a page) and C-l (center current line 
in the buffer) to be sufficient. 

-Original Message-
From: Timothy Washington twash...@gmail.com
Sender: clojure@googlegroups.com
Date: Wed, 14 Sep 2011 20:08:28 
To: clojure@googlegroups.com
Reply-To: clojure@googlegroups.com
Subject: Re: Rounding the edges of an Emacs beginner

Far out - this is great stuff. Thanks guys.

Wrt to moving down (or up) a block, vim-style, what I mean is the following
(all functionality in 'Command Mode').

In Vim , you press *Ctrl-d* and *Ctrl-u* to go down and up a block
respectively. Depending on the size of your window, it moves the cursor
about 1/3rd of the way down (or up) the screen. This is very handy to have
when just browsing a buffer. You can be more precise by pressing 37k, to
move the cursor up 37 lines, etc.

For whatever reason, I haven't been able to find something similar in
Emacs.


Tim


On Wed, Sep 14, 2011 at 3:53 AM, Stefan Kamphausen
ska2...@googlemail.comwrote:

 Hi,

 just a few follow-ups...

 On Wednesday, September 14, 2011 4:13:47 AM UTC+2, frye wrote:

- ? howto list modes engaged

 Aside from the already mentioned C-h m (aka M-x describe-mode) you will
 want to use

 * C-h k (M-x describe-key) followed by some keybinding to find out what
 that keybinding does
 * C-h w (M-x where-is) followed by the name of some command to find out
 what keybinding exists for that command
 * C-h a PATTERN (M-x apropos) to search for PATTERN in command names and
 variables (ah, I miss hyper-apropos from XEmacs)
 * C-h v VARIABLE (M-x describe-variable) to see the documentation for a
 variable in ELisp (use C-c C-d d on Clojure symbols to see their
 documentation from SLIME)
 * C-h f FUNCTION (M-x describe-function) to see docs for an Elisp-function
 * and finally C-h ? to find out what other help is available

 The built-in help system of Emacs is one of its greatest strengths.


-

? Can you use Emacs / Slime / CDT (debugging) with Ruby / Rails

 ? howto do Code completion (clojure, and elisp )


 Try TAB in the REPL and M-TAB in a Clojure-buffer when you are connected
 to a running image.


 As a VIM'er, I'm trying to do the following using emacs navigation, but
 seem to have missed the levers to pull. I'm using a vim navigation 
 pluginhttp://gitorious.org/evil/pages/Home,
 which helps a lot.


- ? set line numbers


 I use linum.el written by  Markus Triska:
 (when (try-require 'linum) ;; try require is just a minor wrapper which
 checks, whether a lib is available
   (global-linum-mode))


- ? go to line 'n'

 Since my fingers are used to M-g I bind that key to goto-line :
 (global-set-key (kbd M-g) #'goto-line)


- ? how to jump to matching parentheses

 Meta with left and right cursor keys. Actually those are forward-sexp and
 backward-sexp


- ? move down a chunk like in vim

 What does that mean?


- ? yank 'n' lines - emacs yank puts back some 'killed' text ; HOWTO
copy

 Mark things by first enabling the mark with C-SPC. Move around using your
 usual command.  Copy to the kill-ring with M-w or cut the text and copy it
 to the kill-ring using C-w.  After that you can yank (Emacsspeak for
 'paste') from the kill ring with C-y.  Try M-y right after a C-y to get
 older elements on the kill-ring. For marking, try what C-M-SPC does, also
 hit it several times in a row.
 Warning: if your finger's memory learns this, using modern IDEs may feel
 awkward.

 Regards,
 Stefan

  --
 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: Conj arrivals and Thursday night...

2010-10-18 Thread Peter Buckley
I'll be arriving between 9:30 and 10pm, and I expect to be up for some
coding or a drink, or perhaps a little of both.

-Peter

On Mon, Oct 18, 2010 at 2:12 PM,  lprefonta...@softaddicts.ca wrote:
 Count me out, pretty sure I'll need a drink by the time I arrive (21:00).
 I like so much airplane travels, livestock receives more attention from their
 carriers than airline passengers these days. Meuh !

 Luc P.

 Ryan Waters ryan.or...@gmail.com wrote ..
 I probably wouldn't be able to show up until 8:00pm but I'd be
 interested in getting on the 'list' for said group.

 Thanks,
 Ryan


 On Mon, Oct 18, 2010 at 11:32 AM, Andrew Gwozdziewycz apg...@gmail.com 
 wrote:
  Hey Conj goers,
 
  I'm scheduled to arrive around 6:30, and after I check in am planning
  to spend the rest of the night writing code. Anyone want to help
  commandeer a random lobby to join in on the fun?
 
  Andrew
  --
  http://www.apgwoz.com
 
  --
  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



-- 
The king’s heart is like a stream of water directed by the Lord; He
guides it wherever He pleases.

-- 
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: picking out a tag from a nested struct-map and xml-seq

2010-09-03 Thread Peter Buckley
Thanks Abishek, this did help!

It pretty much worked as-is for me, I only needed one small change.

It was that the get-mods-for-iva function below returns a seq whose
first element is the matches and next element(s) were my entire xml
content - easily rectified with (first (xz/xml1- x-zip...

On Tue, Aug 31, 2010 at 11:25 PM, Abhishek Reddy arbs...@gmail.com wrote:
 Hi Peter,

 The library clojure.contrib.zip-filter is pretty good at this sort of thing.
 For example:

 (require '[clojure.xml :as xml])
 (require '[clojure.contrib.zip-filter.xml :as zx])
 (require '[clojure.zip :as zip])

 (defn get-mods-for-iva
   Returns the mods node if one exists under a version node
    whose inner-ver-attrib matches test-iva.  Otherwise, returns nil.
   [x-zip test-iva]
   (zx/xml1- x-zip
  (zx/tag= :version)
  (zx/attr= :inner-ver-attrib test-iva)
  (zx/tag= :type)
  (zx/tag= :mods)))

 (defn get-replacement-values
   Returns a seq of mods nodes if available in x-file for versions
    1.4 and 1.6 respectively.
   [x-file]
   (let [x-zip (zip/xml-zip (xml/parse x-file))
     test-ivas [1.4 1.6]]
     (map (partial get-mods-for-iva x-zip) test-ivas)))

 ``clojure.contrib.zip-filter.xml/xml1-'' filters an xml-zip tree
 using predicates on tags, attributes or text values of nodes.  You can
 chain predicates together (like in ``clojure.core/-'') to navigate
 trees conditionally.  If a predicate returns false or nil, the whole
 form returns nil, so you know there is no complete match.

 In the ``get-mods-for-iva'' function above, we start with the complete
 tree ``x-zip'', and filter for version, then
 version inner-ver-attrib=test-iva, then type, and finally mods.

 In ``get-replacement-values'', we parse the XML file and derive an
 xml-zip tree from it.  We then call ``get-mods-for-iva'' for each of
 the pre-defined versions, and return a seq of their results.

 This may not be the best solution, and I may have misinterpreted your
 exact XML structure, but the code shows a simple, functional style.
 We try to avoid do* forms and side effects (printing during calculation)
 where possible, collecting results of function calls instead.

 I hope it helps!


 On Wed, Sep 1, 2010 at 7:10 AM, Peter buckmeist...@gmail.com wrote:

 Hi-

 I'm brand new to Clojure and FP, reading a bunch and working on my
 first programming task (reading in values from an xml file and a text
 file and then creating a new text file with some lines/sections of the
 original text file replaced based on the content of the xml).

 I found some helpful info here:
 http://www.chrisumbel.com/article/clojure_xml_parsing_xml-seq
 on reading the xml file, but I'm a couple more levels deep than that
 article. I don't know much about Clojure yet, but I have a feeling I'm
 not doing it the right/idiomatic/best way. I've basically got three
 nested calls to doseq, and I think it is mostly due to my own
 unfamiliarity with Clojure and the better options I would have to do
 this in FP.

 I'm getting the ver tag in the xml then checking one of its attribs to
 make sure I'm pulling from the version I want, and then I get the
 content of the mods tag. I've tried to somewhat simplify this case so
 the following isn't tested after being extracted from my sandbox.

 TIA!

 (defn- dig-through-struct
  Hides a pair of nested doseq calls from my main function
  [xml-as-struct]
  (doseq [y (:content xml-as-struct)
          :when (= :type (:tag y))]
    (doseq [z (:content y)
            :when (= :mods (:tag z))]
    (println The content I want (:content z)

 (defn- get-replacement-values
  Pulls from xml values we want to replace/update/add
  [x-file]
  (let [xml-file (File. x-file)]
    (xml-seq (parse xml-file))
    (for [testing-ver `(1.4 1.6)]
      (doseq [x (xml-seq (parse xml-file))
              :when (= :ver (:tag x))]
        (let [iva (:inner-ver-attrib (:attrs x))]
          (if (= testing-ver iva)
            (dig-through-struct x testing-ver iva)
            (println Did not match the ver we want testing-ver iva)))

 And this is my xml:

 proj
 bunch of attribs
 ...

 ver
 inner-ver-attrib=1.4 (or 1.6 etc, this is a tag I'm interested in
 conditionally checking)
 bunch of attribs
 ...

 type
 bunch of attribs
 ...

  mods
    remove
      entry-namefiles/entry-name
      entrypath_old\foo_old.c/entry
      entrypath_old1\foo_old.h/entry
    /remove
    add
      entry-namefiles/entry-name
      entrypath\foo.c/entry
      entrypath1\foo.h/entry
    /add
    change
      entry-nameopts/entry-name
      from-bar=1/from
      to-bar=2/to
    /change
  /mods
 /type/version/project

 --
 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
 

Re: Thinking in Clojure

2010-09-03 Thread Peter Buckley
I'm only a little ways through Joy of Clojure (my first Clojure book)
but bear with me as I'm thinking aloud on what it means for me to
think in Clojure. I hope list members will forgive me if I get
things wrong - and please correct my working concept(s) as well.

One of the things that stuck out for me that I heard somewhere (can't
remember exactly) was that OOP is about framing questions in terms of
nouns and FP is about framing questions in terms of verbs.

Partly for my own benefit (and the list's critique and refinement) I
want to talk about this as it relates to an example. The first task
I'm working on in Clojure is taking a text file which is sortof a
template, and then removing/adding/changing certain lines/strings in
it based on an xml kindof config file, in the end spitting out an
improved text file.

If I was in the OOP frame of mind, I would have a class to represent
my text file, and a class to represent my xml file. There would
possibly be a shared base class to let me share the common slurping
(reading of lines) from the files. As verb-y as that is (I hope
Clojure is polluting my thought process already!) the base class would
probably be called File or something super noun-y. In any case, the
classes, the files, these are all nouns.

But in the FP frame of mind, I just have data or information, and the
focus is on the transformations that I do with the data. The
transformations are things like zip-my-xml-into-a-struct-map or
read-my-lines-into-a-seq and replace-text-values-with-xml-values. The
focus is on the actions (verbs being action words), and the functions
are essentially the verbs.

I feel like I'm starting to get the concept of thinking in a
function-al way, although I have a lot of work to do yet on learning
Clojure the language.

HTH,
Peter

On Thu, Sep 2, 2010 at 10:02 PM, Wilson MacGyver wmacgy...@gmail.com wrote:
 I highly recommend Joy of Clojure. It's a good 2nd book on clojure.
 It shows you the why things are the way they are, and how to
 do things the clojure way as much as possible.

 On Thu, Sep 2, 2010 at 9:29 PM, HB hubaghd...@gmail.com wrote:
 Hey,
 I finished reading Programming Clojure and Practical Clojure and
 I'm hooked :)
 Please count me in the Clojure club.
 But I failed how to think in Clojure.
 My main career is around Java web applications (Hibernate, Spring,
 Lucene) and Web services.
 Lets not talk about Java web frameworks neither Clojure ones, I want
 to talk in general.
 Usually we create some domain entities, map them with Hibernate/
 iBatis.
 I don't know how a Clojure application would be build without objects.
 I think Scala really shines here, this OOP/FP is really powerful
 approach (please note I'm not saying Clojure isn't good, I don't seel
 flame war)
 How to think in Clojure? how to achieve this shift?




 --
 Omnem crede diem tibi diluxisse supremum.

 --
 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



-- 
The king’s heart is like a stream of water directed by the Lord; He
guides it wherever He pleases.

-- 
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