Re: Question about data structures and encapsulation

2011-06-16 Thread Alessio Stalla
On Jun 16, 2:59 am, Colin Yates  wrote:
> Thanks for all the help, all of you.  The Clojure community has a reputation
> for being helpful :)
>
> The example of age as a property which might change from a value to a
> function was indeed a strawman, but it was just an example.  So the
> consensus seems to be that yes, that requirement is hard to solve, but as
> Sean states, it isn't a particularly common occurrence.  KISS with maps
> seems to be the way to go.
>
> Thanks again!

FWIW, in Common Lisp the two main record-like types of objects
(structs and classes) are defined using macros that have the option of
generating accessor functions for you. Also typically when using raw
lists as data structures it is considered good practice to define
functions that abstract the access to their elements.
If defining functions manually for your maps is tedious, consider
coding a macro that does it for you. Note that, unlike accessor
methods in OO classes, accessor functions for maps/lists cannot be
polymorphic in the type of the data structures they access, so they
typically end up encoding the name of the data structure in their own
name, e.g person-age.

Cheers,
Alessio

-- 
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: Tutorial about web development with Clojure

2011-06-16 Thread Can Arel
Thanks , very helpful!

2011/6/11 Tarantoga 

> Hi all,
>
> I have implemented a small blog (posts, comments, authentication) with
> Clojure using the Rails-like style of development. It is located here:
> https://github.com/dbushenko/ClojureBlog. The blog uses the following
> principles:
> 1) MVC architecture;
> 2) RESTfull design;
> 3) Convention over configuration;
> 4) DRY (Don't repeat yourself);
> The code contains lots of comments. Hope it will be useful for Clojure
> web developers.
>
> --
> 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: using regex reader macro with generated code

2011-06-16 Thread Ken Wesson
On Wed, Jun 15, 2011 at 10:47 PM, Alex Baranosky
 wrote:
> IS it possible to use the regex reader macro #"" with generated code?  What
> I mean is do something like:
> #"${(join "|" (range 1 1))}"
> I'm using ${...} to mean string interpolation, though I know Clojure doesn't
> have that syntax.  Is there a way to get this effect or must I use
> (re-pattern (join "|" (range 1 1)))

The latter. You'd need user-defined read macros for the former.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: using regex reader macro with generated code

2011-06-16 Thread Rasmus Svensson
2011/6/16 Alex Baranosky :
> IS it possible to use the regex reader macro #"" with generated code?  What
> I mean is do something like:
> #"${(join "|" (range 1 1))}"
> I'm using ${...} to mean string interpolation, though I know Clojure doesn't
> have that syntax.  Is there a way to get this effect or must I use
> (re-pattern (join "|" (range 1 1)))
> Thanks for the help!
> Alex

When you generate code programmatically (e.g. in a macro), you
generate the data structures as objects rather than their string form.
Consider this macro*:

(defmacro unless [cond-expr false-expr true-expr]
  (liist 'if cond-expr true-expr false-expr))

To make the (if ...) list you don't dive into the string
representation of this data structure -- i.e. you don't try to do
something like (str "(if " cond-expr " " ... ")"). You should think
about what kind of objects the syntax represent and try to generate
those instead. Code is data. The string representation is only for
storing code in files and interacting with a human. Clojure itself
works with the data as objects.

To construct a regex pattern object re-pattern is the function to use,
as you already know. There is no reason to dive into string syntax. If
you happen to want to serialize this object later (e.g. print it at
the repl or dump it to a text file), this regex object will print as
an ordinary regex literal.

* Using syntax-quote is probably more ideomatic here.

// Rasmus Svensson (raek)

-- 
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 about data structures and encapsulation

2011-06-16 Thread Vincent
 nice podcast  

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

Re: Tutorial about web development with Clojure

2011-06-16 Thread Junior Zhang
So cool!

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

Vote for Clojure as Most Innovative Java Technology

2011-06-16 Thread Stuart Sierra
Do you think Clojure is the Most Innovative Java Technology of 2011?

Vote here:  http://vote.jax-awards.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

Re: Vote for Clojure as Most Innovative Java Technology

2011-06-16 Thread Ambrose Bonnaire-Sergeant
Where's the "Most Innovative of the last decade" button?

:)

--
Ambrose

On Thu, Jun 16, 2011 at 8:58 PM, Stuart Sierra
wrote:

> Do you think Clojure is the Most Innovative Java Technology of 2011?
>
> Vote here:  http://vote.jax-awards.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

Re: clojure-csv Column or field extraction

2011-06-16 Thread octopusgrabbus
I would like to modify the examples given

user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
#'user/csv
user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
"6"
user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
"6"
user=> (defn get-column [parsed-csv col] (map #(nth % col)
parsed-csv)) ;; Function to return a given column.
#'user/get-column
user=> (get-column csv 1) ;; Get second column as a sequence.
("2" "5" "8")

to read in a .csv file, and then perform the functions on the parsed
csv file, but I am getting clojure.lang.LazySeq cannot be cast to
clojure.lang.IFn.

How do I do this properly?
Thanks.

On Jun 16, 12:20 am, David Santiago  wrote:
> Here's a repl session that will hopefully demonstrate how to do a few
> things, including pull out an entire column. Just remember the library
> turns CSVs into regular clojure data structures, so getting the data
> you want out of the return value of the parse is just about indexing
> into vectors.
>
> user=> (use 'clojure-csv.core)
> nil
> user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
> #'user/csv
> user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
> "6"
> user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
> "6"
> user=> (defn get-column [parsed-csv col] (map #(nth % col)
> parsed-csv)) ;; Function to return a given column.
> #'user/get-column
> user=> (get-column csv 1) ;; Get second column as a sequence.
> ("2" "5" "8")
>
>   - David
>
> On Wed, Jun 15, 2011 at 9:58 PM, octopusgrabbus
>
>
>
>
>
>
>
>  wrote:
> > I've got to go back and look at your documentation. I'm not sure how
> > to pull the columns out of each row.
>
> > On Jun 15, 5:04 pm, David Santiago  wrote:
> >> I'm afraid I don't understand the question. What do you mean
> >> "positionally?" When it parses the CSV file, it gives you back a
> >> stream of rows, each row being a vector of the contents of each cell
> >> of the CSV. If you are interested in cells at a given row/column, you
> >> should be able to count into those vectors fairly naturally...
>
> >>    - David
>
> >> On Wed, Jun 15, 2011 at 2:08 PM, octopusgrabbus 
> >> wrote:
> >> > Is it possible to use clojure-csv to extract data positionally in
> >> > a .csv file, or should I use BufferedReader to read each line lazily
> >> > and apply splitting the line up into fields by delimiter?
>
> >> > Thanks.
> >> > cmn
>
> >> > --
> >> > 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


Clojure Agents at AGERE! @ SPLASH (?)

2011-06-16 Thread aricci
Dear Clojurers

given the Clojure support to concurrent programming and in particular
to a notion of "agent", I thought you may be interested to a workshop
running in SPLAH 2011 called

AGERE!

devoted to foster the discussion and research about

ACTORS and AGENTS

as paradigm for computer programming,
as natural evolution (?) of the OO one,  embracing a

decentralized mindset

in thinking about problems and designing, programming systems.

In other words:

"Programming systems, languages, applications
based on agents, actors, and decentralized control"

It is meant to synergetically mesh up ideas, discussion and results
about
agent and actor systems  that appeared in many contexts
- from (OO) concurrent programming to distributed AI

but here with a specific objective, which is exploring their value
(and development) as paradigm for computing, designing, programming,

You can read more here: http://agere2011.apice.unibo.it

We setup also a Google group AGERE! at SPLASH:

https://groups.google.com/group/agere-at-splash?hl=en

open to everyone that would like to discuss and interact about these
topics,
and contribute to the event (which will be in October).

It is like to say: "Let's start the workshop now!".

Best,
Alessandro, one of the co-organizers of AGERE!

-- 
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 about data structures and encapsulation

2011-06-16 Thread Mikkel
This could be one way to solve the problem in the example and keep a
uniform API:
(def joe {:age ((fn [] (- 2011 1979)))})
(:age joe)
#> 32

Any comments on that?

On Jun 15, 8:41 pm, Colin Yates  wrote:
> Newbie so go gentle please :).  
>
> I am an experienced OO Java developer (decade +) considering jumping fence
> to a functional language, and clojure is pretty high up on the list for a
> number of reasons.
>
> I am so used to defining everything as objects which are sealed units of
> state and behaviour that I am struggling to see how to solve the same
> problem with clojure.  I desperately wish somebody would write a "domain
> driven design with clojure" :).
>
> In brief, in OO state is exposed via a well defined API.  That state may be
> simple properties (values) or it may be calculations (functions).  And
> critically, the decision as to whether it is a value or a function is an
> implementation concern.  The Java Bean spec defines accessors for properties
> of a class, behind which lies the logic of how to retrieve that state.  So,
> the very common Person class will expose get/setName(), get/setAge() etc.
> and as a consumer I have no idea how the results are calcualted.
>
> In Clojure, if I understand correctly, the preferred way would be to use a
> map (or defstruct) with keys such as :name and :age.  These are then
> retrieved as (person :name) and (person: age) etc.  
>
> My question is if I suddenly decided that one of those values is best
> implemented as a calculation, how can I seamlessly implement that.  By
> seamless I mean implement it without updating any consumers of a person?
>  For example, if I changed the age property to be  the result of a function,
> I could either replace the value of age with a function that calculates age
> or write a function(person)->age.
>
> Both of those are disruptive to the consumers of person.
>
> I understand that clojure is about explicitly distinguishing between state
> and functions, but I see this as a high price to pay.  Have I missed
> something?  The OO in me is saying "well, never introspect a map directly,
> rather provide get-X(person) functions" but that is very very noisy.
>
> That's enough for now - this is, I expect, the first of many cries for help
> :)
>
> Thanks in advance to all who reply!

-- 
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 about data structures and encapsulation

2011-06-16 Thread Laurent PETIT
2011/6/16 Mikkel :
> This could be one way to solve the problem in the example and keep a
> uniform API:
> (def joe {:age ((fn [] (- 2011 1979)))})
> (:age joe)
> #> 32
>
> Any comments on that?

You're applying the function immediately. It's not different than doing
(let [age ((fn [] (- 2011 1979)))]
  {:age age})

-- 
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: using regex reader macro with generated code

2011-06-16 Thread Daniel Werner
On Jun 16, 4:47 am, Alex Baranosky 
wrote:
> IS it possible to use the regex reader macro #"" with generated code?  What
> I mean is do something like:
>
> #"${(join "|" (range 1 1))}"
>
> I'm using ${...} to mean string interpolation, though I know Clojure doesn't
> have that syntax.  Is there a way to get this effect or must I use
> (re-pattern (join "|" (range 1 1)))

In your specific example, as all the components used to build your
regex are static, you could use re-pattern as a macro:

(defmacro re-ra­nge []
  (re-p­attern (cloj­ure.string­/join "|" (rang­e 1 1000)­)

However, as soon as you want to parameterise the regex, things get
hairy. You *could* have your macro take arguments like this:

; bad idea
(defmacro re-ra­nge [start end]
  (re-p­attern (cloj­ure.string­/join "|" (rang­e start end­)

This would work as long as the macro is passed static values, like 1
and 1000. This, however, *won't* work:

(let [x 1000]
  (re-range 1 x)

In this case #'re-range macro would receive the symbol 'x as its end
argument, because macros are executed at compile time (or macro
expansion time, to be more precise) and take code as their data.

Hope that helps,
--
Daniel

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


Aw: Re: Question about data structures and encapsulation

2011-06-16 Thread Meikel Brandmeyer
Hi,

one could use lazymap: https://bitbucket.org/kotarak/lazymap. Unfortunately, 
it is broken at the moment. Have to bring up-to-date with 1.2 and later.

(defn person
  [name year-of-birth]
  (lazy-hash-map :name name :age (- 2011 year-of-birth)))

The actual difference would only be calculated when the :age key is 
accessed. The result would then be cached. (It uses delays under the hood).

Sincerely
Meikel

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

Functions destructuring maps in the arglist

2011-06-16 Thread Tassilo Horn
Hi all,

I have some functions that use destructuring on a map parameter, and it
seems I have a false assumption on the workings.  Take for example this
one:

(defn foo
  [{:keys [a b]
:or {a 1 b 2}
:as all}]
  [(hash-map :a a :b b) all])

I expected it to always return a vector of two equal maps.  However,
that's not true.  all is in fact the map I gave at the call, not the map
with the default values declared in the :or applied.

Why is that? So that you can distinguish given actual args that happen
to match default values from real, non-given defaults?

That somehow makes sense, but is there some way to get the complete map
with defaults applied, too?

In my application, I don't care about if some value is an implicit or
explicit default, but I have some functions with many keys that are
split in two subfunctions.  One public frontend functions with :or in
order to let callers see the defaults, and one private function that
does the actual work, assumes correct args and is called by the public
one:

  (defn- foo-1 [{:keys [a b c]}] ...)

  (def foo [{:keys [a b c]
 :or {a 1 b 2 c 3}
 :as all}]
;; do some stuff
;; (foo-1 all) ;; That won't work, instead I have to do the lengthy...
(foo-1 (hash-map :a a :b b :c c))
;; do more stuff
)

Any recourse?

Bye,
Tassilo

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


Modelling complex data structures (graphs and trees for example)

2011-06-16 Thread Colin Yates
(newbie warning)

Our current solution is an OO implementation in Groovy and Java.  We
have a (mutable) Project which has a DAG (directed acyclic graph).
This is stored as a set of nodes and edges.  There are multiple
implementations of nodes (which may themselves be Projects).  There
are also multiple implementations of edges.

My question isn't how to do this in a functional paradigm, my first
question is *how do I learn* to do this in a functional paradigm.  I
want to be able to get the answer myself ;).  To that end, are there
any "domain driven design with functional programming" type resources?

A more specific question is how do I model a graph?  These graphs can
be quite extensive, with mutations on the individual nodes as well as
the structure (i.e. adding or removing branches).  Does this mean that
every every node would be a ref?  I think the general answer is that
the aggregate roots are refs, meaning they are an atomic block, but is
there any more guidance?

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


2011 State of Clojure survey

2011-06-16 Thread Chas Emerick
Last year's State of Clojure survey[1] was such a success and yielded such 
valuable data about the Clojure community that I had no choice but to do it all 
again this year!

The 2011 State of Clojure survey opened yesterday, and will remain open until 
Monday, June 20th:

http://cemerick.com/2011/06/15/the-2011-state-of-clojure-survey-is-open/

If you haven't yet participated, please do so!  "Taking the pulse" of the 
community in this way can help library developers and clojure/core prioritize 
their efforts, and may help provide ammunition for those working to gain 
acceptance of Clojure in their workplaces, universities, and elsewhere.

And, if you know of someone who's using Clojure, but who might not have 
participated in the survey (not everyone is as tuned into twitter and the 
mailing list here as others, of course), do feel free to pass along the link 
above.

Cheers,

- Chas

[1] 
http://cemerick.com/2010/06/07/results-from-the-state-of-clojure-summer-2010-survey/

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


Screencast: Clojure + Emacs + slime + swank + cake + Overtone

2011-06-16 Thread Sam Aaron
Hi there,

I just finished making a screencast primarily for new Overtone users on how to 
get set up with Emacs as a primary editor:

http://vimeo.com/25190186

It turns out that this should be pretty useful for Clojure hackers in general 
as it's really a screencast on how to set up a Clojure environment using Emacs 
slime, swank and cake. Just s/Overtone/your-project/

Of course, it's also great if you're interested in making music with 
programming languages :-)

Sam

---
http://sam.aaron.name

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


List comprehension not running

2011-06-16 Thread Thomas
Hi All,

I have a ref with a watcher on it, and I call another function from
the
watch function. I can see that call happens, but the for construct
doesn't
seem to run. Any idea why this is? Am I doing something wrong?

Here is a simplified version of the code:


(def numbers (ref #{1 2 3 4 5 6 7 8 9}))

(defn more-actions
[col]
(println "this prints" )
(for [x (range 10)] (println "this doesn't print" col x)))

(defn watcher
[akey aref old-val new-val]
(println "new value:" new-val)
(more-actions new-val)
)

(add-watch numbers "foo" watcher)

(dosync (alter numbers disj 1))


Thanks in advance,
Thomas

ps. I am running 1.2.1

-- 
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-csv Column or field extraction

2011-06-16 Thread David Santiago
Change the first line to something like (def csv (parse-csv (slurp
"path/to/my/file.csv"))).

  -  David

On Thu, Jun 16, 2011 at 8:20 AM, octopusgrabbus
 wrote:
> I would like to modify the examples given
>
> user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
> #'user/csv
> user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
> "6"
> user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
> "6"
> user=> (defn get-column [parsed-csv col] (map #(nth % col)
> parsed-csv)) ;; Function to return a given column.
> #'user/get-column
> user=> (get-column csv 1) ;; Get second column as a sequence.
> ("2" "5" "8")
>
> to read in a .csv file, and then perform the functions on the parsed
> csv file, but I am getting clojure.lang.LazySeq cannot be cast to
> clojure.lang.IFn.
>
> How do I do this properly?
> Thanks.
>
> On Jun 16, 12:20 am, David Santiago  wrote:
>> Here's a repl session that will hopefully demonstrate how to do a few
>> things, including pull out an entire column. Just remember the library
>> turns CSVs into regular clojure data structures, so getting the data
>> you want out of the return value of the parse is just about indexing
>> into vectors.
>>
>> user=> (use 'clojure-csv.core)
>> nil
>> user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
>> #'user/csv
>> user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
>> "6"
>> user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
>> "6"
>> user=> (defn get-column [parsed-csv col] (map #(nth % col)
>> parsed-csv)) ;; Function to return a given column.
>> #'user/get-column
>> user=> (get-column csv 1) ;; Get second column as a sequence.
>> ("2" "5" "8")
>>
>>   - David
>>
>> On Wed, Jun 15, 2011 at 9:58 PM, octopusgrabbus
>>
>>
>>
>>
>>
>>
>>
>>  wrote:
>> > I've got to go back and look at your documentation. I'm not sure how
>> > to pull the columns out of each row.
>>
>> > On Jun 15, 5:04 pm, David Santiago  wrote:
>> >> I'm afraid I don't understand the question. What do you mean
>> >> "positionally?" When it parses the CSV file, it gives you back a
>> >> stream of rows, each row being a vector of the contents of each cell
>> >> of the CSV. If you are interested in cells at a given row/column, you
>> >> should be able to count into those vectors fairly naturally...
>>
>> >>    - David
>>
>> >> On Wed, Jun 15, 2011 at 2:08 PM, octopusgrabbus 
>> >> wrote:
>> >> > Is it possible to use clojure-csv to extract data positionally in
>> >> > a .csv file, or should I use BufferedReader to read each line lazily
>> >> > and apply splitting the line up into fields by delimiter?
>>
>> >> > Thanks.
>> >> > cmn
>>
>> >> > --
>> >> > 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

-- 
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: List comprehension not running

2011-06-16 Thread Baishampayan Ghose
'for' is not recommended for causing side-effects. Since you are not using
the return value of the for comprehension, the lazy sequence is not getting
realised. You can either use 'doall' around it or better still, use 'doseq'.


Hope that helps.

Regards,
BG

---
Sent from phone. Please excuse brevity.
On Jun 16, 2011 9:41 PM, "Thomas"  wrote:
> Hi All,
>
> I have a ref with a watcher on it, and I call another function from
> the
> watch function. I can see that call happens, but the for construct
> doesn't
> seem to run. Any idea why this is? Am I doing something wrong?
>
> Here is a simplified version of the code:
>
>
> (def numbers (ref #{1 2 3 4 5 6 7 8 9}))
>
> (defn more-actions
> [col]
> (println "this prints" )
> (for [x (range 10)] (println "this doesn't print" col x)))
>
> (defn watcher
> [akey aref old-val new-val]
> (println "new value:" new-val)
> (more-actions new-val)
> )
>
> (add-watch numbers "foo" watcher)
>
> (dosync (alter numbers disj 1))
>
>
> Thanks in advance,
> Thomas
>
> ps. I am running 1.2.1
>
> --
> 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

TriClojure would love to hear you speak

2011-06-16 Thread Chris Redinger
Hey all!

Do you have a topic you'd like to talk to somebody about? Why not head on
over to Durham and speak at our monthly
TriClojuremeeting?! We're open to
hearing about all sorts of topics.

Speaking at user groups is a fantastic way to improve your speaking ability,
and with the Clojure Conj , among other
conferences, approaching now would be a great time to start brushing up
those skills.

It's also a great way to get word out about what you are working on. If
you've got a product you're pimping, this is known as marketing. If you've
got an open source project, this is a method of recruiting users and
volunteers.

Plus, you never know which member of Clojure/core will show up at one of our
meetings. And you could use this time to buy them a drink and get your
favorite feature prioritized.

So, if you are interested, let me know what you'd like to talk about and
when, and I'll get you on the schedule.

Thanks!

-- 
Christopher Redinger
Clojure/core
http://clojure.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

Re: List comprehension not running

2011-06-16 Thread Steve Miner
(dotimes [x 10] ...)  should do the trick if you're just interested in side 
effects.

On Jun 16, 2011, at 12:24 PM, Baishampayan Ghose wrote:
> 'for' is not recommended for causing side-effects. Since you are not using 
> the return value of the for comprehension, the lazy sequence is not getting 
> realised. You can either use 'doall' around it or better still, use 'doseq'.
> 

-- 
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-csv Column or field extraction

2011-06-16 Thread octopusgrabbus
Many thanks.

On Jun 16, 12:18 pm, David Santiago  wrote:
> Change the first line to something like (def csv (parse-csv (slurp
> "path/to/my/file.csv"))).
>
>   -  David
>
> On Thu, Jun 16, 2011 at 8:20 AM, octopusgrabbus
>
>
>
>
>
>
>
>  wrote:
> > I would like to modify the examples given
>
> > user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
> > #'user/csv
> > user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
> > "6"
> > user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
> > "6"
> > user=> (defn get-column [parsed-csv col] (map #(nth % col)
> > parsed-csv)) ;; Function to return a given column.
> > #'user/get-column
> > user=> (get-column csv 1) ;; Get second column as a sequence.
> > ("2" "5" "8")
>
> > to read in a .csv file, and then perform the functions on the parsed
> > csv file, but I am getting clojure.lang.LazySeq cannot be cast to
> > clojure.lang.IFn.
>
> > How do I do this properly?
> > Thanks.
>
> > On Jun 16, 12:20 am, David Santiago  wrote:
> >> Here's a repl session that will hopefully demonstrate how to do a few
> >> things, including pull out an entire column. Just remember the library
> >> turns CSVs into regular clojure data structures, so getting the data
> >> you want out of the return value of the parse is just about indexing
> >> into vectors.
>
> >> user=> (use 'clojure-csv.core)
> >> nil
> >> user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9"))
> >> #'user/csv
> >> user=> (nth (nth csv 1) 2)  ;; Get 2nd row, last column.
> >> "6"
> >> user=> (-> csv (nth 1) (nth 2))  ;; Another way to do it.
> >> "6"
> >> user=> (defn get-column [parsed-csv col] (map #(nth % col)
> >> parsed-csv)) ;; Function to return a given column.
> >> #'user/get-column
> >> user=> (get-column csv 1) ;; Get second column as a sequence.
> >> ("2" "5" "8")
>
> >>   - David
>
> >> On Wed, Jun 15, 2011 at 9:58 PM, octopusgrabbus
>
> >>  wrote:
> >> > I've got to go back and look at your documentation. I'm not sure how
> >> > to pull the columns out of each row.
>
> >> > On Jun 15, 5:04 pm, David Santiago  wrote:
> >> >> I'm afraid I don't understand the question. What do you mean
> >> >> "positionally?" When it parses the CSV file, it gives you back a
> >> >> stream of rows, each row being a vector of the contents of each cell
> >> >> of the CSV. If you are interested in cells at a given row/column, you
> >> >> should be able to count into those vectors fairly naturally...
>
> >> >>    - David
>
> >> >> On Wed, Jun 15, 2011 at 2:08 PM, 
> >> >> octopusgrabbus wrote:
> >> >> > Is it possible to use clojure-csv to extract data positionally in
> >> >> > a .csv file, or should I use BufferedReader to read each line lazily
> >> >> > and apply splitting the line up into fields by delimiter?
>
> >> >> > Thanks.
> >> >> > cmn
>
> >> >> > --
> >> >> > 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

-- 
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: Modelling complex data structures (graphs and trees for example)

2011-06-16 Thread Raoul Duke
On Thu, Jun 16, 2011 at 7:08 AM, Colin Yates  wrote:
> (newbie warning)
> any "domain driven design with functional programming" type resources?

have you googled at all? seriously, graphs & fp are standard fare in
the fp world! i'd expect there to be a zillion docs about doing it in
other fp languages; haskell, lisp, scheme, ocaml, scala...

-- 
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: Modelling complex data structures (graphs and trees for example)

2011-06-16 Thread Andreas Liljeqvist
I would make the graph immutable.
If performance is a objective it might not work though.
My tip for learning it:
Sit down and think about the problem. Consider your Clojure structures.


2011/6/16 Colin Yates 

> (newbie warning)
>
> Our current solution is an OO implementation in Groovy and Java.  We
> have a (mutable) Project which has a DAG (directed acyclic graph).
> This is stored as a set of nodes and edges.  There are multiple
> implementations of nodes (which may themselves be Projects).  There
> are also multiple implementations of edges.
>
> My question isn't how to do this in a functional paradigm, my first
> question is *how do I learn* to do this in a functional paradigm.  I
> want to be able to get the answer myself ;).  To that end, are there
> any "domain driven design with functional programming" type resources?
>
> A more specific question is how do I model a graph?  These graphs can
> be quite extensive, with mutations on the individual nodes as well as
> the structure (i.e. adding or removing branches).  Does this mean that
> every every node would be a ref?  I think the general answer is that
> the aggregate roots are refs, meaning they are an atomic block, but is
> there any more guidance?
>
> --
> 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 about data structures and encapsulation

2011-06-16 Thread Caleb
Colin,
I just read this definition from SICP, which made me think about your
question again:

"In general, the underlying idea of data abstraction is to identify
for each type of data object a basic set of operations in terms of
which all manipulations of data objects of that type will be
expressed, and then to use only those operations in manipulating the
data."

So that seems pretty compatible with your definition, except that as
you said, in OO your operations typically have shared state in
addition to shared data types.

But I am not sure that I agree that having functions that operate on
the data, rather than sharing state are more noisy.  For example,
these seem fairly equivalent to me:

p/age(caleb)
p/favorite-color(caleb)

or

caleb.getAge()
caleb.getFavoriteColor()

This assumes that you have defined 'age' and 'favorite-color' in a
namespace that you have aliased as 'p' in the current context. That's
an important point to me, because In addition to providing operations
on shared state, objects and classes are also used to create
namespaces for operations.  In Clojure you can get namespaces a la
carte (without having to use classes).  I am fairly beginnerish at
Clojure myself, but I have found its namespaces to provide some of the
important conceptual glue that I relied on classes for in other
languages.  Otherwise you would have a lot of noise.

SICP reference: 
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.2


On Jun 15, 1:41 pm, Colin Yates  wrote:
> Newbie so go gentle please :).  
>
> I am an experienced OO Java developer (decade +) considering jumping fence
> to a functional language, and clojure is pretty high up on the list for a
> number of reasons.
>
> I am so used to defining everything as objects which are sealed units of
> state and behaviour that I am struggling to see how to solve the same
> problem with clojure.  I desperately wish somebody would write a "domain
> driven design with clojure" :).
>
> In brief, in OO state is exposed via a well defined API.  That state may be
> simple properties (values) or it may be calculations (functions).  And
> critically, the decision as to whether it is a value or a function is an
> implementation concern.  The Java Bean spec defines accessors for properties
> of a class, behind which lies the logic of how to retrieve that state.  So,
> the very common Person class will expose get/setName(), get/setAge() etc.
> and as a consumer I have no idea how the results are calcualted.
>
> In Clojure, if I understand correctly, the preferred way would be to use a
> map (or defstruct) with keys such as :name and :age.  These are then
> retrieved as (person :name) and (person: age) etc.  
>
> My question is if I suddenly decided that one of those values is best
> implemented as a calculation, how can I seamlessly implement that.  By
> seamless I mean implement it without updating any consumers of a person?
>  For example, if I changed the age property to be  the result of a function,
> I could either replace the value of age with a function that calculates age
> or write a function(person)->age.
>
> Both of those are disruptive to the consumers of person.
>
> I understand that clojure is about explicitly distinguishing between state
> and functions, but I see this as a high price to pay.  Have I missed
> something?  The OO in me is saying "well, never introspect a map directly,
> rather provide get-X(person) functions" but that is very very noisy.
>
> That's enough for now - this is, I expect, the first of many cries for help
> :)
>
> Thanks in advance to all who reply!

-- 
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: Modelling complex data structures (graphs and trees for example)

2011-06-16 Thread lambdatronic
My 2c:

Regarding learning how to model a complex data structure in a
functional paradigm:

  I can think of few resources which sum up the proper mindset you
need to get into
  better than the canonical Clojure essay on state and identity, found
here:

http://clojure.org/state

Regarding how to model a graph in Clojure:

  I would suggest that you avoid thinking about refs unless you are
likely to need to
  perform some kind of concurrent updates to your graph.  A nested
associative data
  structure should do the trick just fine.


(defrecord Node [foo bar baz])

(defn node [foo bar baz] (Node. foo bar baz))

(def the-graph {})

(defn add-node [g n]
  (if (g n)
g
(assoc g n {:next #{} :prev #{}})))

(defn add-edge [g n1 n2]
  (-> g
  (add-node n1)
  (add-node n2)
  (update-in [n1 :next] conj n2)
  (update-in [n2 :prev] conj n1)))

(defn remove-edge [g n1 n2]
  (-> g
  (add-node n1)
  (add-node n2)
  (update-in [n1 :next] disj n2)
  (update-in [n2 :prev] disj n1)))

(defn remove-node [g n]
  (if-let [{:keys [next prev]} (g n)]
((comp
  #(dissoc % n)
  #(reduce (fn [g* n*] (remove-edge g* n* n)) % prev)
  #(reduce (fn [g* n*] (remove-edge g* n n*)) % next))
 g)
g))

(defn contains-node? [g n]
  (g n))

(defn contains-edge? [g n1 n2]
  (get-in g [n1 :next n2]))

(defn next-nodes [g n]
  (get-in g [n :next]))

;; Assumes DAG
(defn depth-first-search [g root-node goal?]
  (loop [open-list (list root-node)]
(when-first [n open-list]
  (if (goal? n)
n
(recur (concat (next-nodes g n) (rest open-list)))


And there you go.  A fast, functional DAG implementation that doesn't
use any mutable state.

  Happy hacking,
~Gary


On Jun 16, 10:08 am, Colin Yates  wrote:
> (newbie warning)
>
> Our current solution is an OO implementation in Groovy and Java.  We
> have a (mutable) Project which has a DAG (directed acyclic graph).
> This is stored as a set of nodes and edges.  There are multiple
> implementations of nodes (which may themselves be Projects).  There
> are also multiple implementations of edges.
>
> My question isn't how to do this in a functional paradigm, my first
> question is *how do I learn* to do this in a functional paradigm.  I
> want to be able to get the answer myself ;).  To that end, are there
> any "domain driven design with functional programming" type resources?
>
> A more specific question is how do I model a graph?  These graphs can
> be quite extensive, with mutations on the individual nodes as well as
> the structure (i.e. adding or removing branches).  Does this mean that
> every every node would be a ref?  I think the general answer is that
> the aggregate roots are refs, meaning they are an atomic block, but is
> there any more guidance?

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


Properly including clojure-contrib

2011-06-16 Thread octopusgrabbus
What is the proper way to :use clojure contrib so split resolves as a
symbol?

ns test-csv
  (:gen-class)
  (:import (java.io BufferedReader FileReader StringReader))
  (:use clojure-csv.core)
  (:use [clojure.contrib.def]))

(defn process-file [file-name]
(with-open [br (BufferedReader. (FileReader. file-name))]
(println (split "," (line-seq br)

(defn -main [& args]
  (process-file "resultset.csv"))

Thanks.
cmn

-- 
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: 2011 State of Clojure survey

2011-06-16 Thread octopusgrabbus
Thanks for posting last year's survey as well as notifying us about
this year's.

On Jun 16, 10:26 am, Chas Emerick  wrote:
> Last year's State of Clojure survey[1] was such a success and yielded such 
> valuable data about the Clojure community that I had no choice but to do it 
> all again this year!
>
> The 2011 State of Clojure survey opened yesterday, and will remain open until 
> Monday, June 20th:
>
> http://cemerick.com/2011/06/15/the-2011-state-of-clojure-survey-is-open/
>
> If you haven't yet participated, please do so!  "Taking the pulse" of the 
> community in this way can help library developers and clojure/core prioritize 
> their efforts, and may help provide ammunition for those working to gain 
> acceptance of Clojure in their workplaces, universities, and elsewhere.
>
> And, if you know of someone who's using Clojure, but who might not have 
> participated in the survey (not everyone is as tuned into twitter and the 
> mailing list here as others, of course), do feel free to pass along the link 
> above.
>
> Cheers,
>
> - Chas
>
> [1]http://cemerick.com/2010/06/07/results-from-the-state-of-clojure-summ...

-- 
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: Swank-Inject Issue

2011-06-16 Thread Johan Wirde
Hi!

I have only built on OSX so far which is why I haven't noticed this
problem. Apparently the com.sun.jdi classes are packaged differently than on
other platforms (there is no tools.jar on OSX).

The best solution I could come up with involved using a new feature from
lein 1.6.0-SNAPSHOT (:extra-classpath-dirs).

I would be very interested in other options for declaring a dependency on
tools.jar in a leiningen project!

Regards,
Johan

On Wed, Jun 15, 2011 at 7:55 PM, Asim Jalis  wrote:

> Hi,
>
> I am trying to get swank-inject to work on Ubuntu Linux and I am
> getting a failure related to tools.jar (ClassNotFoundException:
> com.sun.jdi.Bootstrap jdi.clj: 1). This error does not go away even if
> I add tools.jar directly to CLASSPATH.
>
> Has anyone seen this error before? Any ideas on how to solve this
> would be great.
>
> Thanks!
>
> Asim
>
> --
> Here are the commands I am executing:
>
> export JAVA_HOME=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64
> export JDK_HOME=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64
> export
> CLASSPATH=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64/lib/tools.jar
> which java
> rm -rf   $HOME/tmp/swank-fun
> mkdir -p $HOME/tmp/swank-fun
> cd   $HOME/tmp/swank-fun
> git clone https://github.com/wirde/swank-inject.git
> cd swank-inject
> lein uberjar
> ajalis-wsl:/home/ajalis> m swank/install-v4
> export JAVA_HOME=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64
> export JDK_HOME=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64
> export
> CLASSPATH=/home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64/lib/tools.jar
> which java
> rm -rf   $HOME/tmp/swank-fun
> mkdir -p $HOME/tmp/swank-fun
> cd   $HOME/tmp/swank-fun
> git clone https://github.com/wirde/swank-inject.git
> cd swank-inject
> lein uberjar
>
> --
> Here is the output I get:
>
> /home/ajalis/dev/tools/Linux/jdk/jdk1.6.0_16_x64/bin/java
> Initialized empty Git repository in
> /home/ajalis/tmp/swank-fun/swank-inject/.git/
> remote: Counting objects: 225, done.
> remote: Compressing objects: 100% (199/199), done.
> remote: Total 225 (delta 110), reused 0 (delta 0)
> Receiving objects: 100% (225/225), 30.22 KiB, done.
> Resolving deltas: 100% (110/110), done.
> Cleaning up.
> Copying 5 files to /home/ajalis/tmp/swank-fun/swank-inject/lib
> Exception in thread "main" java.lang.ClassNotFoundException:
> com.sun.jdi.Bootstrap (jdi.clj:1)
>at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2911)
>at clojure.lang.Compiler.compile1(Compiler.java:5933)
>at clojure.lang.Compiler.compile1(Compiler.java:5923)
>at clojure.lang.Compiler.compile(Compiler.java:5992)
>at clojure.lang.RT.compile(RT.java:368)
>at clojure.lang.RT.load(RT.java:407)
>at clojure.lang.RT.load(RT.java:381)
>at clojure.core$load$fn__4511.invoke(core.clj:4905)
>at clojure.core$load.doInvoke(core.clj:4904)
>at clojure.lang.RestFn.invoke(RestFn.java:409)
>at clojure.core$load_one.invoke(core.clj:4729)
>at clojure.core$load_lib.doInvoke(core.clj:4766)
>at clojure.lang.RestFn.applyTo(RestFn.java:143)
>at clojure.core$apply.invoke(core.clj:542)
>at clojure.core$load_libs.doInvoke(core.clj:4800)
>at clojure.lang.RestFn.applyTo(RestFn.java:138)
>at clojure.core$apply.invoke(core.clj:544)
>at clojure.core$use.doInvoke(core.clj:4880)
>at clojure.lang.RestFn.invoke(RestFn.java:409)
>at swank_inject.aot$loading__4410__auto__.invoke(aot.clj:2)
>at clojure.lang.AFn.applyToHelper(AFn.java:159)
>at clojure.lang.AFn.applyTo(AFn.java:151)
>at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2906)
>at clojure.lang.Compiler.compile1(Compiler.java:5933)
>at clojure.lang.Compiler.compile1(Compiler.java:5923)
>at clojure.lang.Compiler.compile(Compiler.java:5992)
>at clojure.lang.RT.compile(RT.java:368)
>at clojure.lang.RT.load(RT.java:407)
>at clojure.lang.RT.load(RT.java:381)
>at clojure.core$load$fn__4511.invoke(core.clj:4905)
>at clojure.core$load.doInvoke(core.clj:4904)
>at clojure.lang.RestFn.invoke(RestFn.java:409)
>at clojure.core$load_one.invoke(core.clj:4729)
>at clojure.core$compile$fn__4516.invoke(core.clj:4916)
>at clojure.core$compile.invoke(core.clj:4915)
>at user$eval7.invoke(NO_SOURCE_FILE:1)
>at clojure.lang.Compiler.eval(Compiler.java:5424)
>at clojure.lang.Compiler.eval(Compiler.java:5415)
>at clojure.lang.Compiler.eval(Compiler.java:5391)
>at clojure.core$eval.invoke(core.clj:2382)
>at clojure.main$eval_opt.invoke(main.clj:235)
>at clojure.main$initialize.invoke(main.clj:254)
>at clojure.main$null_opt.invoke(main.clj:279)
>at clojure.main$main.doInvoke(main.clj:354)
>at clojure.lang.RestFn.invoke(RestFn.java:422)
>at clojure.lang.Var.invoke(Var.java:369)
>at clojure.lan

Java interop: casting

2011-06-16 Thread Gregg Reynolds
Hi,

I'm trying to make the GAE local testing stuff (http://code.google.com/
appengine/docs/java/tools/localunittesting.html)  work with Clojure
and running into a cast problem.  Specifically, the example shows

 private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new
LocalDatastoreServiceTestConfig());

where the LocalServiceTestHelper ctor takes one arg of type
LocalServiceTestConfig (which is an interface).
LocalDatastoreServiceTestConfig implements LocalServiceTestConfig.

which I try to do in clojure like this:

(def foo (new LocalDatastoreServiceTestConfig))
(def bar (LocalServiceTestHelper. foo))

which yields a java.lang.ClassCastException.  Messing around with
class, .getName, cast, etc. I end up with:

com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
cannot be cast to java.lang.Class

It seems that clojure won't treat LocalDatastoreServiceTestConfig as a
LocalServiceTestConfig.  Am I interpreting all this correctly?  I'm
relatively new to clojure and my java is a little rusty, but I've
banged my head on this all afternoon and I'm out of ideas.

Thanks,

Gregg

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


Best practice for distributing a standalone clojure command line utility

2011-06-16 Thread Damon Snyder
Hi Everyone,
I'm have a side project that I'm working on that I want to distribute
as a standalone script. This is probably best illustrated as an
example. What I would like to be able to do is give users a script, so
they can do:

   gantry -H example.host.com -f examples/tasks.clj uptime

Instead of

   java -jar gantry-0.0.1-SNAPSHOT-standalone.jar -H example.host.com -
f examples/tasks.clj uptime

What I'm curious about is what is the best practice within the
community for doing this? Backing up for a minute, to me, the first
invokation would be the preferred in my mind. Perhaps the second isn't
so bad if you are used to interacting with jar files in this way. I
think I would prefer that the details of running java be abstracted
away from the command line user's experience.

A few approaches I have thought about: 1) Upload the stand alone jar
to github and have the "gantry" script pull down the standalone into
~/.gantry and construct the command line. 2) Create a cake wrapper
(not preferred because it introduces a dependency). 3) Forget the
wrapper and just distribute the jar.

The project I am talking about is here: https://github.com/drsnyder/gantry.
Thanks,
Damon

-- 
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: Properly including clojure-contrib

2011-06-16 Thread Damon Snyder
Hi cmn,
I think if you add clojure.contrib.string to your use or simply add
(:use clojure.contrib.string). I think that should fix it.

Damon

On Jun 16, 12:16 pm, octopusgrabbus  wrote:
> What is the proper way to :use clojure contrib so split resolves as a
> symbol?
>
> ns test-csv
>   (:gen-class)
>   (:import (java.io BufferedReader FileReader StringReader))
>   (:use clojure-csv.core)
>   (:use [clojure.contrib.def]))
>
> (defn process-file [file-name]
>     (with-open [br (BufferedReader. (FileReader. file-name))]
>                             (println (split "," (line-seq br)
>
> (defn -main [& args]
>   (process-file "resultset.csv"))
>
> Thanks.
> cmn

-- 
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: Properly including clojure-contrib

2011-06-16 Thread octopusgrabbus
I don't know what I'm doing wrong. After adding (:use
clojure.contrib.string) to

(ns test-csv
  (:gen-class)
  (:import (java.io BufferedReader FileReader StringReader))
  (:use clojure-csv.core)
  (:use clojure.contrib.string))


(defn process-file [file-name]
(with-open [br (BufferedReader. (FileReader. file-name))]
(println (split (line-seq br)",")))

(defn -main [& args]
  (process-file "resultset.csv"))

I'm getting these errors on compile:

  [compile] Compiling namespace test-csv
WARNING: repeat already refers to: #'clojure.core/repeat in namespace:
test-csv, being replaced by: #'clojure.contrib.string/repeat
WARNING: butlast already refers to: #'clojure.core/butlast in
namespace: test-csv, being replaced by: #'clojure.contrib.string/
butlast
WARNING: reverse already refers to: #'clojure.core/reverse in
namespace: test-csv, being replaced by: #'clojure.contrib.string/
reverse
WARNING: get already refers to: #'clojure.core/get in namespace: test-
csv, being replaced by: #'clojure.contrib.string/get
WARNING: partition already refers to: #'clojure.core/partition in
namespace: test-csv, being replaced by: #'clojure.contrib.string/
partition
WARNING: drop already refers to: #'clojure.core/drop in namespace:
test-csv, being replaced by: #'clojure.contrib.string/drop
WARNING: take already refers to: #'clojure.core/take in namespace:
test-csv, being replaced by: #'clojure.contrib.string/take
error evaluating:
((compile-stale source-path compile-path))
java.lang.RuntimeException: java.lang.Exception: EOF while reading
(test_csv.clj:15)
.
.
.

What am I doing wrong?
tnx
cmn
On Jun 16, 5:16 pm, Damon Snyder  wrote:
> Hi cmn,
> I think if you add clojure.contrib.string to your use or simply add
> (:use clojure.contrib.string). I think that should fix it.
>
> Damon
>
> On Jun 16, 12:16 pm, octopusgrabbus  wrote:
>
>
>
>
>
>
>
> > What is the proper way to :use clojure contrib so split resolves as a
> > symbol?
>
> > ns test-csv
> >   (:gen-class)
> >   (:import (java.io BufferedReader FileReader StringReader))
> >   (:use clojure-csv.core)
> >   (:use [clojure.contrib.def]))
>
> > (defn process-file [file-name]
> >     (with-open [br (BufferedReader. (FileReader. file-name))]
> >                             (println (split "," (line-seq br)
>
> > (defn -main [& args]
> >   (process-file "resultset.csv"))
>
> > Thanks.
> > cmn

-- 
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: Properly including clojure-contrib

2011-06-16 Thread Benny Tsai
Hi cmn,

A few things:

1. The warnings you see are because the clojure.contrib.string namespace 
defines several functions that have the same name as core functions (repeat, 
reverse, etc.).  The recommended way to pull in namespaces like that is to 
do (:require [clojure.contrib.string :as str]), and then the functions can 
be used via (str/repeat ...), (str/reverse ...), etc.
2. As of 1.2, "split" is incorporated into clojure.string, so no need to 
grab clojure.contrib.string just for that function.  clojure.string also 
defines functions with the same name as core functions, so it should be 
pulled in via (:require [clojure.string :as str]), and split can then be 
used via (str/split ...).
3. That EOF error is because process-file needs one more closing paren.

-- 
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: Properly including clojure-contrib

2011-06-16 Thread Mark Rathwell
The clojure.contrib.string namespace contains many function names which are
already defined clojure.core.  So, by :use-ing clojure.contrib.string, you
will be replacing the core functions with the string functions.  Rarely do
you really want to do this.  It is generally best to :require instead of
:use.

so something like:

(ns test-csv
 (:gen-class)
 (:import (java.io BufferedReader FileReader StringReader))
 (:use clojure-csv.core)
 (:require [clojure.contrib.string :as string]))

(defn process-file [file-name]
   (with-open [br (BufferedReader. (FileReader. file-name))]
   (println (string/split (line-seq br)",")))

(defn -main [& args]
 (process-file "resultset.csv"))



On Thu, Jun 16, 2011 at 5:37 PM, octopusgrabbus wrote:

> I don't know what I'm doing wrong. After adding (:use
> clojure.contrib.string) to
>
> (ns test-csv
>   (:gen-class)
>  (:import (java.io BufferedReader FileReader StringReader))
>  (:use clojure-csv.core)
>   (:use clojure.contrib.string))
>
>
> (defn process-file [file-name]
>(with-open [br (BufferedReader. (FileReader. file-name))]
>(println (split (line-seq br)",")))
>
> (defn -main [& args]
>  (process-file "resultset.csv"))
>
> I'm getting these errors on compile:
>
>  [compile] Compiling namespace test-csv
> WARNING: repeat already refers to: #'clojure.core/repeat in namespace:
> test-csv, being replaced by: #'clojure.contrib.string/repeat
> WARNING: butlast already refers to: #'clojure.core/butlast in
> namespace: test-csv, being replaced by: #'clojure.contrib.string/
> butlast
> WARNING: reverse already refers to: #'clojure.core/reverse in
> namespace: test-csv, being replaced by: #'clojure.contrib.string/
> reverse
> WARNING: get already refers to: #'clojure.core/get in namespace: test-
> csv, being replaced by: #'clojure.contrib.string/get
> WARNING: partition already refers to: #'clojure.core/partition in
> namespace: test-csv, being replaced by: #'clojure.contrib.string/
> partition
> WARNING: drop already refers to: #'clojure.core/drop in namespace:
> test-csv, being replaced by: #'clojure.contrib.string/drop
> WARNING: take already refers to: #'clojure.core/take in namespace:
> test-csv, being replaced by: #'clojure.contrib.string/take
> error evaluating:
> ((compile-stale source-path compile-path))
> java.lang.RuntimeException: java.lang.Exception: EOF while reading
> (test_csv.clj:15)
> .
> .
> .
>
> What am I doing wrong?
> tnx
> cmn
> On Jun 16, 5:16 pm, Damon Snyder  wrote:
> > Hi cmn,
> > I think if you add clojure.contrib.string to your use or simply add
> > (:use clojure.contrib.string). I think that should fix it.
> >
> > Damon
> >
> > On Jun 16, 12:16 pm, octopusgrabbus  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > What is the proper way to :use clojure contrib so split resolves as a
> > > symbol?
> >
> > > ns test-csv
> > >   (:gen-class)
> > >   (:import (java.io BufferedReader FileReader StringReader))
> > >   (:use clojure-csv.core)
> > >   (:use [clojure.contrib.def]))
> >
> > > (defn process-file [file-name]
> > > (with-open [br (BufferedReader. (FileReader. file-name))]
> > > (println (split "," (line-seq br)
> >
> > > (defn -main [& args]
> > >   (process-file "resultset.csv"))
> >
> > > Thanks.
> > > cmn
>
> --
> 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: Properly including clojure-contrib

2011-06-16 Thread octopusgrabbus
Thanks.
That did it.

On Jun 16, 5:46 pm, Benny Tsai  wrote:
> Hi cmn,
>
> A few things:
>
> 1. The warnings you see are because the clojure.contrib.string namespace
> defines several functions that have the same name as core functions (repeat,
> reverse, etc.).  The recommended way to pull in namespaces like that is to
> do (:require [clojure.contrib.string :as str]), and then the functions can
> be used via (str/repeat ...), (str/reverse ...), etc.
> 2. As of 1.2, "split" is incorporated into clojure.string, so no need to
> grab clojure.contrib.string just for that function.  clojure.string also
> defines functions with the same name as core functions, so it should be
> pulled in via (:require [clojure.string :as str]), and split can then be
> used via (str/split ...).
> 3. That EOF error is because process-file needs one more closing paren.

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


Am I getting back a vector of lines and can I split each line?

2011-06-16 Thread octopusgrabbus
This Clojure program:

ns test-csv
  (:require [clojure.contrib.string :as str])
  (:import (java.io BufferedReader FileReader StringReader))
  (:use clojure-csv.core))


(defn process-file [file-name]
(with-open [br (BufferedReader. (FileReader. file-name))]
 (println (line-seq br


(defn -main [& args]
  (process-file "resultset.csv"))

is printing a test file. I believe line-seq returns a sequence of
strings. I am having trouble figuring out where to call str/split. The
error I'm getting back is you can cast to a regular expression. Any
thoughts?

Thanks.
cmn

-- 
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: Am I getting back a vector of lines and can I split each line?

2011-06-16 Thread octopusgrabbus
BTW I changed (:require [clojure.contrib.string :as str]) to (:require
[clojure.string :as str]) and the problem persists.

On Jun 16, 6:07 pm, octopusgrabbus  wrote:
> This Clojure program:
>
> ns test-csv
>   (:require [clojure.contrib.string :as str])
>   (:import (java.io BufferedReader FileReader StringReader))
>   (:use clojure-csv.core))
>
> (defn process-file [file-name]
>     (with-open [br (BufferedReader. (FileReader. file-name))]
>                              (println (line-seq br
>
> (defn -main [& args]
>   (process-file "resultset.csv"))
>
> is printing a test file. I believe line-seq returns a sequence of
> strings. I am having trouble figuring out where to call str/split. The
> error I'm getting back is you can cast to a regular expression. Any
> thoughts?
>
> Thanks.
> cmn

-- 
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: Java interop: casting

2011-06-16 Thread Stuart Halloway
Hi Gregg,

It appears that LocalServiceTestHelper's constructor takes an array of 
LocalServiceTestConfig. Try 

(def bar (LocalServiceTestHelper. (into-array LocalServiceTestConfig [foo])))

Stu

Stuart Halloway
Clojure/core
http://clojure.com

> Hi,
> 
> I'm trying to make the GAE local testing stuff (http://code.google.com/
> appengine/docs/java/tools/localunittesting.html)  work with Clojure
> and running into a cast problem.  Specifically, the example shows
> 
> private final LocalServiceTestHelper helper =
>new LocalServiceTestHelper(new
> LocalDatastoreServiceTestConfig());
> 
> where the LocalServiceTestHelper ctor takes one arg of type
> LocalServiceTestConfig (which is an interface).
> LocalDatastoreServiceTestConfig implements LocalServiceTestConfig.
> 
> which I try to do in clojure like this:
> 
> (def foo (new LocalDatastoreServiceTestConfig))
> (def bar (LocalServiceTestHelper. foo))
> 
> which yields a java.lang.ClassCastException.  Messing around with
> class, .getName, cast, etc. I end up with:
> 
> com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
> cannot be cast to java.lang.Class
> 
> It seems that clojure won't treat LocalDatastoreServiceTestConfig as a
> LocalServiceTestConfig.  Am I interpreting all this correctly?  I'm
> relatively new to clojure and my java is a little rusty, but I've
> banged my head on this all afternoon and I'm out of ideas.
> 
> Thanks,
> 
> Gregg
> 
> 


-- 
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: Best practice for distributing a standalone clojure command line utility

2011-06-16 Thread Miki


> A few approaches I have thought about: 1) Upload the stand alone jar 
> to github and have the "gantry" script pull down the standalone into 
> ~/.gantry and construct the command line. 2) Create a cake wrapper 
> (not preferred because it introduces a dependency). 3) Forget the 
> wrapper and just distribute the jar. 
>
1 is what lein does and it seem to work well.

You might consider creating an "uberjar" and then packing it with one of the 
various jar -> exe programs (such as IzPack). 

-- 
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: Swank-Inject Issue

2011-06-16 Thread Asim Jalis
Sweet. That worked. Thanks!

On Thu, Jun 16, 2011 at 1:32 PM, Johan Wirde  wrote:
> Hi!
> I have only built on OSX so far which is why I haven't noticed this
> problem. Apparently the com.sun.jdi classes are packaged differently than on
> other platforms (there is no tools.jar on OSX).
> The best solution I could come up with involved using a new feature from
> lein 1.6.0-SNAPSHOT (:extra-classpath-dirs).
> I would be very interested in other options for declaring a dependency on
> tools.jar in a leiningen project!
> Regards,
> Johan
> On Wed, Jun 15, 2011 at 7:55 PM, Asim Jalis  wrote:
>>
>> Hi,
>>
>> I am trying to get swank-inject to work on Ubuntu Linux and I am
>> getting a failure related to tools.jar (ClassNotFoundException:
>> com.sun.jdi.Bootstrap jdi.clj: 1). This error does not go away even if
>> I add tools.jar directly to CLASSPATH.
>>
>> Has anyone seen this error before? Any ideas on how to solve this
>> would be great.
>>
>> Thanks!
>>
>> Asim

-- 
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: Best practice for distributing a standalone clojure command line utility

2011-06-16 Thread Miki
One more option is to embed the jar in base64 encoding in a script, extract 
the jar to a temp location and run it.
The following Perl script does that (it uses the base64 executable, but you 
can probably use MIME::Base64 as well).
 #!/usr/bin/env perl

$jar = "/tmp/lp-$ENV{USER}.jar";
unless (-e $jar) {
open DECODE, "|base64 -d > $jar" or die "can't open base64 pipe";
print DECODE ;
}
exec "java", "-jar", $jar, @ARGV

__DATA__



-- 
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 about data structures and encapsulation

2011-06-16 Thread Ryan Twitchell
Regarding JavaBeans and the like, more often than not I've found that
when getters and setters do not reference fields directly, they are
contributing to a composition: as an adapter, a facade, or whatever-
you-please.  It is not quite as often that getters simply return a
calculation based on data in their own object.  With that in mind,
note that such compositions usually address the problems of
structuring a program in some new way, often at run time.  Functional
programming has lots of its own solutions for such problems.

Just for reflection:
What would you do with an existing class which had a getName() method,
when you suddenly realized you wanted getFirstName() and getLastName()
instead?  Or the reverse?
What would you do if the problem you described applied to a database
table?
What would you do if you wanted to process several unrelated classes
in a generic manner, reading data from all of them?  How about an
arbitrary number of existing, unrelated classes discovered at runtime?

Clojure does encourage programming to interfaces (and protocols), and
how much state you expose is up to you.  Consider balancing this risk
by including (for defrecords) a library of functions which achieve
your client code's most common needs regarding a record type or a set
of related types (you could probably describe this as an application
of the Pareto principle).  Try not to pepper such a library with
getter functions without good reason though.  The problem you pose is
a real risk when data can be directly accessed, there is no avoiding
that; every programming language has its trade-offs, just as every
design pattern does.

Here are a few of what I've found to be the most useful pieces of
information for appreciating Clojure's functional style, coming from
OO.  The first two, at least, you've probably found already. ;)

Directly related to your question, a clojure.org page that discusses
the disadvantages of information hiding: http://clojure.org/datatypes

"Object Orientation is overrated": http://clojure.org/rationale

Stuart Halloway's Protocols and OO presentation
(ClojureProtocolsJAOO.pdf), available from
http://github.com/stuarthalloway/clojure-presentations/downloads

Out of the Tar Pit, a 60 page essay on "functional/relational
programming".  Not a light read, but convincing.  -
http://web.mac.com/ben_moseley/frp/frp.html

Ryan


On Jun 15, 2:41 pm, Colin Yates  wrote:
> Newbie so go gentle please :).  
>
> I am an experienced OO Java developer (decade +) considering jumping fence
> to a functional language, and clojure is pretty high up on the list for a
> number of reasons.
>
> I am so used to defining everything as objects which are sealed units of
> state and behaviour that I am struggling to see how to solve the same
> problem with clojure.  I desperately wish somebody would write a "domain
> driven design with clojure" :).
>
> In brief, in OO state is exposed via a well defined API.  That state may be
> simple properties (values) or it may be calculations (functions).  And
> critically, the decision as to whether it is a value or a function is an
> implementation concern.  The Java Bean spec defines accessors for properties
> of a class, behind which lies the logic of how to retrieve that state.  So,
> the very common Person class will expose get/setName(), get/setAge() etc.
> and as a consumer I have no idea how the results are calcualted.
>
> In Clojure, if I understand correctly, the preferred way would be to use a
> map (or defstruct) with keys such as :name and :age.  These are then
> retrieved as (person :name) and (person: age) etc.  
>
> My question is if I suddenly decided that one of those values is best
> implemented as a calculation, how can I seamlessly implement that.  By
> seamless I mean implement it without updating any consumers of a person?
>  For example, if I changed the age property to be  the result of a function,
> I could either replace the value of age with a function that calculates age
> or write a function(person)->age.
>
> Both of those are disruptive to the consumers of person.
>
> I understand that clojure is about explicitly distinguishing between state
> and functions, but I see this as a high price to pay.  Have I missed
> something?  The OO in me is saying "well, never introspect a map directly,
> rather provide get-X(person) functions" but that is very very noisy.
>
> That's enough for now - this is, I expect, the first of many cries for help
> :)
>
> Thanks in advance to all who reply!

-- 
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 about data structures and encapsulation

2011-06-16 Thread Ken Wesson
On Fri, Jun 17, 2011 at 12:58 AM, Ryan Twitchell  wrote:
> Just for reflection:
> What would you do with an existing class which had a getName() method,
> when you suddenly realized you wanted getFirstName() and getLastName()
> instead?  Or the reverse?

If you can't refactor the class, that's a relatively simple one to
solve with helper methods/functions:

(defn word-seq [s]
  (map (partial apply str) (take-nth 2 (partition-by
#(Character/isWhitespace %) s

(defn is-not-capitalized [w]
  (Character/isLowerCase (first w)))

(defn get-name [first last]
  (str first " " last))

(defn get-first-name [full]
  (first (word-seq full)))

(defn get-last-name [full]
  (let [chunks (reverse (drop 1 (word-seq full)))]
(apply str
  (interpose " "
(reverse
  (cons
(first chunks)
(take-while is-not-capitalized (rest chunks

=> (get-name "Bob" "Marley")
"Bob Marley"
=> (get-first-name "Bob Marley")
"Bob"
=> (get-last-name "Bob Marley")
"Marley"
=> (get-last-name "Sarah Michelle Gellar")
"Gellar"
=> (get-last-name "Frederique van der Wal")
"van der Wal"
=> (get-last-name "Olivia d'Abo")
"d'Abo"

The only slightly tricky one is get-last-name, since some last names
are more than one word and these need to be distinguished from middle
names. Fortunately, these last names only seem to capitalize the last
chunk. The last three examples use three famous actresses' names to
demonstrate that it drops middle names, keeps multi-part surnames, and
keeps surnames that start with a noncapitalized letter but are only
one part.

Of course there may be some more obscure corner case that isn't
covered, and if the input is incorrectly capitalized or spaces are
missing, all bets are off.

Names with only one chunk are presumed to be first names, so
get-first-name returns the whole input and get-last-name an empty
string in those cases.

Note how the above is clean sequence-manipulation code without a
single ugly regexp in sight.

-- 
Some people, when confronted with a problem, think “I know, I'll use
regular expressions.”
Now they have two problems.
- Jamie Zawinski

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