Re: Allow Data Structure to Be Called as Function

2011-06-15 Thread Stuart Halloway
> You could also use reify: > > (defn make-foo [s] > (reify clojure.lang.IFn > (invoke [this] (str "Hello, " s > > ((make-foo "RJ")) > "Hello, RJ" > > I have to admit, though, that I'm unclear on the relative merits of defrecord > vs. reify. Anyone want to comment? > > Cheers, > -M

Re: clojure-csv Column or field extraction

2011-06-15 Thread David Santiago
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=

Re: clojure-csv Column or field extraction

2011-06-15 Thread octopusgrabbus
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, e

using regex reader macro with generated code

2011-06-15 Thread 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 (jo

Re: Allow Data Structure to Be Called as Function

2011-06-15 Thread RJ Nowling
Thank you, Ken and Michael. Not knowing how to do that bothered me since it felt like I couldn't create data structures that were on the same level of the built-in data structures. :) On Jun 15, 6:59 pm, Michael Nygard wrote: > You could also use reify: > > (defn make-foo [s] >   (reify clojure

Re: Allow Data Structure to Be Called as Function

2011-06-15 Thread Michael Nygard
You could also use reify: (defn make-foo [s] (reify clojure.lang.IFn (invoke [this] (str "Hello, " s ((make-foo "RJ")) "Hello, RJ" I have to admit, though, that I'm unclear on the relative merits of defrecord vs. reify. Anyone want to comment? Cheers, -Michael Nygard On Jun 15, 20

Re: Question about data structures and encapsulation

2011-06-15 Thread Colin Yates
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

Re: Where to place Arguments

2011-06-15 Thread Sean Corfield
On Wed, Jun 15, 2011 at 8:25 AM, Aaron Cohen wrote: > For one previous discussion of this same topic: > https://groups.google.com/d/msg/clojure/iyyNyWs53dc/13dWIhwTKzoJ Very helpful. Rich's explanation helps clarify something that hasn't (yet) sunk in for me: the difference between "collection" a

Re: Question about data structures and encapsulation

2011-06-15 Thread Sean Corfield
Hi Colin! Welcome to Clojure! On Wed, Jun 15, 2011 at 11:41 AM, Colin Yates wrote: > 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. The FP approach certainly takes some getting used to after a lot of Ja

Re: clojure-csv Column or field extraction

2011-06-15 Thread David Santiago
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

Re: Question about data structures and encapsulation

2011-06-15 Thread Laurent PETIT
Hi, I must admit my thoughts are still not fixed concerning this, guided by several considerations: * consider the ring spec: it specifies what keys are expected to be present in the request map, the response map. Good enough. * Wait ! what if some keys could be calculated from others (derived)

Re: Emacs setup - quick navigation to files and definitions

2011-06-15 Thread looselytyped
emacs-nav is a lightweight "project explorer" for emacs that I have found useful - https://code.google.com/p/emacs-nav/ It has the ability to grep the directory structure for a symbol (Press 'g' when the cursor is in the emacs-nav window). I find that handy to search for function names across proj

Re: Allow Data Structure to Be Called as Function

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 3:53 PM, RJ Nowling wrote: > Hi, > > I'm sorry if this has been asked before, but I would like to know how > to create data structures in Clojure that can be used in the same way > as the built-in data structures.  For example, I can access the > elements of a vector by (my

Allow Data Structure to Be Called as Function

2011-06-15 Thread RJ Nowling
Hi, I'm sorry if this has been asked before, but I would like to know how to create data structures in Clojure that can be used in the same way as the built-in data structures. For example, I can access the elements of a vector by (my-vec 1). How can I implement this interface when creating a da

Re: Question about data structures and encapsulation

2011-06-15 Thread Meikel Brandmeyer
Hi, and just today this was posted to reddit: http://skillsmatter.com/podcast/scala/talk-by-patrick-fredriksson 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

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
Thanks for all the responses. This was a success. On Jun 15, 3:02 pm, octopusgrabbus wrote: > Thanks for the response. I eventually found that as well. > > (ns test-csv >   (:gen-class) >   (:import (java.io BufferedReader FileReader)) >   (:use clojure-csv.core)) > > (defn process-file [file-nam

clojure-csv Column or field extraction

2011-06-15 Thread octopusgrabbus
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" grou

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
Thanks for the response. I eventually found that as well. (ns test-csv (:gen-class) (:import (java.io BufferedReader FileReader)) (:use clojure-csv.core)) (defn process-file [file-name] (with-open [br (BufferedReader. (FileReader. file-name))] (parse-csv (line-seq

Re: Question about data structures and encapsulation

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 2:41 PM, Colin Yates wrote: > 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 o

Question about data structures and encapsulation

2011-06-15 Thread Colin Yates
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

Re: Why is class name not found?

2011-06-15 Thread Mark Rathwell
See Ken's post, there is a paren out of place in test_csv.clj. On Wed, Jun 15, 2011 at 2:02 PM, octopusgrabbus wrote: > Yes, I did all that. > > On Jun 15, 2:01 pm, Mark Rathwell wrote: > > Did you run the command to re-pull the dependencies, then rebuild your > jar? > > (I'm assuming it is som

Re: Why is class name not found?

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 1:58 PM, octopusgrabbus wrote: > java.lang.ClassNotFoundException: :use.clojure-csv (test_csv.clj:1) > > (ns test-csv >  (:import (java.io BufferedReader FileReader) >  (:use clojure-csv))) Oops. You're trying to import your use clause. (ns test-csv  (:import (java.io Bu

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
Yes, I did all that. On Jun 15, 2:01 pm, Mark Rathwell wrote: > Did you run the command to re-pull the dependencies, then rebuild your jar? >  (I'm assuming it is something like 'cake deps') > > On Wed, Jun 15, 2011 at 1:58 PM, octopusgrabbus > wrote: > > > > > > > > > I'm getting a new error:]

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
If I take the :use clojure-csv out of test_csv.clj, it compiles and all is well. I am guessing this is because I've mentioned clojure-csv in the project.clj file. On Jun 15, 1:58 pm, octopusgrabbus wrote: > I'm getting a new error:] > >   [compile] Compiling namespace test-csv > error evaluating:

Re: Why is class name not found?

2011-06-15 Thread Mark Rathwell
Did you run the command to re-pull the dependencies, then rebuild your jar? (I'm assuming it is something like 'cake deps') On Wed, Jun 15, 2011 at 1:58 PM, octopusgrabbus wrote: > I'm getting a new error:] > > [compile] Compiling namespace test-csv > error evaluating: > ((compile-stale source

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
I'm getting a new error:] [compile] Compiling namespace test-csv error evaluating: ((compile-stale source-path compile-path)) java.lang.RuntimeException: java.lang.ClassNotFoundException: :use.clojure-csv (test_csv.clj:1) Here's the modified project.clj -

Swank-Inject Issue

2011-06-15 Thread Asim Jalis
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

Re: Why is class name not found?

2011-06-15 Thread Mark Rathwell
It is standard to name your filenames with underscores, but your clojure names with dashes (so 'ns test_csv' should be 'ns test-csv'). Also update that in your project.clj :main key. That may or may not be the cause of the problem here. On Wed, Jun 15, 2011 at 1:19 PM, octopusgrabbus wrote: > I

Re: Why is class name not found?

2011-06-15 Thread octopusgrabbus
I am invoking the program using java -jar test_csv-0.1-standalone.jar On Jun 15, 1:19 pm, octopusgrabbus wrote: > I am getting this error and cannot find out what I've done wrong. Any > pointers would be very appreciated. > > Exception in thread "main" java.lang.NoClassDefFoundError: test_csv > >

Why is class name not found?

2011-06-15 Thread octopusgrabbus
I am getting this error and cannot find out what I've done wrong. Any pointers would be very appreciated. Exception in thread "main" java.lang.NoClassDefFoundError: test_csv I have built the project in test_csv successfully using cake. project.clj -- (defproject test_csv "0.1" :de

Re: Clojure group in DFW area

2011-06-15 Thread ch...@rubedoinc.com
Everyone, sorry for late notice but are meeting tonight is cancelled due to some scheduling conflicts. We have another meeting set for Tuesday June 28th 630PM - 900PM @ Rubedo, inc. 14580 Beltwood Pkwy E Suite 103 Farmers Branch, TX 75244 See you then ! On Jun 3, 9:46 am, "ch...@rubedoinc.com"

Re: (function [args] more args)

2011-06-15 Thread James Keats
Hi, I admit that subvec is not a good example as it does indeed take a vector as a first argument, perhaps i'll find better example or perhaps I might've just been confused. I learnt lisp and scheme many years ago, abandoned them for languages with better libraries, and I'm perhaps thrown off by th

Re: (function [args] more args)

2011-06-15 Thread Paul Lam
The enclosed vector (or list, map, set, etc) is considered as arg1 because it is one entity. Take a look at the source for subvec: => (clojure.repl/source subvec) (defn subvec "Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied

Re: Having trouble figuring out dependencies

2011-06-15 Thread Mark Rathwell
Just to be clear, you do not need to download and build all of your dependencies, and you do not need to worry about whether they are on your classpath. I don't know cake, but I assume it is similar to leiningen in that is manages all of your dependencies for you, via maven, and again, if like lei

Aw: (function [args] more args)

2011-06-15 Thread Meikel Brandmeyer
Hi, in your example the vector *is* the argument. You could just as well write (let [x [1 2 3 4 5]] (subvec x 1 3)). On function definition the arguments are given in a vector, yes. I'm not sure I understand your concern completely. Sincerely Meikel -- You received this message because you a

Re: Having trouble figuring out dependencies

2011-06-15 Thread octopusgrabbus
I happened to have clojure-contrib 1.2.0 changed that dependency, and it built. Many thanks. On Jun 15, 11:43 am, Ambrose Bonnaire-Sergeant wrote: > On Wed, Jun 15, 2011 at 11:26 PM, octopusgrabbus > wrote: > > > Here is the project.clj > > (defproject helloworld "0.1" > >    :dependencies [[org.

Re: (function [args] more args)

2011-06-15 Thread Timothy Baldridge
So let me see if I can help out with this. In classic lisp, when you define a function it would take this syntax: (defn name (arg1 arg2) body) The only problem with this approach is that sometimes it is hard to figure out what is part of the body and what is the argument lists. Clojure so

Re: Having trouble figuring out dependencies

2011-06-15 Thread Ambrose Bonnaire-Sergeant
On Wed, Jun 15, 2011 at 11:26 PM, octopusgrabbus wrote: > Here is the project.clj > (defproject helloworld "0.1" >:dependencies [[org.clojure/clojure > "1.1.0-master-SNAPSHOT"] > [org.clojure/clojure-contrib > "1.0-SNAPSHOT"]] >

(function [args] more args)

2011-06-15 Thread James Keats
Hi again. This is another syntax that I'm struggling with: (function [args] more args) Or for example: (subvec [1 2 3 4 5] 1 3) Please note I'm not referring specifically to the subvec function, but simply using it as an example, as I've seen this syntax with many other functions, but it escap

Re: Having trouble figuring out dependencies

2011-06-15 Thread octopusgrabbus
Here is the project.clj (defproject helloworld "0.1" :dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"] [org.clojure/clojure-contrib "1.0-SNAPSHOT"]] :main helloworld) but I've had an aha moment. Nothing prevents me f

Re: Where to place Arguments

2011-06-15 Thread Aaron Cohen
On Tue, Jun 14, 2011 at 4:28 PM, Nick Zbinden wrote: > I'm writing this here because of two reasons: > 1. The universial threading operator keeps showing up. Im not saying > its a always a bad thing but I think we should trie to avoid it in > most cases and the standard on the parameter order wou

Re: Having trouble figuring out dependencies

2011-06-15 Thread Ambrose Bonnaire-Sergeant
Hi cmn, Cake manages your dependencies via maven, you shouldn't need to worry about classpaths or local jars. Do you have a project.clj file in your project root? Can you post it here? Thanks, Ambrose On Wed, Jun 15, 2011 at 10:57 PM, octopusgrabbus wrote: > I have clojure-1.2.1.jar. It is in

Re: Having trouble figuring out dependencies

2011-06-15 Thread octopusgrabbus
I've found the missing Clojure releases on github, will unpack and put in my CLASSPATH. On Jun 15, 10:57 am, octopusgrabbus wrote: > I have clojure-1.2.1.jar. It is in my classpath. > I am trying to build a very simple hello world project with cake, and > have two dependencies: > > org.clojure:cl

Re: Using clojure-csv

2011-06-15 Thread .Bill Smith
The indentation made it confusing, but the (use ...) was outside of the (ns ...). I had the same initial reaction, especially since i prefer (:use) over (use) except when typing code into the REPL. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Having trouble figuring out dependencies

2011-06-15 Thread octopusgrabbus
I have clojure-1.2.1.jar. It is in my classpath. I am trying to build a very simple hello world project with cake, and have two dependencies: org.clojure:clojure:jar:1.1.0-master-SNAPSHOT org.clojure:clojure-contrib:jar:1.0-SNAPSHOT Is this a cake dependency? I can't figure out why cake needs the

Re: (. rnd nextInt) vs (.nextInt rnd)

2011-06-15 Thread James Keats
> > > What's the point of the sugared version? It's not any less to type. > > Actually there's one fewer character -- a space. > Okay, I'll give you that. > > It's also incomprehensible to me how it came about. In the middle one > > it's simple, class and method, but the in sugared one it's just

Re: Using clojure-csv

2011-06-15 Thread octopusgrabbus
Thanks. It wasn't on the CLASSPATH. On Jun 14, 3:41 pm, David Santiago wrote: > I think the basic problem is Clojure is not able to find the > clojure-csv jar file. I'm afraid I'm not quite clear enough on your > specific setup to know exactly what has gone wrong. I'm not sure where > you have th

Re: loop/recur and tail postion

2011-06-15 Thread Kevin Sookocheff
Thanks everyone. Makes perfect sense. -- 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 unsubscri

Re: loop/recur and tail postion

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 10:08 AM, Kevin Sookocheff wrote: > Hi, I'm going through some Scheme code to learn Clojure.  I defined a > function > > rember > > as > > > (defn rember [atom l] >         (loop [a atom lat l] >        (cond >         (empty? lat) `() >         (= (first lat)

Re: (. rnd nextInt) vs (.nextInt rnd)

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 9:52 AM, James Keats wrote: > Hi all. I'm struggling to see the point of this (from Pragmatic's > Programming Clojure): > > Java  =>  rnd.nextInt() > Clojure => (. rnd nextInt) > sugared => (.nextInt rnd) > > > What's the point of the sugared version? It's not any less to t

Aw: loop/recur and tail postion

2011-06-15 Thread Meikel Brandmeyer
Hi, no, it's not. The cons is in the tail position. Here a working version. (defn rember [a l] (loop [ret [] lat (seq l)] (cond (not lat) ret (= (first lat) a) (recur ret (next lat)) :else (recur (conj ret (first lat)) (next lat) Note, h

Re: loop/recur and tail postion

2011-06-15 Thread Jonas
> Is the call to recur not in tail position here? > > No, because of (cons (first lat) (recur a (rest lat))). You cons (first lat) after you call (recur ...). That is why (recur ...) is not in tail position. -- You received this message because you are subscribed to the Google Groups "Cloju

loop/recur and tail postion

2011-06-15 Thread Kevin Sookocheff
Hi, I'm going through some Scheme code to learn Clojure. I defined a function rember as (defn rember [atom l] (loop [a atom lat l] (cond (empty? lat) `() (= (first lat) a) (rest lat) :else (cons (first lat) (recur a (rest lat))

Re: (. rnd nextInt) vs (.nextInt rnd)

2011-06-15 Thread Joop Kiefte
The difference is that the sugared version works just like a normal Clojure function. It also eases a lot of things with macros like (doto). 2011/6/15 James Keats : > Hi all. I'm struggling to see the point of this (from Pragmatic's > Programming Clojure): > > Java  =>  rnd.nextInt() > Clojure =>

(. rnd nextInt) vs (.nextInt rnd)

2011-06-15 Thread James Keats
Hi all. I'm struggling to see the point of this (from Pragmatic's Programming Clojure): Java => rnd.nextInt() Clojure => (. rnd nextInt) sugared => (.nextInt rnd) What's the point of the sugared version? It's not any less to type. It's also incomprehensible to me how it came about. In the midd

Re: ClassNotFoundException with dynamically compiled classes

2011-06-15 Thread Tassilo Horn
Ken Wesson writes: Hi Ken, >> Why can't I access that class by its qualified name although it's >> there? > > Perhaps it's not visible to the normal classloader, but it is to some > other classloader used by this graph library. Yes, indeed that library uses its own classloader. > Can you not j

Re: SQL queries on csv-files

2011-06-15 Thread Shantanu Kumar
Clojure-CSV might be useful: https://github.com/davidsantiago/clojure-csv Regards, Shantanu On Jun 14, 6:06 pm, Mark wrote: > Although it may be overkill for you, take a look at Teiid:  http://teiid.org > > On Jun 14, 5:30 am, finbeu wrote: > > > > > > > > > Hello, > > > I have a couple of csv

Re: ClassNotFoundException with dynamically compiled classes

2011-06-15 Thread Ken Wesson
On Wed, Jun 15, 2011 at 6:27 AM, Tassilo Horn wrote: > Hi all, > > in my clojure project, I'm working with an external java graph library. > Graphs represented by that library conform to a user-specified data > model, that is, the graph itself and all its vertices and edges are > objects of some j

ClassNotFoundException with dynamically compiled classes

2011-06-15 Thread Tassilo Horn
Hi all, in my clojure project, I'm working with an external java graph library. Graphs represented by that library conform to a user-specified data model, that is, the graph itself and all its vertices and edges are objects of some java class, which is dynamically generated and compiled when loadi

Re: Emacs setup - quick navigation to files and definitions

2011-06-15 Thread Kelvin Ward
In my experience ECB and Speedbar (both come with CEDET) is the only option. I think that speedbar may be available without cedet, but it seems less functional. ECB can keep the speedbar window fixed regardless of closing/opening other emacs windows. It's not a nice as IDEs I'd say, but certainly d

Re: No any? function

2011-06-15 Thread de1976
Thanks for the responses. I agree that "some" takes care of things quite nicely. The asymmetrical naming convention in this case was what caught my eye. Just wanted to make sure if it was a deliberate design decision or an oversight. Sounds like it was done by design. On Jun 14, 9:29 am, Ambrose