Re: ANN: A pretty printer for Clojure

2009-03-14 Thread budu

I just tried it, this is fantastic! We'll finally be able to debug
macros while keeping our sanity. Many thanks for this and I hope it
will be added directly into Clojure.

On Mar 12, 3:05 am, Tom Faulhaber tomfaulha...@gmail.com wrote:
 I have now released the first version of my pretty printer as part
 of my cl-format library. It is released under the EPL.

 The pretty printer has two functions that you probably care about:

 (pprint obj) will pretty print the given object, and
 (pp) at the REPL will pretty print the last result output, i.e. the
 value in *1.

 The pretty printer currently supports two modes: simple and code.
 Simple mode prints structure in a standard way that's good for data.
 Code mode understands lots of Clojure forms (defn, binding vectors,
 condp, etc.) and attempts to print them in an idiomatic way.

 Cl-format is on github athttp://github.com/tomfaulhaber/cl-format.
 There is a Readme there with instructions, examples, limitations and
 futures. I won't even try to put examples here, because google groups
 wreaks havoc on formatting.

 The simplest way to get some pretty printing happiness:
 1) Download the 
 jar:http://github.com/tomfaulhaber/cl-format/raw/master/release/cl-format...
 2) Put it in your classpath.
 3) Fire up your REPL
 4) (use 'com.infolace.format)
 5) Use pprint and pp as described above.

 This is definitely a first release and there are sure to be bugs. And
 I know there are things missing. So let me know if you're having
 problems and I'll try to get things fixed up ASAP.

 Enjoy!

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



Identifying maps.

2009-03-10 Thread budu

Hi, I've just read the On the importance of recognizing and using
maps post and it made wonder about the best way for identifying maps.
Obviously, when the situation permit it, we better use some kind of
label to identify them. But sometimes, it's preferable to test for
multiple keys and I'm not sure what's the best way to do this. We can
use contains? but it takes only one key. I've made a modification to
contains? so that it can take many keys as shown in the patch below.

P.S.: I've still not mailed a contributor agreement, tried to send it
two months ago, but it came back. I had totally forgotten about
postage stamps! It's astonishing how the web can make you used to get
stuff for free ;-) I'll try again this week with stamps this time!

--- src/clj/clojure/core.clj(revision 1301)
+++ src/clj/clojure/core.clj(working copy)
@@ -900,7 +900,16 @@
   vectors and Java arrays, this tests if the numeric key is within
the
   range of indexes. 'contains?' operates constant or logarithmic
time;
   it will not perform a linear search for a value.  See also 'some'.
-  [coll key] (. clojure.lang.RT (contains coll key)))
+  ([coll key] (. clojure.lang.RT (contains coll key)))
+  ([coll key  keys]
+ (loop [keys (cons key keys) acc true]
+   (if keys
+ (let [key (first keys)
+   res (and acc (. clojure.lang.RT (contains coll key)))]
+   (if (and res (seq? keys))
+ (recur (next keys) res)
+ res))
+ acc

 (defn get
   Returns the value mapped to key, not-found or nil if key not
present.

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



Turning a sequence of chars into a string.

2009-01-25 Thread budu

Hi everybody, since I started using Clojure I've always felt that a
small function for turning a sequence of chars into a string was
missing. I'm currently using this one even though the name isn't quite
right, but I didn't found better:

(defn unseq [chars]
(new String (into-array (. Character TYPE) chars)))

So, is there a better way to accomplish this? Then, do someone have a
better name for it? And finally, would this be worth including into
Clojure or Clojure-contrib, with a better name?

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
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 now running in production

2009-01-14 Thread budu

Congratulation, this is quite amazing to see Clojure mature so fast
and already working in production system. Sorry but I need to get back
at finding that damn bug in a 10 years old VB legacy application :-(

On Jan 13, 10:38 am, Luc Prefontaine lprefonta...@softaddicts.ca
wrote:
 Hi everyone,

 as of yesterday pm, Clojure is running in a live system in a big
 veterinarian hospital.

 We designed an HL7 message bus to link several services within the
 hospital.
 Presently we link the medical record system with the radiology
 department.
 The main benefit is to avoid re-keying information about patient and
 requests in every system.

 We also provide some key applications on the bus to allow people to
 share information in a consistent
 way along the system they use on a daily basis. It's like a Babel tower,
 radiologists want to work
 with their radiology system while the administration wants to work with
 the medical record system to
 bill, ... each of these systems meet specific needs of a user base.
 However there is a need for a common ground to share information. That's
 what our product offers.

 This year the bus will expand to encompass prescription requests with
 the pharmacy, the lab exams
 and a couple of other systems. We have also another prospect so we may
 end up with more than one site
 by the end of 2009.

 The bus is designed to be a product, not a set of integration tools to
 be assembled differently
 at each customer site. It is highly configurable, all message based and
 runs on distributed hardware.

 Clojure drives the top level logic of the bus (routing decisions, error
 handling, archiving, ...).

 After digging for some parallel processing language better than Java,
 Clojure emerged as a logical choice.
 The design of this system is distributed with fault tolerance in every
 software function but we needed to have
 some options about the low-level components. Having access to all Java
 libraries out there was a major factor
 in our decision to use Clojure.

 Presently it runs on six small boxes like this one:

 http://www.fic.com.tw/product/ficimages/minipc.jpg

 with an internal redundant network. Each function is running in
 master/slave mode with automatic fail over.
 The throughput of the system is at least two thousands transactions an
 hour. You can unplug cables, boxes, ...
 and it still runs. It can sustain more than one fault before it fails.

 In the following year using Clojure and Terracotta we expect to bring
 the degree of parallelism up to a point were we will
 be able to run concurrently all the functions on multiple boxes and get
 rid of the master/slave mode.
 Distributed clusters are also in the pipe to allow to route between
 different sites while keeping local site traffic and different local
 applications.

 Expect a web site about this product in the next 2/3 months. We will
 give Clojure visibility on this site.
 Many of the key features of the system rely on Clojure so we would like
 to give credit to Clojure and Rich.
 Maybe this will be an incentive for people to look at Clojure as a
 viable alternative to other functional
 languages.

 Rich, thank you and congratulation, your baby has grown up well in the
 last year and it will soon be asking for the car keys :

 Luc
--~--~-~--~~~---~--~~
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
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: update-values for clojure.contrib.sql

2009-01-02 Thread budu

D'oh! I have a hard time kicking out that old habit. And changing code
after testing it too!

On Jan 2, 4:21 am, Christian Vest Hansen karmazi...@gmail.com
wrote:
 Well, one thing that sticks out (particularly to me) is the fact that
 you forgot to put your doc-string *before* your [params*] list :)
 (ahem)



 On Fri, Jan 2, 2009 at 8:21 AM, budu nbudu...@gmail.com wrote:

  Hi, I was experimenting with clojure-contrib's sql features and found
  that there wasn't any update-values function. I've written my own and
  I'm sharing it here:

  (defn update-values [table where column-names  values]
   Update columns of a table with values. columns-names is a vector of
   column names (strings or keywords) and the rest of arguments are the
   values for those columns.
   (let [columns (map #(str (the-str %)  = ?) column-names)
         template (if (seq column-names)
                   (apply str (interpose , columns))
                   )]
     (apply do-prepared
            (format update %s set %s where %s
                    (the-str table) template where)
            [values])))

  It only send one set of values to do-prepared because of the where
  clause that would have to change according to each sets. I'm ready for
  your commentaries and/or suggestions.

 --
 Venlig hilsen / Kind regards,
 Christian Vest Hansen.
--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



update-values for clojure.contrib.sql

2009-01-01 Thread budu

Hi, I was experimenting with clojure-contrib's sql features and found
that there wasn't any update-values function. I've written my own and
I'm sharing it here:

(defn update-values [table where column-names  values]
  Update columns of a table with values. columns-names is a vector of
  column names (strings or keywords) and the rest of arguments are the
  values for those columns.
  (let [columns (map #(str (the-str %)  = ?) column-names)
template (if (seq column-names)
  (apply str (interpose , columns))
  )]
(apply do-prepared
   (format update %s set %s where %s
   (the-str table) template where)
   [values])))

It only send one set of values to do-prepared because of the where
clause that would have to change according to each sets. I'm ready for
your commentaries and/or suggestions.
--~--~-~--~~~---~--~~
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
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: French translation of the Clojure rationale

2008-11-24 Thread budu

Wow, jamais je n'aurais pensé lire des commentaires à propos des
problèmes de prononciation de madame Marois ce matin. Comme on dit au
Québec: Osti qu'j'ai hâte qu'les élections finisse!

Sorry about being offtopic ;-)

On Nov 22, 11:35 am, Luc Prefontaine [EMAIL PROTECTED]
wrote:
 Salutations aux cousins outre-Atlantique,

 Je ne veux pas vous décourager mais effectivement la maîtrise de
 l'anglais au moins au niveau de la lecture est
 plutôt incontournable en informatique. J'ai un associé du coin
 d'Aix-en-Provence et un autre d'Algérie qui n'ont pas eu le
 choix à leur arrivée ici. Pourtant ici il y a une majorité qui ne
 maîtrise pas l'anglais (et souvent le français d'ailleurs).

 Il y a 25 ans je me suis tapé la lecture d'une partie de la doc d'IBM
 sur mainframe en français (traduction faite en France).
 Les ventes d'IBM à l'époque ne vendaient pas de la camelote pour leurs
 clients vu les prix auxquels ils vendaient leurs gros monstres
 donc c'était un travail de traduction fidèle.

 J'en suis vite arrivé à une indigestion. Le volume du texte était
 supérieur d'au moins 30% à son équivalent anglais
 et de plus la référence à des acronymes à toutes les 2 phrases,
 acronymes évidemment tous en anglais, rendait la
 lecture des plus ardue. Passer d'une langue à l'autre pas de problèmes
 mais 20 ou 30 fois dans la même page de texte ?

 En ce qui a trait à Clojure, l'intro en français ça peut aller pour
 accrocher l'oeil et susciter de l'intérêt
 mais pour le reste juste à penser au travail d'entretien que ça va
 demander à chaque fois que la doc originale en anglais est modifiée...
 disons que je pense que l'énergie devrait être mise ailleurs.

 De toute façon un autre problème qui va se poser c'est que toute
 référence externe à cette documentation a 99% de chance d'être... en
 anglais !

 Non je ne suis pas un fan du Parti Québécois dont la chef qui aspire à
 la gouvernance de la province maîtrise l'anglais moins bien qu'une vache
 espagnole.
 Ça vous pouvez vous en douter à la lecture de ce qui précède mais je
 pense qu'il y a des réalités qu'il faut savoir reconnaître...

 Bonne chance tout de même, cousins :)))

 A+

 Luc
 Montréal, Québec

 On Sat, 2008-11-22 at 04:43 -0800, peg wrote:
  j'ai  oublié ... peut être la traduction d'un article comme celui-ci
  serait-elle plus démonstrative / pédagogique :

 http://www.defmacro.org/ramblings/fp.html

  article référencé ici-même il y a quelques temps

  On Nov 22, 1:40 pm, peg [EMAIL PROTECTED] wrote:
   Bonjour,
   Je peux aussi aider à la traduction mais je pense aussi qu'un
   didacticiel serait bienvenue plutot qu'un introduction générale.
   Démonstration de l'efficacité par l'exemple.
   Phil (from Paris)


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: packaging App (cross-platform) without scripts, only jar

2008-09-20 Thread budu

Thanks a lot! It's funny that you wrote this post now because I was
about to try to figure it out myself this week-end.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Binding dynamically created symbols in the lexical context.

2008-08-29 Thread budu

Thank you very much! Your trick worked and it even made me realize
that the match-forms function is not even required. I've replaced it
by a much more simple is-match? function and completely overhauled the
match macro.

Here's the new code with your corrections, some other improvements and
an example of how I intend to use it:

(defn result [v] #(list [v %]))

(def zero (fn [s] ()))

(def item
  #(cond (= 0 (. % length)) ()
 true (list [(. % (charAt 0))
 (. % (substring 1))])))

(defn bind [p f]
  (fn [s]
 (let [r (p s)]
   (if (= 0 (count r)) r
   (mapcat #(let [[v s] %] ((f v) s)) r)

(defn sat [p]
  (bind item #(if (p %) (result %) zero)))

(defn pchar [c] (sat #(= % c)))

(defn is-match? [p t]
  (if (and (seq? p) (= 'quote (first p)))
(= t (second p))
(symbol? p)))

(defmacro match [value  clauses]
  (when (and clauses (= 0 (rem (count clauses) 2)))
(let [[c1 c2  cr] clauses
  only-sym #(or (not (symbol? %)) (= '_ %))
  syms (map #(if (only-sym %) (gensym) %) c1)]
  `(if (and (every? identity (map is-match? '~c1 ~value))
(or (some (fn [x#] (= ' x#)) '~c1)
(= (count '~c1) (count ~value
 (if (= 0 (count '~syms)) false
 (let [~(vec syms) ~value] ~c2))
 (match ~value [EMAIL PROTECTED])

(defn- parser-error []
  (new Exception Parser must end with non-binding form.))

(defn- expand-parser-body [body s]
  (let [rec (fn [p xs]
  `(let [r# (~p ~s) ~s (second (first r#))]
 (if (= 0 (count r#)) r#
 ~(expand-parser-body xs s]
(match body
   (_ '- _) (parser-error)
   (p) (list p s)
   (v '- p  xs) (rec p xs)
   (p  xs) (rec p xs

(defmacro parser [ body]
  (let [s (gensym 's)]
`(fn [~s] ~(expand-parser-body body s

(defn split [s]
  (if (= 0 (count s)) []
  [(. s (charAt 0))
   (. s (substring 1 (count s)))]))

(defn join [c s]
  (. String (format %c%s (to-array [c s]

;; string :: String - Parser String
(defn string [s]
  (if (= 0 (count s)) (result )
  (let [[x xs] (split s)]
(parser _ - (pchar x)
_ - (string xs)
(result (join x xs))

user= ((string hello) hello world)
([hello  world])

It's a straitforward implementation of the parser combinators
described in the Monadic Parser Combinators papers by Hutton and
Meijer.

Thanks again!!!

On Aug 26, 11:57 pm, Chouser [EMAIL PROTECTED] wrote:
 On Sun, Aug 24, 2008 at 6:02 PM, budu [EMAIL PROTECTED] wrote:

  Well, for now only the value s used by the parser macro is really
  needed.

 I think you misunderstood me, but I'm not too sure.  Anyway, here's an 
 attempt:

 (defn match-forms [p s]
   (if (= '_ p) []
     (loop [p p s s vars []]
       (cond
         (and (= 0 (count p)) (= 0 (count s))) vars
         (= 0 (count s)) nil
         :else (let [[fp  rp] p [fs  rs] s]
                 (cond
                   ;; wildcard pattern
                   (= '_ fp) (recur rp rs vars)
                   ;; rest
                   (and (symbol? fp) (= ' fp))
                   (conj vars (first rp) (conj rs fs))
                   ;; add variable to bindings
                   (symbol? fp) (recur rp rs (conj vars fp fs))
                   ;; match a symbol
                   (and (seq? fp) (= 'quote (first fp)))
                   (if (= fs (second fp)) (recur rp rs vars) nil)
                   ;; not matching
                   true nil))

 (defmacro match [value  clauses]
   (when (and clauses (= 0 (rem (count clauses) 2)))
     (let [[c1 c2  cr] clauses
           syms (take-nth 2 (match-forms c1 c1))]
       `(if-let m# (take-nth 2 (rest (match-forms '~c1 ~value)))
          (let [~(vec syms) (vec m#)]
            ~c2)
          (match ~value [EMAIL PROTECTED])

 The trick here is I run match-forms once at compile time to get the
 list of symbols that will need to be bound, even though I don't have
 the real values yet.  I use that list to set up a let expression.
 At runtime, I run match-forms again, but only take the values part and
 drop that into the let that I set up at compile time.

 That's probably not the best way to solve the problem, but it is *a*
 way, and may help you find a more correct solution.  ...and since I
 don't really understand what you're trying to do, I had only limited
 tests that I could try, so I've probably introduced some new bugs.
 But at the very least, your original examples now work:

 user= (match '(1 2 3) (a b c) (list c b a))
 (3 2 1)
 user= (let [z 4] (match '(1 2 3) (a b c) (list z c b a)))
 (4 3 2 1)

 --Chouser
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit