[ANN] eq - A command line tool for edn

2016-06-12 Thread Jonas
Hi!

I've been working on a command line tool for edn processing and pretty 
printing. The project is available at https://github.com/jonase/eq and it 
is heavily inspired by jq (https://stedolan.github.io/jq/). Eq could be a 
very useful tool if you're working a lot with edn data (for example via 
curl).

There are no pre-built binaries available yet so you'll need to be build it 
manually. There are instructions in the projects README.

This is a very young project. The query syntax will evolve and new 
primitives will be added. Feel free to provide bug reports or feature 
requests via github.

/Jonas

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


core.async pub/sub closing source channel issue

2015-03-01 Thread Jonas
Hi all!

I’m working with core.async pub/sub and ran into an issue which I don’t 
quite understand. According to the clojure.core.async/sub docstring:

 By default the channel will be closed when the source closes

This is not the behaviour I’m seeing when I call 
clojure.core.async/unsub-all immediately after I close the source channel.

Example:

(def source (async/chan))
(def sub-chan (async/chan))
(def pub (async/pub source (constantly foo)))

;; by default sub-chan should close when source closes
(async/sub pub foo sub-chan) 

;; This will not close sub-chan
(async/thread
  (async/close! source)
  (async/unsub-all pub))

;; This will close sub-chan
(async/thread
  (async/close! source))

What is the reason for this behaviour? Is it unnecessary to call unsub-all 
if I close the publications source channel?

Thanks,
Jonas

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: a nicer way to write 1 - 2 + 3 - 4 ... +/- n

2014-11-14 Thread Jonas
Is this cheating?

(defn altsum [n]
  (int (* (if (even? (inc n)) 1 -1) 
  (Math/floor (/ (inc n) 2)

On Friday, November 14, 2014 3:31:38 AM UTC+2, Andy L wrote:

 Hi,

 All I was able to come up with was this 

 (defn altsum[n] (reduce + (map * (range 1 (inc n))  (interpose -1 (repeat 
 1)

 ... works quite well, however I was wondering if there is more idiomatic 
 way to write that.

 Thanks,
 Andy


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transducers: Why left to right rather than right to left?

2014-10-30 Thread Jonas
clojure.core/comp has not been changed at all. It's just the nature of how 
transducers work. Here's a another example where function composition seems 
to compose left-to-right (the second example, `comp2`):

(defn add-3 [x] (+ 3 x))
(defn mul-2 [y] (* 2 y))
(defn sub-1 [z] (- 1 z))

(def comp1 (comp add-3 mul-2 sub-1))

;; (comp1 2)
;; (add-3 (mul-2 (sub-1 2)))
;; ((fn [x] (+ x 3)) ((fn [y] (* y 2)) (fn [z] (- 1 z)) 2))
;; ((fn [x] (+ x 3)) ((fn [y] (* y 2)) (- 1 2)))
;; ((fn [x] (+ x 3)) (* (- 1 2) 2))
;; (+ (* (- 1 2) 2) 3)
;; 1

(defn add-3 [f]
  (fn [x]
(f (+ 3 x

(defn mul-2 [f]
  (fn [x]
(f (* 2 x

(defn sub-1 [f]
  (fn [x]
(f (- 1 x

(def comp2 ((comp add-3 mul-2 sub-1) identity))

;; (comp2 2)
;; ((add-3 (mul-2 (sub-1 identity))) 2)
;; ((add-3 (mul-2 (fn [x] (identity (- 1 x) 2) 
;; ((add-3 (fn [x] ((fn [x] (identity (- 1 x))) (* 2 x 2) 
;; ((fn [x] ((fn [x] ((fn [x] (identity (- 1 x))) (* 2 x))) (+ 3 x))) 2)
;; ((fn [x] ((fn [x] (identity (- 1 x))) (* 2 x))) (+ 3 2))
;; ((fn [x] (identity (- 1 x))) (* 2 (+ 3 2)))
;; (identity (- 1 (* 2 (+ 3 2
;; (- 1 (* 2 (+ 3 2)))
;; -9

which is the same as with -

(- 2 
 (+ 3)
 (* 2)
 (- 1))
;; -9


On Thursday, October 30, 2014 5:44:48 PM UTC+2, Mars0i wrote:

 Caveat: I am still feeling around in the dark in my understanding of 
 transducers.  What I write below may just convey how clueless I am.

 (Meta-caveat: I'm probably spitting into the wind.  I should no doubt use 
 my time more wisely.)


 Normal function composition is done starting from the right.  This is 
 familiar from mathematics, other Lisps, most languages, and it's how 
 Clojure's function application and 'comp' work.

 Sometimes it's easier to understand composition going from left to right, 
 as in many natural languages and as in unix pipes, and Clojure provides 
 '-' and '-' to do that.  That's good.  Best of both worlds.  One thing I 
 like about these operators is that their name clearly indicates the 
 direction of function application.

 Transducers allow function composition with potential efficiency gains, 
 but apply functions starting from left to right.  But *it does this using 
 the name 'comp'*, which otherwise applies functions from right to left.  
 What??  Doesn't that seem like a Bad Thing?  Why not use a different name?  
 (It's like overloading the minus sign so that in some contexts, it 
 subtracts the first argument from the second.)

 (Is Clojure is getting too popular?  Its essential features--prefix 
 notation, parentheses, purely functional operations, and laziness--aren't 
 doing enough to scare away Java programmers?  :-)


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ANN: Om 0.8.0-alpha1, Reference Cursors!

2014-10-18 Thread Jonas Enlund
Hi

Interesting work as usual! One quick question: What is the difference between 

(let [xs (om/observe owner (items))]
  ...)

as seen in the sub-view component versus the one in main-view which doesn't use 
`om/observe`:

(let [xs (items)]
   ...)


/Jonas


On Saturday, October 18, 2014 6:53:50 PM UTC+3, David Nolen wrote:
 I'm happy to announce the release of Om 0.8.0-alpha1. This release
 
 includes the single biggest conceptual enhancement since its initial
 
 release - Reference Cursors.
 
 
 
 As we begin to build larger and larger applications with Om, we
 
 often run afoul of the need to organize our application around a
 
 hierarchical tree. This is more problematic than in React itself as Om
 
 emphasizes a programming model that supports full snapshotting of the
 
 application state. This seemingly beneficial property actually
 
 exacerbates the hierachical issue and often leads to an incredible
 
 amount non-modular programming!
 
 
 
 The introduction of Reference Cursors allow Om programmers to stop
 
 thinking in terms of trees and return to a more natural mode of UI
 
 programming - simply calling out into shared APIs around application
 
 data precisely where you need it. No need to pass data through
 
 intermediate components on way to the target child component -
 
 Reference Cursors allow you to get at the data exactly where it is
 
 required and this without abandoning the ability to time travel over
 
 your application state.
 
 
 
 There are more thoughts and details here:
 
 https://github.com/swannodette/om/wiki/Advanced-Tutorial#reference-cursors
 
 
 
 Please give Reference Cursors a try in your application and send lots
 
 of feedback!
 
 
 
 This is an alpha release. No previous Om APIs should be affected,
 
 however the Reference Cursor feature is largely untested beyond
 
 a simple example in the repo.
 
 
 
 https://github.com/swannodette/om
 
 
 
 Cheers,
 
 David

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Clojure:Lisp :: LSD:Meditation

2014-06-13 Thread Jonas
I found this post from 2011 which probably is still 
relevant: https://groups.google.com/d/msg/clojure/t0pGIuoyB7I/RQtuuAOhes8J

On Friday, June 13, 2014 1:05:47 PM UTC+3, David Della Costa wrote:

 You raise a good point, which is that I don't know what the group policy 
 is or where it's posted.  I just see this in the header on the google 
 groups page: 

 Welcome to the Clojure mailing list. Please note that posts by new 
 members are moderated to prevent spam. 

 Anyone know better than this? 

 (2014/06/13 18:50), Josh Kamau wrote: 
  If i were to be asked, i would restrict the group to: 
  1. Any type of question that is related to clojure 
  2. Any type of announcement on clojure core library 
  3. Any new library/version 
  4. Any link to a narration on real life usages (e.g how we did xyz with 
  clojure) or benchmarks  (generally hard facts ) 
  5. Any link to new book, tutorial, training materials. 
  
  This is just my opinion, I dont know the group policy and may be its all 
  up to me to choose what i want to read and what i dont want to and 
  probably keep my feelings to myself ;) 
  
  Josh 
  
  
  On Fri, Jun 13, 2014 at 12:34 PM, Dave Della Costa 
  ddell...@gmail.com javascript: mailto:ddell...@gmail.com 
 javascript: wrote: 
  
  I'm not sure what the problem is here.  I've posted personal blog 
 links 
  before that were Clojure related; I sincerely thought that it was 
  potentially useful to the group, and I more or less got responses 
 that 
  supported that. 
  
  That being the case, I'm having a hard time understanding what is so 
  different about my blog post and Divyansh's; as far as I can tell, 
 this 
  post is relevant to Clojure, even if it's a bit more...exploratory. 
  It 
  has Clojure code examples, it talks about Common Lisp and Python and 
  metaprogramming.  It's clearly not random spam. 
  
  So it seems to me that some folks simply don't like the content; 
 that's 
  fine, but I think it's a stretch to say that it's not appropriate 
 for 
  this list.  Or if it is not appropriate, then even relevant blog 
 posts 
  should never be appropriate, and arguably stuff like, say, epic 
  ruminations on the nature of literate programming would arguably be 
 even 
  less appropriate for the list. 
  
  DD 
  
  (2014/06/13 11:25), Gary Trakhman wrote: 
   To be fair, I actually read the thing, but I hoped to see more 
   interesting information on LSD, meditation and Clojure than the 
  headline 
   would suggest :-). 
   
   
   On Thu, Jun 12, 2014 at 10:01 PM, Atamert Ölçgen mu...@muhuk.com 
 javascript: 
  mailto:mu...@muhuk.com javascript: 
   mailto:mu...@muhuk.com javascript: mailto:mu...@muhuk.com 
 javascript: wrote: 
   
   There's also Planet Clojure http://clojure.in/. 
   
   @Divyansh 
   
   Josh, Hussein and Gary are not the only ones who think this 
  sort of 
   traffic building is uncool. By traffic building I mean; 
 sending a 
   message with a link that has no valuable information for the 
 group 
   members. They are probably just nodding their head and 
  thinking that 
   sending another response is not necessary. At least that's 
 what I 
   did before I saw your response. 
   
   90% of the messages in this group doesn't interest me. That's 
  fine. 
   Valuable information for someone else. But I certainly 
  wouldn't want 
   everybody to post their blogs here regularly. Because each 
 message 
   is a tiny little distraction. I'm willing to pay the price 
 because 
   when a really cool library is announced for example, I get a 
 big 
   reward. Let's keep the benefit/cost ratio, time-wise  
   attention-wise, high. 
   
   
   
   
   On Thu, Jun 12, 2014 at 10:05 PM, Gary Trakhman 
   gary.t...@gmail.com javascript: mailto:gary.t...@gmail.com 
 javascript: 
  mailto:gary.t...@gmail.com javascript: mailto:
 gary.t...@gmail.com javascript: 
  wrote: 
   
   Twitter's a more organic way to do this.  Your followers 
 can 
   read it, decide to retweet or not. 
   
   
   On Thu, Jun 12, 2014 at 5:37 PM, Divyansh Prakash 
   divyansh...@gmail.com javascript: 
  mailto:divyansh...@gmail.com javascript: 
   mailto:divyansh...@gmail.com javascript: 
  mailto:divyansh...@gmail.com javascript: wrote: 
   
   Sorry if you feel that way. Thought i could share my 
   thoughts and start an interesting discussion. 
   That is what the group is for. 
   You are obviously free to skip anything that doesn't 
   interest you. That was the prime reason for the 
  concise title. 
   I 

Re: Animation libraries for clojurescript?

2014-04-20 Thread Jonas
Hi,

I have looked at quite a few Javascript 2D graphics libraries. The ones I 
found particularly interesing are paper.js[1] and fabric.js[2]. At least 
paper.js is in active development and works fine with ClojureScript.

Depending on your requirements SVG might also be a good alternative. I've 
found that SVG + one of the new React based CLJS wrapper libs is an 
excellent fit (see my experiments in reagent[3] and om[4]). There are also 
js libs for working with SVG such as Raphael[5] and the newer Snap.svg[6] 
(which is by the same author as Raphael).

/Jonas

[1] http://paperjs.org/
[2] http://fabricjs.com/
[3] https://github.com/jonase/elements
[4] https://github.com/jonase/om-svg-tests
[5] http://raphaeljs.com/
[6] http://snapsvg.io/

On Sunday, April 20, 2014 12:19:17 AM UTC+3, puzzler wrote:

 Are there any javascript 2D animation libraries that are particularly 
 well-suited for use from clojurescript?

 I'm especially interested in a library that uses a scenegraph to store 
 graphical objects in hierarchical relationships to one another.

 Thanks,

 Mark


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: probably a noobie question: apparent memory leak

2014-03-29 Thread Jonas
You could give core.rrb-vector[1]. From the docs:

The main API entry points are clojure.core.rrb-vector/catvec, 
performing vector concatenation, and clojure.core.rrb-vector/subvec, which 
produces a new vector containing the appropriate subrange of the input 
vector (in contrast to clojure.core/subvec, which returns a view on the 
input vector).

[1] https://github.com/clojure/core.rrb-vector

On Saturday, March 29, 2014 8:42:25 PM UTC+2, Ryan Waters wrote:

 If you do a (count @mem) it reports the length of the atom's vector isn't 
 growing without bounds.  It seems counterintuitive that the parts of the 
 old vector wouldn't get garbage collected because the atom no longer points 
 to them.  But I guess I need to rtfd.

 Thank you.


 On Sat, Mar 29, 2014 at 10:07 AM, Aaron Cohen 
 aa...@assonance.orgjavascript:
  wrote:



 On Sat, Mar 29, 2014 at 10:09 AM, Ryan Waters 
 ryan@gmail.comjavascript:
  wrote:

 I have some code that blows up the heap and I'm not sure why.  I've 
 reduced it down to the following.

 I've tried to make sure the atom doesn't have boundless growth and I 
 didn't think 'while' hangs on to the head of sequences so I'm embarrassed 
 to say I'm stumped.


 (defn leaks-memory
   []
   (let [mem (atom [])
 chunksize 1000
 threshold 2000]
   (while true
 (swap! mem conj (rand-int 100))

 ; every 'chunksize' item past 'threshold'
 (when (and (= 0 (mod (count @mem) chunksize))
( (count @mem) threshold))
   (swap! mem subvec chunksize)

 (doc subvec)

 Returns a persistent vector of the items in vector from
 start (inclusive) to end (exclusive). If end is not supplied,
 defaults to (count vector). This operation is O(1) and very fast, as
 the resulting vector shares structure with the original and no
 trimming is done.

 subvec is fast, but it's not saving you any memory.

 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: oob schemas, re: The Language of the System

2014-01-18 Thread Jonas
IIRC in that particular part of the talk he was specifically talking about 
(non-self describing) protocol buffers and not JSON.  

On Saturday, January 18, 2014 10:00:09 PM UTC+2, Brian Craft wrote:

 Regarding Rich's talk (http://www.youtube.com/watch?v=ROor6_NGIWU), can 
 anyone explain the points he's trying to make about self-describing and 
 extensible data formats, with the JSON and google examples?

 He argues that google couldn't exist if the web depended on out-of-band 
 schemas. He gives as an example of such a schema a JSON encoding where an 
 out-of-band agreement is made that field names with substring date refer 
 to string-encoded dates.

 However, this is exactly the sort of thing google does. It finds dates, 
 and other data types, heuristically, and not through the formats of the web 
 being self-describing or extensible.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] Eastwood 0.1.0 Clojure lint tool

2014-01-11 Thread Jonas
Andy and Nicola has done truly amazing work with this release! Check out 
the graph describing issues created/solved for tools.analyzer(.jvm) during 
the last 60 days: 
http://dev.clojure.org/jira/secure/ConfigureReport.jspa?projectOrFilterId=project-10371periodName=dailydaysprevious=60cumulative=trueversionLabels=majorselectedProjectId=10371reportKey=com.atlassian.jira.plugin.system.reports%3Acreatedvsresolved-reportNext=Next

Cheers,
Jonas

On Saturday, January 11, 2014 9:30:46 AM UTC+2, Andy Fingerhut wrote:

 Eastwood is a Clojure lint tool.  It analyzes Clojure source code in 
 Leiningen projects, reporting things that may be errors.

 Installation instructions are in the documentation here:

 https://github.com/jonase/eastwood

 For example, did you know that if you use clojure.test to write tests, and 
 have multiple deftest definitions in the same namespace with the same name, 
 then the tests in all but the last deftest will never be run, whether those 
 tests would pass or fail?  Eastwood can find those duplicate names, as well 
 as other occurrences of the same Var name defined more than once.

 Eastwood can also warn about misplaced doc strings, calling deprecated 
 functions or Java methods, expressions that are suspicious because they 
 always return the same value (e.g. (= expr) is always true), expressions 
 whose return value is not used and appear to have no side effects, and a 
 few others.  See the documentation linked above for a complete list.

 Jonas Enlund wrote the original version of Eastwood with the help of 
 several other contributors.  Version 0.1.0 is an update by Jonas, Nicola 
 Mometto, and myself.  It uses the new Clojure contrib libraries 
 tools.reader for reading the code, and tools.analyzer and 
 tools.analyzer.jvm for parsing the source into abstract syntax trees, 
 making it straightforward to write many of the linters.  Thanks especially 
 to Nicola Mometto for tireless enhancements and bug fixes to those 
 libraries.

 You can file issues on the Github issue tracker if you encounter problems, 
 but please read the Known Issues section of the documentation before 
 filing problems.  Several issues have already been discovered, and their 
 causes documented, while testing Eastwood on most of the Clojure contrib 
 libraries, Clojure itself, and over 35 other open source libraries.

 Go squash some bugs!

 Andy Fingerhut



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How can I improve this?

2014-01-10 Thread Jonas
Here's a version using reduce:

  (defn uniquify [items]
(first
  (reduce (fn [[result count-map] item]
(let [n (inc (count-map item 0))]
  [(conj result (str item _ n))
   (assoc count-map item n)]))
  [[] {}]
  items)))

Replace (str item _ n) with (if (zero? n) item (str item _ n) if you 
don't want to append _0 the first time you encounter a new string

On Friday, January 10, 2014 5:12:27 PM UTC+2, Alex Miller wrote:

 I would not use an atom. Think about it as doing a reduce while passing 
 along a set of the names you've seen so far. You might also look at the 
 implementation of distinct in clojure.core which is similar (you want to 
 detect duplicates in the same way, but emit new names instead of omitting 
 dupes).


 On Friday, January 10, 2014 8:59:10 AM UTC-6, Colin Yates wrote:

 I have a sequence of file names and I want to make them unique. 
  (uniquify [a b c a]) = [a b c a_1])

 This is what I have come up with, but surely there is a better way?

 What would you all do?  Feedback welcome (including the word 'muppet' as 
 I am sure I have missed something simple) :)

 (defn uniquify
   Return a sequence, in the same order as s containing every element
   of s. If s (which is presumed to be a string) occurs more than once
   then every subsequent occurrence will be made unique.

   Items will be updated to include an incrementing numeric count using
   the specified formatter function. The formatter function will be
   given the name and the number and should return a combination of the
   two.

   The set of unique s's in the returned sequence will be the count of
   s's in s.  
   ([s] (uniquify s (fn [item duplicates] (str item _ duplicates
   ([s formatter]
  (let [occurrences (atom {})
register-occurrence (fn [item]
  (if (get @occurrences item)
(swap! (get @occurrences item) inc)
(swap! occurrences assoc item (atom 
 1)))
  @(get @occurrences item))
process (fn [item]
  (let [duplicates (dec (register-occurrence item))]
(if ( duplicates 0)
  (formatter item duplicates)
  item)))
unique-s (map process s)]
unique-s)))



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How can I improve this?

2014-01-10 Thread Jonas Enlund
On Fri, Jan 10, 2014 at 9:39 PM, Mark Engelberg mark.engelb...@gmail.comwrote:

 Technically, all these solutions are flawed.

 With the input
 [a a a_1]
 you'll get back
 [a a_1 a_1]

 To truly address this, you need to also add the newly formatted filename
 into the seen map, which none of the suggested solutions do.


That's why I wrote my solution like I did, i.e., concatenate _1 when a
new string is found. This would result in the vector [a_1 a_2 a_1_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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/rt-l_X3gK-I/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to go about 'proving' why dynamically typed languages are better.

2013-10-08 Thread Jonas


On Tuesday, October 8, 2013 10:19:07 PM UTC+3, Laurent PETIT wrote:




 2013/10/8 Greg Bowyer gbo...@fastmail.co.uk javascript:

 js Array(16).join(wat - 1) +  Batman!
 NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!
 js 

  
 One of the many reasons we're using Clojurescript and not raw javascript 
 :-) 


ClojureScript is an improvement, no doubt about that! But 
javascript idiosyncrasies does leak through on 
occasion: http://cljsfiddle.net/fiddle/jonase.batman
 



 On Tuesday, October 8, 2013 6:07:47 AM UTC-7, Laurent PETIT wrote:

 2013/10/8 Robert Day rober...@gmail.com


 On 08/10/13 13:49, Nando Breiter wrote:




 If you try and add 10 to Hello in a typed language, you get an 
 error. If you try to do the same in a dynamic language, you get an error.


 Not necessarily...

 $ perl
 print 10 + Hello, \n


 ^D
 10
 $


 Then don't use Perl :-p

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] cljsfiddle.net

2013-09-29 Thread Jonas
Thanks! I added these two addons to the cljs editor and it's a huge 
improvement IMHO.

Jonas

On Saturday, September 28, 2013 9:41:52 PM UTC+3, Ian Bishop wrote:

 These are pretty great for writing Clojure in CodeMirror:

 http://codemirror.net//addon/edit/matchbrackets.js
 http://codemirror.net//addon/edit/closebrackets.js

 On Saturday, 28 September 2013 14:27:28 UTC-3, David Nolen wrote:

 Just gave it a spin http://cljsfiddle.net/fiddle/swannodette.test-logic

 Great work. Is there anyway to turn on parentheses matching on in 
 CodeMirror? Even better if Code Mirror can highlight unbalanced parens.

 (Using it also makes me realize that ClojureScript should really provide 
 a way to collect warnings as data )

 David


 On Sat, Sep 28, 2013 at 6:24 AM, Jonas jonas@gmail.com wrote:

 Hi

 I’m working on a ClojureScript playground application (
 http://cljsfiddle.net) similar to jsfiddle[1], jsbin[2] etc. The app 
 has now reached a point where I’m happy to show it to a wider audience.

 I’m hoping cljsfiddle.net will be used for:
 * Personal/collaborative experiments
 * ClojureScript Demos
 * Teaching Clojure(Script)
 * Single page (client only) web apps (such as games)
 * etc.

 A short list of (current) features:
 * Write and run ClojureScript programs without leaving your browser.
 * Save your work for later or share with the rest of the ClojureScript 
 community.
 * Use popular cljs libraries by ‘require’ them in your ns declaration.
 - Currently available: domina, dommy, hiccups, core.match, core.logic
 * core.async is available but will probably not work yet. I’ll be 
 working on this.
 * You can also require namespaces you (or someone else) previously 
 wrote. This means you can develop utility libraries specifically designed 
 to be used on cljsfiddle.net. (Example: [3])
 * Link to a specific namespace showing only the final html result of 
 your work (great for demo purposes and other pure-client apps). (Example: 
 [4])

 I’m quite happy with how the site works and I’m looking forward to your 
 feedback. If you find any bugs or other problems please file a bug report 
 on github[5]. Also, any help with the UI design would be most appreciated 
 as I think it can be substantially improved.

 The very first time you run a program on cljsfiddle it will take a while 
 to compile and load all the dependencies, subsequent runs should be much 
 faster thanks to HTTP caching. Once the deps are cached the 
 edit/compile/run cycle should be very fast. 

 I’ve tested the site on chrome and firefox. It will currently not work 
 with firefox version 24 or older, so if you’re a firefox user you must 
 upgrade to firefox 25.

 Happy Hacking, 
 Jonas

 [1] http://jsfiddle.net/
 [2] http://jsbin.com/
 [3] http://cljsfiddle.net/fiddle/jonase.bezier
 [4] http://cljsfiddle.net/view/jonase.snake
 [5] http://github.com/jonase/cljsfiddle

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google 
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[ANN] cljsfiddle.net

2013-09-28 Thread Jonas
Hi

I’m working on a ClojureScript playground application 
(http://cljsfiddle.net) similar to jsfiddle[1], jsbin[2] etc. The app has 
now reached a point where I’m happy to show it to a wider audience.

I’m hoping cljsfiddle.net will be used for:
* Personal/collaborative experiments
* ClojureScript Demos
* Teaching Clojure(Script)
* Single page (client only) web apps (such as games)
* etc.

A short list of (current) features:
* Write and run ClojureScript programs without leaving your browser.
* Save your work for later or share with the rest of the ClojureScript 
community.
* Use popular cljs libraries by ‘require’ them in your ns declaration.
- Currently available: domina, dommy, hiccups, core.match, core.logic
* core.async is available but will probably not work yet. I’ll be working 
on this.
* You can also require namespaces you (or someone else) previously wrote. 
This means you can develop utility libraries specifically designed to be 
used on cljsfiddle.net. (Example: [3])
* Link to a specific namespace showing only the final html result of your 
work (great for demo purposes and other pure-client apps). (Example: [4])

I’m quite happy with how the site works and I’m looking forward to your 
feedback. If you find any bugs or other problems please file a bug report 
on github[5]. Also, any help with the UI design would be most appreciated 
as I think it can be substantially improved.

The very first time you run a program on cljsfiddle it will take a while to 
compile and load all the dependencies, subsequent runs should be much 
faster thanks to HTTP caching. Once the deps are cached the 
edit/compile/run cycle should be very fast. 

I’ve tested the site on chrome and firefox. It will currently not work with 
firefox version 24 or older, so if you’re a firefox user you must upgrade 
to firefox 25.

Happy Hacking, 
Jonas

[1] http://jsfiddle.net/
[2] http://jsbin.com/
[3] http://cljsfiddle.net/fiddle/jonase.bezier
[4] http://cljsfiddle.net/view/jonase.snake
[5] http://github.com/jonase/cljsfiddle

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [ANN] cljsfiddle.net

2013-09-28 Thread Jonas
Hi

I updated the clojurescript version and core.async seems to work fine 
now: http://cljsfiddle.net/fiddle/jonase.async

Jonas


On Saturday, September 28, 2013 7:31:55 PM UTC+3, David Nolen wrote:

 Wow, awesome. Yes to core.async support, there was a release yesterday 
 with new goodies for Clojure and ClojureScript.

 David


 On Sat, Sep 28, 2013 at 6:24 AM, Jonas jonas@gmail.com 
 javascript:wrote:

 Hi

 I’m working on a ClojureScript playground application (
 http://cljsfiddle.net) similar to jsfiddle[1], jsbin[2] etc. The app has 
 now reached a point where I’m happy to show it to a wider audience.

 I’m hoping cljsfiddle.net will be used for:
 * Personal/collaborative experiments
 * ClojureScript Demos
 * Teaching Clojure(Script)
 * Single page (client only) web apps (such as games)
 * etc.

 A short list of (current) features:
 * Write and run ClojureScript programs without leaving your browser.
 * Save your work for later or share with the rest of the ClojureScript 
 community.
 * Use popular cljs libraries by ‘require’ them in your ns declaration.
 - Currently available: domina, dommy, hiccups, core.match, core.logic
 * core.async is available but will probably not work yet. I’ll be working 
 on this.
 * You can also require namespaces you (or someone else) previously wrote. 
 This means you can develop utility libraries specifically designed to be 
 used on cljsfiddle.net. (Example: [3])
 * Link to a specific namespace showing only the final html result of your 
 work (great for demo purposes and other pure-client apps). (Example: [4])

 I’m quite happy with how the site works and I’m looking forward to your 
 feedback. If you find any bugs or other problems please file a bug report 
 on github[5]. Also, any help with the UI design would be most appreciated 
 as I think it can be substantially improved.

 The very first time you run a program on cljsfiddle it will take a while 
 to compile and load all the dependencies, subsequent runs should be much 
 faster thanks to HTTP caching. Once the deps are cached the 
 edit/compile/run cycle should be very fast. 

 I’ve tested the site on chrome and firefox. It will currently not work 
 with firefox version 24 or older, so if you’re a firefox user you must 
 upgrade to firefox 25.

 Happy Hacking, 
 Jonas

 [1] http://jsfiddle.net/
 [2] http://jsbin.com/
 [3] http://cljsfiddle.net/fiddle/jonase.bezier
 [4] http://cljsfiddle.net/view/jonase.snake
 [5] http://github.com/jonase/cljsfiddle

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: communicating quits to timeouts AND parent loop in core.async

2013-07-17 Thread Jonas
You can also use the alt! macro:

(let [stop (chan)]
  (go (loop []
(println Hello World!)
(alt!
 (timeout 1000) (do (println I'm done sleeping...)
(recur))
 stop :ok)))
  (!! (timeout 1))
  (!! stop :now)
  (println We're done.))


On Wednesday, July 17, 2013 10:31:50 PM UTC+3, David Nolen wrote:

 Why not the following?

 (let [stop (chan)]
   (go (loop []
 (println Hello World!)
 (let [[v c]] (alts! [(timeout 1) stop])]
   (if (= c stop)
 :done
 (do (println I'm done sleeping, going to recur now...)
   (recur)))


 On Wed, Jul 17, 2013 at 2:47 PM, Ben Mabey b...@benmabey.comjavascript:
  wrote:

 Hi all,
 In a number of places where I'm trying core.async I have run across the 
 pattern of having a loop inside a go block with some timeouts in the loop 
 body.  Contrived example:

 (go
  (while true
(println Hello World!)
(! (timeout 1))
(println I'm done sleeping, going to recur now...)))

 In situations like these I almost always want to be able to stop the loop 
 and prematurely stop the timeouts.  Using alt! we can easily handle the 
 need of stopping the timeout.  Stopping the overall loop is easy as well 
 but I can't seem to do it without the use of an atom.  Here are some macros 
 I've come up with using a channel, an atom, and an additional go block:
 https://gist.github.com/**bmabey/6023231https://gist.github.com/bmabey/6023231

 Is there a better way to do this that doesn't involve an atom? If we had 
 a `closed?` fn for channels one could write:

 (let [stop (chan)]
   (go
(while (not (closed? stop))
  (println Hello World!)
  (alts! [(timeout 1) stop])
  (println I'm done sleeping, going to recur now...)))
   stop)

 This seems ideal and a good use case for adding some sort of function to 
 detect termination.  Thoughts?

 Thanks,
 Ben

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@**googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en
 --- You received this message because you are subscribed to the Google 
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@**googlegroups.com javascript:.
 For more options, visit 
 https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
 .





-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: GSOC Algebraic Expressions

2013-05-30 Thread Jonas
This is a very interesting project. I look forward to following its 
development.

I did a presentation[1] on the implementation of the kibit[2] rule system a 
few weeks ago which you might find interesting since it's using core.logic 
as well.

[1] http://jonase.github.io/kibit-demo/http://jonase.github.io/kibit-demo/#1
[2] https://github.com/jonase/kibit

Jonas

On Wednesday, May 29, 2013 6:10:52 PM UTC+3, Maik Schünemann wrote:

 Hello,
 I am glad to announce that my proposal got accepted for google summer of 
 code.
 I am doing the algebraic expression project idea which could lay the 
 foundation for a clojure CAS System by providing a library to manipulate 
 expressions syntactically
 and also solving equations and optimizing them for evaluation on top of 
 core.matrix.

 I have created a blog post in which I explained it in more detail and also 
 the design decisions I have to make in the beginning, such as how to 
 represent an expression,
 a rule, how to deal with core.logic ...
 http://kimavcrp.blogspot.de/201blog 
 post3/05/gsoc-project-algebraic-expressions-pre.htmlhttp://kimavcrp.blogspot.de/2013/05/gsoc-project-algebraic-expressions-pre.html

 Please comment if you have feedback or feature request or have a concrete 
 use case for what you would want to use it. The more feedback I get the 
 better I can make the
 library. 




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] Termito - a term rewriting library

2013-03-17 Thread Jonas
Hi

I'm happy to announce the first release of termito[1]. Termito is a term 
rewriting library inspired by the kibit rule system. With termito you can 
write declarative term rewriting rules like 

(defrules zero-rules
  [(* 0 ?x) 0])

(defrules identity-rules
  [(* 1 ?x) ?x]
  [(+ 0 ?x) ?x])

(def rules (concat zero-rules identity-rules)

and ask the library to simplify expressions for you:

(simplify '(+ (* 0 x) (* 1 y) rules)
;; = y

Feedback, usage and bug reports welcome!

Jonas

[1] https://github.com/jonase/termito

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: datomic question

2013-03-03 Thread Jonas
Hi

You can use the tempid 
(http://docs.datomic.com/clojure/index.html#datomic.api/tempid) function to 
generate new temporary ids.

Jonas

On Monday, March 4, 2013 8:50:56 AM UTC+2, edw...@kenworthy.info wrote:

 Okay, I think I understand that.

 Does that mean this code could never work as intended in a Clojure 
 program, only at the repl (which seems a bit of a limitation) or is there a 
 way to make it work as intended, generating a different id each time? Or is 
 the whole approach taken in this code flawed?

 On Sunday, 3 March 2013 21:59:45 UTC, Michał Marczyk wrote:

 #db/id ... is a tagged literal. It gets read in as an id object with 
 some integer inside. The way this happens is that the reader looks up 
 a data reader function associated with the symbol db/id in the map 
 held by the var *data-readers* and passes to it the result of parsing 
 the rest of the literal (a vector holding the keyword :db.part/db in 
 this case). Importantly, this function is not pure and the integer it 
 uses will be different on each invocation. (Given this form of the 
 #db/id literal; you can also specify a particular number yourself -- 
 #db/id [:db.part/db some-number-here].) 

 In any case, once the reader reads in your code including some 
 particular id, the compiler will compile the result preserving the 
 particular values it sees, so it will embed code to construct *exactly 
 this* id in the compiled output. Thus you end up with a particular id 
 hardwired into the first version of your function. 

 With the second version, if you invoke it multiple times at the REPL, 
 you ask the reader for a new id at each invocation, so it works as you 
 expect. If instead you were to use it inside a function like so: 

 (defn foo [] 
   (make-column-schema #db/id [:db.part/db] :results/subject 
 :db.type/string)), 

 then again the same id would be used for every (foo) call. 

 Cheers, 
 Michał 


 On 3 March 2013 21:58,  edw...@kenworthy.info wrote: 
  So, I am studying a piece of code from the web. I've dissected most of 
 it 
  and am in the process of re-factoring it. 
  
  What I don't understand is why one version works and the other doesn't. 
  
  So for both: 
  
  (ns gcse-results.core (:use [datomic.api :only [q db] :as d]) (:use 
  quil.core)) 
  
  This doesn't work: 
  
  (defn make-column-schema [db-ident db-type] 
  {:db/id #db/id[:db.part/db] 
  :db/ident db-ident 
  :db/valueType db-type 
  :db/cardinality :db.cardinality/one 
  :db.install/_attribute :db.part/db}) 
  
  Each call to: 
  
  (make-column-schema :results/subject :db.type/string) 
  
  The value of #db/id[:db.part/db] is the same. 
  
  And this works: 
  
  (defn make-column-schema [db-id db-ident db-type] 
  {:db/id db-id 
  :db/ident db-ident 
  :db/valueType db-type 
  :db/cardinality :db.cardinality/one 
  :db.install/_attribute :db.part/db}) 
  
  Each call to: (make-column-schema #db/id[:db.part/db] :results/subject 
  :db.type/string) 
  
  The value of #db/id[:db.part/db] is the different, as expected. 
  
  Now I thought that I understood #db/id[:db.part/db] (call to a Java 
  constructor) but obviously my understanding is flawed as I would expect 
 both 
  of these functions to produce the same thing, but they don't so there's 
  obviously some gap in my understanding. 
  
  Help? 
  
  -- 
  -- 
  You received this message because you are subscribed to the Google 
  Groups Clojure group. 
  To post to this group, send email to clo...@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+u...@googlegroups.com 
  For more options, visit this group at 
  http://groups.google.com/group/clojure?hl=en 
  --- 
  You received this message because you are subscribed to the Google 
 Groups 
  Clojure group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to clojure+u...@googlegroups.com. 
  For more options, visit https://groups.google.com/groups/opt_out. 
  
  



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [ANN] analyze 0.3.0 - Hygienic transformation

2013-02-14 Thread Jonas


On Friday, February 15, 2013 6:19:00 AM UTC+2, ronen wrote:


 It looks as if https://github.com/jonase/kibit/ is a lint/check style 
 tool that only reads the source code, this limits its utilization:

 Kibit 
 readshttp://clojure.github.com/clojure/clojure.core-api.html#clojure.core/read
  source 
 code without any macro expansion or evaluation. A macro can therefor easily 
 invalidate a rule. Also, kibit will not know if the symbol + in the form (+ 
 x 1) actually refers to a local or to a function in a namespace other 
 than clojure.core. Expect some false positives.

 So there is a place for an AST based one (more similar to findbugs I guess)


If someone is interested in this https://github.com/jonase/eastwood might 
be a good starting point.
 


 On Wednesday, February 13, 2013 9:21:52 AM UTC+2, Ambrose 
 Bonnaire-Sergeant wrote:

 IMO that's the job of a linter-style tool, which can be written easily 
 with `analyze`.

 On Tue, Feb 12, 2013 at 11:58 PM, Michael Wood esio...@gmail.com wrote:

 It might be useful, though, to be able to enable warnings for shadowed
 variables.

 On 12 February 2013 17:38, Timothy Baldridge tbald...@gmail.com wrote:
  This sort of pattern is used quite a lot in clojure (even in core):
 
  (let [data (if (string? data) (read-string data) data)
data (if (string? (first data)) (first data) (next data))
data (if (string? (first data)) (first data) (next data))]
   data)
 
  Throwing exceptions on overridden variable names would not only break
  Clojure code, but also is very non-lispy.
 
  Timothy
 
 
 
  On Tue, Feb 12, 2013 at 6:31 AM, AtKaaZ atk...@gmail.com wrote:
 
  it makes sense to not throw now that I think about it, when using _
  instead of a
  I'm also thinking of cases like:
  = (let [a 1]
   (let [b 2 a 3]
 (println a b)))
  3 2
  nil
 
  is there something that would let me know I'm overwriting a ? I 
 figure
  if something like this would slip by would be tough to track down
 
 
  On Tue, Feb 12, 2013 at 1:46 PM, Michael Wood esio...@gmail.com 
 wrote:
 
  On 12 February 2013 12:28, AtKaaZ atk...@gmail.com wrote:
   what would this do:
  
   (let [a 1, a 2] a)
   becomes:
   (let [a 1, a123 2] a)
   or
   (let [a 1, a123 2] a123)
   or
   exception[I prefer]
 
  It would be the second option, i.e.:
 
  (let [a 1, a123 2] a123)
 
  The original code is valid, so it would not throw an exception.
 
   On Tue, Feb 12, 2013 at 7:10 AM, Ambrose Bonnaire-Sergeant
   abonnair...@gmail.com wrote:
  
   Processing a hygienic AST relieves the burden of worrying about
   shadowing
   of locals.
  
   Wherever a binding would normally be shadowed, it is instead 
 renamed
   to a
   local binding currently not in scope.
  
   eg. (let [a 1, a a] a)
  
   becomes
  
   (let [a 1, a123 a] a123)
  
   It can be useful for those processing Clojure's analysis results.
  
   Thanks,
   Ambrose
  
  
   On Tue, Feb 12, 2013 at 1:54 AM, kovas boguta 
 kovas@gmail.com
   wrote:
  
   What is a hygienic AST?
  
   Thanks
   k
  
  
   On Sun, Feb 10, 2013 at 10:45 PM, Ambrose Bonnaire-Sergeant
   abonnair...@gmail.com wrote:
Hi everyone,
   
Happy to release analyze 0.3.0 with new hygienic code
transformation
capabilities.
   
[analyze 0.3.0]
   
In a line:
   
analyze.hygienic= (- (ast (let [a 1 a a b a a a] a)) ast-hy
emit-hy)
((fn* ([] (let* [a 1 a2921 a b a2921 a2922 a2921] a2922
   
Hygienic AST's have enabled large performance boosts in 
 core.typed.
I'm
excited to see how it could
be as useful to others.
   
Note: hygienic AST's (those transformed with
`analyze.hygienic/ast-hy` can
be printed normally with `analyze.emit-form/emit-form`, and
hygienically
with `analyze.hygienic/emit-hy`.
   
https://github.com/frenchy64/analyze
   
Thanks,
Ambrose
   
--
--
You received this message because you are subscribed to the 
 Google
Groups Clojure group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the 
 Google
Groups
Clojure group.
To unsubscribe from this group and stop receiving emails from 
 it,
send
an
email to clojure+u...@googlegroups.com.
For more options, visit 
 https://groups.google.com/groups/opt_out.
   
   
  
   --
   --
   You received this message because you are subscribed to the 
 Google
   Groups Clojure group.
   To post to this group, send email to clo...@googlegroups.com
   Note that posts from new members are moderated - please be 
 patient
   with
   your first post.
   To unsubscribe from this group, send email to
   

Re: [ClojureScript] Please test CLJS-418, fixing browser REPL

2013-02-09 Thread Jonas Enlund
On Thursday, February 7, 2013 7:11:35 PM UTC+2, David Nolen wrote:
 http://dev.clojure.org/jira/browse/CLJS-418
 
 
 
 Some of you may have encountered bizarre problems when trying to use browser 
 REPL with the latest releases of ClojureScript. This ticket contains a patch 
 that should resolve the issue but we need people to test.
 
 
 
 Thanks,
 David

Hi

I tested this with the following approach and got the repl to work without 
issues:

* I modified cljsbuild[1] to use [org.clojure/google-closure-library 
0.0-2029-2] instead of [org.clojure/google-closure-library-third-party 
0.0-2029].
* AFAIK google-closure-library 0.0-2029-2 will be used by clojurescript in a 
new release so the above change (should) confirm that the transitive dependency 
on google-closure-library-third-party is indeed working as expected.

I also tried to test the browser repl without cljsbuild but script/bootstrap 
pulls in different closure-library deps than are specified in the pom.xml. The 
browser repl works without cljsbuild out of the box. 

If more testing concerning this issue is required please tell me because I'd 
like to see a new clojurescript release soon.

Jonas

[1] https://github.com/emezeske/lein-cljsbuild/blob/master/support/project.clj

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] nrepl-transcript

2013-01-14 Thread Jonas
Hi

I created a middleware for nrepl that saves a transcript of your repl 
interactions so you can go back and see what you did. 

https://github.com/jonase/nrepl-transcript

Feedback welcome!

Jonas

-- 
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: what is js/ in clojurescript?

2013-01-12 Thread Jonas
Hi

I created an issue+patch on 
JIRA: http://dev.clojure.org/jira/browse/CLJS-455

Jonas

On Monday, January 7, 2013 3:58:25 PM UTC+2, Peter Taoussanis wrote:

 Thanks David.

 Ticket  patch welcome.


 I've been lazy / holding out for the electronic CA, but I'll make a note 
 to come back to this if no one else steps up.

 Cheers!



-- 
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: Tail call in multi method?

2012-12-17 Thread Jonas
recur doesn't work well with multimethods:

(defmulti foo identity)
 
(defmethod foo 1 [n]
  (recur (dec n)))
 
(defmethod foo 0 [n]
  :ok)
 
(foo 1) ;; runs forever

Jonas

On Monday, December 17, 2012 6:56:34 PM UTC+2, juan.facorro wrote:

 What about recur http://clojure.org/special_forms#recur? 

 It's a special form used for tail call optimizations.

 Juan

 On Monday, December 17, 2012 1:32:31 PM UTC-3, bruce li wrote:

 Hello, everyone.

 I'm currently trying to model an automata using multi-method. So in my 
 code, I have something like:

 (defmethod trans :state
  [state]
  ; ...
  (trans ..

 In the last line, the trans will be called with some different state.

 However, it seems that such call still consumes stack and I quickly come 
 to a stack overflow error when the states are reached multiple times.

 I'm wondering if there is some ways to optimize the code.

 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: math expression simplifier, kibit implementation

2012-12-02 Thread Jonas


On Sunday, December 2, 2012 7:33:17 PM UTC+2, David Nolen wrote:

 On Sat, Dec 1, 2012 at 12:24 AM, Jonas jonas@gmail.com 
 javascript:wrote:


 * Predicates on logic vars: 
 [(foo (? x number?)) (bar ?x)] = match (foo 42) but not (foo :bar)


 This is now possible since we have constraints.


Awesome. Is this already in a released version of core.logic? Do you know 
of any examples I might study?
 

  

 * Segment vars:
 [(* ??x 1 ??y) (* ??x ??y)] = (* 4 3 2 1 2 3 4) would turn into (* 4 
 3 2 2 3 4)
 and
 [(* ??x 0 ??y) 0] = (* 1 2 3 0 4 5 6 7) would turn into 0


 This has been possible for some time - but you need to extend unification. 
 You need to create a wrapper around sequences and a new kind of logic var. 
 Kevin's work on the partial map (PMap) functionality is a good starting 
 point as well the work I've done on constrained vars (CVar).


I'd be interested in creating an SVar (segment var) then. I'll start by 
trying to understand yours and Kevins work on CVar/PMap.
   


 As far as doing a computer algebra system, I know things like this have 
 been done before in Prolog so I don't see why not.


Sorry, I didn't mean to imply that it couldn't be done in core.logic, only 
that the kibit rule system isn't as expressive as I'd like it to be.

Jonas

 


 David




-- 
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: math expression simplifier, kibit implementation

2012-11-30 Thread Jonas
Hi 

The function `simplify-one` in kibit.core is the “brain” behind kibit:

(defn simplify-one [expr rules]
  (let [alts (logic/run* [q]
(logic/fresh [pat subst]
  (logic/membero [pat subst] rules)
  (logic/project [pat subst]
(logic/all (pat expr)
 (subst q)]
(if (empty? alts) expr (first alts

The line `(logic/membero [pat subst] rules)` picks a rule (both the pattern 
and the substitution part). Both `pat` and `subst` are functions who have 
closed over the same logic vars. pat takes a form and subst takes the logic 
var representing the result as arguments. Since both pat and subst contain 
the same logic vars the final expression `(logic/all (pat expr) (subst q))` 
will only succeed if (pat expr) succeeds. If (pat expr) succeeds it has 
presumably bound its logic vars and since the same vars are closed over in 
subst, the final answer is unified with q, giving us a result. 

Rules are compiled with

(defn compile-rule [rule]
  (let [[pat alt] (logic/prep rule)]
[(fn [expr] (logic/== expr pat))
 (fn [sbst] (logic/== sbst alt))]))

(logic/prep rule) walks the rule (where a rule is e.g., [(+ ?x 1) (inc 
?x)]) and replaces symbols starting with `?` with logic vars. The 
compile-rule function is defined in the kibit.rules.util namespace.

This is basically how the kibit rule system works. I don’t think it’s 
powerful enough to create a full-blown computer algebra system and often 
It’s not powerful enough for the kind of rules I’d like to express in 
kibit. Two enhancements I’d like to add are

* Predicates on logic vars: 
[(foo (? x number?)) (bar ?x)] = match (foo 42) but not (foo :bar)
* Segment vars:
[(* ??x 1 ??y) (* ??x ??y)] = (* 4 3 2 1 2 3 4) would turn into (* 4 3 
2 2 3 4)
and
[(* ??x 0 ??y) 0] = (* 1 2 3 0 4 5 6 7) would turn into 0

David Nolen and Kevin Lynagh has discussed enhancements to the core.logic 
unifier on IRC lately. I haven’t been able to follow along as much as I’d 
like so I’m not completely sure what enhancements they are aiming for. You 
can see some of the results of those discussions in many of Kevins gists on 
github (https://gist.github.com/lynaghk)

Cheers,
Jonas 

On Saturday, December 1, 2012 12:08:16 AM UTC+2, Brent Millare wrote:

 Hey all,

 Before I diving in detail into the code, can someone provide me a high 
 level explanation of how kibit simplifies code? I understand underneath it 
 uses core.logic and rules but its not clear to me how it picks one form 
 over the other.

 I'm trying to extend this to data that represents mathematical 
 expressions. Ideally in the future I'd like to have many types of 
 transformations that enable one to shape a mathematical expression in one 
 way or another depending on the  user's requirements.

 My current work (which requires dj atm since its under heavy development) 
 is available here

 https://github.com/bmillare/dj.math



-- 
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: [Ann] Kibit 0.0.6

2012-11-12 Thread Jonas
Hi

I didn't know that `vec` fails with reducers. I'll probably remove the 
`into` rules. I have written about some known limitations of kibit here: 
https://github.com/jonase/kibit#known-limitations . Knowing what a symbol 
refers to is very difficult (especially in the presence of macros). I 
haven't got a good solution for this problem yet. I'm also interested in 
enhancing the codeq clojure analyzer and the exact same problem arises 
there. We had quite an interesting discussion on the IRC channel a few 
weeks ago (at http://clojure-log.n01se.net/date/2012-11-04.html#13:57) so 
any ideas in this area would be most appreciated!

Jonas

On Monday, November 12, 2012 4:20:58 PM UTC+2, Jim foo.bar wrote:

  Thank you Bronza...this is exactly what I meant! when using reducers 
 'into' is the norm isn't it? 
 Couldn't kibit parse the ns declaration before it starts suggesting 
 things? It seems that at least for namespaces that use core.logic or 
 reducers kibit's suggestions will break your code! For example it keeps 
 suggesting (zero? x) instead of (= x 0) even though in a logic program '=' 
  '==' do not mean the same thing as in other namespaces...

 the same with 'into'. You cannot use vec with reducers as Bronza 
 demonstrated!
 In general, I think kibit should check the ns declaration for symbols that 
 have been redefined like =, == ,  etc etc..This way it can resist making 
 suggestions about these redefined symbols...Would that be too hard to 
 implement?

 Jim

 On 12/11/12 13:28, Bronsa wrote:
  
 it is not always true that using vec is equal to using into []

 user= (require '[clojure.core.reducers :as r])
 nil
 user= (r/map inc (range 2))
 #reducers$folder$reify__407 
 clojure.core.reducers$folder$reify__407@1358d955
 user= (into [] *1)
 [1 2]
 user= (vec *2)
 RuntimeException Unable to convert: class 
 clojure.core.reducers$folder$reify__407 to Object[]� 
 clojure.lang.Util.runtimeException (Util.java:170)


 2012/11/12 Andreas Liljeqvist bon...@gmail.com javascript:

 I would prefer the use of vec. 

  If I am using an empty 'to' then I would always replace it with the 
 type constructor.
 Feels more clean to me.
 You aren't logically taking an empty vector and filling it with stuff, 
 you are converting your original coll.�
  
 On Sun, Nov 11, 2012 at 5:04 PM, Jim - FooBar(); 
 jimpi...@gmail.comjavascript:
  wrote:

 Kibit is probably looking for syntactic patterns not for types or 
 anything like that... but still, why is it suggesting this?

 Jim 



 On 11/11/12 15:58, Jim - FooBar(); wrote:

 Kibit says:

 Consider using:
 � (vec (:children (game-tree dir b next-level)))
 instead of:
 � (into [] (:children (game-tree dir b next-level)))

 why is that?
 Does it make a difference if '(:children (game-tree dir b next-level))' 
 returns a reducer?

 Jim



 On 11/11/12 15:08, Jonas wrote:

 Hi

 Today I released version 0.0.6 of Kibit[1].

 Kibit is a simple code analysis tool. The purpose of the tool is to 
 tell its users that Hey, There's already a function for that!. Kibit 
 uses 
 core.logic[2] �to search for patterns of code
 which can be simplified. For example, if the analyzer finds `(apply 
 concat (apply map ...)` It will notify its user about the availability of 
 `mapcat`.

 For this release I have split the leiningen plugin part of kibit of 
 into it�s own project (lein-kibit[3]). This was done in order for kibit 
 to be able to read tagged literals (using the Clojure 1.5 
 `*default-data-reader-fn*` var).

 This release also includes several new rules contributed by the 
 community -- Many thanks!

 I hope you enjoy Kibit

 Jonas

 [1] https://github.com/jonase/kibit
 [2] https://github.com/clojure/core.logic
 [3] https://github.com/jonase/lein-kibit
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient 
 with your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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 clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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 clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript

[Ann] Kibit 0.0.6

2012-11-11 Thread Jonas
Hi

Today I released version 0.0.6 of Kibit[1].

Kibit is a simple code analysis tool. The purpose of the tool is to tell 
its users that Hey, There's already a function for that!. Kibit uses 
core.logic[2]  to search for patterns of code
which can be simplified. For example, if the analyzer finds `(apply concat 
(apply map ...)` It will notify its user about the availability of `mapcat`.

For this release I have split the leiningen plugin part of kibit of into 
it’s own project (lein-kibit[3]). This was done in order for kibit to be 
able to read tagged literals (using the Clojure 1.5 
`*default-data-reader-fn*` var).

This release also includes several new rules contributed by the community 
-- Many thanks! 

I hope you enjoy Kibit

Jonas

[1] https://github.com/jonase/kibit
[2] https://github.com/clojure/core.logic
[3] https://github.com/jonase/lein-kibit

-- 
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: Building School Seating Charts in Clojure and ClojureScript: Part 1

2012-08-29 Thread Jonas


On Wednesday, August 29, 2012 8:29:05 PM UTC+3, Evan Mezeske wrote:

 On Wednesday, August 29, 2012 6:10:59 AM UTC-7, Stathis Sideris wrote:

 Nice post, thanks. Did you write the the geometry utilities yourself?


 Yeah, I did.  That code is pretty application-specific.  It covers things 
 like if a lab-bench desk with two chairs is rotated, where do the seats 
 end up and basic stuff like that.  So, it's nothing too fancy, although it 
 was a little tricky to get it right (which made sharing it all the better).


Great post! I'm already looking forward to the next post,

I've got a similar project starting where I need to move/rotate/drag/drop 
graphical objects so I was wondering if you built your app on SVG, Canvas 
or something else? I'm leaning towards SVG (maybe via the Raphael.js 
library) but I'd love to know what path you took!

Jonas

-- 
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: What is the meaning of :while in a for ?

2012-08-21 Thread Jonas
Both `:when` and `:while` tests if an element should be used when building 
the resulting sequence. If the `:when` part evaluates to false (or nil) the 
element is skipped and the list comprehension continues with the next 
element in the source sequence. `:while` on the other hand ends the list 
comprehension when the test evaluates to false (or nil) and returns the 
sequence generated thus far.

Note the difference between

  (for [x [2 4 6 7 8] :when (even? x)] x) ; = (2 4 6 8)

and

  (for [x [2 4 6 7 8] :while (even? x)] x) ; = (2 4 6)

Hope that helps.

Jonas

On Tuesday, August 21, 2012 1:28:50 PM UTC+3, Nicolas Oury wrote:

 Dear all, 

 What is the meaning of :while in a for? 
 I understand :when, and also that :while jumps more element when the 
 condition is not met, 
 but where does it jump to exactly? 

 Best regards, 

 Nicolas. 


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What is the meaning of :while in a for ?

2012-08-21 Thread Jonas


On Tuesday, August 21, 2012 2:22:39 PM UTC+3, Tassilo Horn wrote:

 Jonas jonas@gmail.com javascript: writes: 

  `:while` on the other hand ends the list comprehension when the test 
  evaluates to false (or nil) and returns the sequence generated thus 
  far. 

 No, it's perfectly possible to have a comprehension with a :while that 
 generates more elements after :while evaluated to false.  :while skips 
 some bindings, but it doesn't need to skip all of them.  See my original 
 reply to Nicolas. 


Thanks for pointing that out. I realize now that my understanding of the 
`for` macro is not complete. I wonder if complex `for`-expressions hurt 
code readability or is the alternative (using map+filter) even more 
complicated?
 


 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

Re: Attractive examples of function-generating functions

2012-08-10 Thread Jonas
How about the new reducers library:

http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html
http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html

Jonas

On Wednesday, August 8, 2012 7:48:23 PM UTC+3, Brian Marick wrote:

 I'm looking for medium-scale examples of using function-generating 
 functions. I'm doing it because examples like this: 

 (def make-incrementer 
  (fn [increment] 
(fn [x] (+ increment x 

 ... or this: 

 (def incish (partial map + [100 200 300])) 

 ... show the mechanics, but I'm looking for examples that would resonate 
 more with an object-oriented programmer. Such examples might be ones that 
 close over a number of values (which looks more like an object), or 
 generate multiple functions that all close over a shared value (which looks 
 more like an object), or use closures to avoid the need to have some 
 particular argument passed from function to function (which looks like the 
 `this` in an instance method). 

 Note: please put the flamethrower down. I'm not saying that looking like 
 objects is the point of higher-order functions. 

 I'll give full credit. 

 - 
 Brian Marick, Artisanal Labrador 
 Contract programming in Ruby and Clojure 
 Occasional consulting on Agile 




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Scheme dotted pair equivalent in Clojure

2012-06-17 Thread Jonas
A very nice section of SICP[1] describes how cons/car/cdr can be built only 
with functions. Translated to Clojure it might look like

(defn cons [a b]
  #(condp = %
 :car a
 :cdr b))

(defn car [cons-cell]
  (cons-cell :car))

(defn cdr [cons-cell]
  (cons-cell :cdr))

(car (cons :a :b)) = :a
(cdr (cons 1 2)) = 2

An excellent example of closures and the use of higher order functions.

Pairs can also serve as nice example usage for defprotocol and reify:

(defprotocol Pair
  (car [cons-cell])
  (cdr [cons-cell]))

(defn cons [a b]
  (reify Pair
(car [_] a)
(cdr [_] b)))

(car (cons :a :b)) = :a
(cdr (cons 1 2)) = 2

[1]: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.3


On Saturday, June 16, 2012 6:35:14 PM UTC+3, octopusgrabbus wrote:

 I have a need to learn enough scheme to read it and write a few functions. 
 I came across dotted pair notation. I am trying to grok it in terms of the 
 only Lisp I know, Clojure. Does dotted pair notation in Scheme compare to  
 form in Clojure, and if so, how?




-- 
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: CRUD application backed only by immutable facts

2012-06-04 Thread Jonas


On Tuesday, June 5, 2012 3:59:39 AM UTC+3, Kevin Lynagh wrote:

 Has anyone seen or implemented a CRUD application in Clojure using a 
 database of immutable facts? 

 For instance, a traditional database table supporting a todo-list 
 application has columns 

 user_id, task_id, task_description, is_done 

 A new row is created when a user adds a task. 
 Then that row is updated so is_done = TRUE when the user checks the 
 task off. 

 With immutable facts this would instead be a collection of statements: 

 User U added task T with description D at time T1 
 User U completed task T at time T2 


I think this would be a great fit for datomic. Consider the following 
transaction:

[[;add entity :task/description Make coffee]
 [:add entity :task/deadline #inst ...]
 [:add entity :task/user user-entitiy]]

In order to mark this todo item as done simply retract the entity:

[[:retractEntity entity]]

In addition, the :task/user attribute could be of type :db.cardinality/many 
so many users would be assigned to the same task. I bet it would also be 
possible to make a todo-item depend on another todo item and ask smart 
(declarative) queries like What tasks has to be done before this task and 
who should do them?
 


 To get a list of unfinished tasks for a user, you'd need to grab all 
 the tasks from this transaction log, put them into a data structure, 
 and then remove ones when you learn that they've been completed. 
 Whatever is left over is the todo list. 

 Nathan Marz talked about this in terms of big data: 

 http://nathanmarz.com/blog/how-to-beat-the-cap-theorem.html 

 and Datomic's big bet is that your life as a developer gets much 
 easier when you just deal with (entity, attribute, value) + time. 

 I buy it in theory, but I have no idea what to expect in terms of 
 performance (e.g., how long would it take to find the current todo 
 list of someone who has added and completed/removed a few thousand 
 items?). 

 Has anyone implemented this idea on Clojure datastructures using, 
 say,  (timestamp, keyseq, value) and reducing a ton of calls to assoc- 
 in? 
 Aside from speed, what are some other tradeoffs of an immutable 
 approach?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: when function

2012-05-21 Thread Jonas


On Monday, May 21, 2012 6:54:28 PM UTC+3, Christian Guimaraes wrote:

 Hi all,

 I'm struggling with when code structures and my imperative mindset.

 What is the better approach (or functional approach) to work with a code 
 like the below?

 (defn parse-group [group-identifier line]
   (when (= group-identifier ID1)
 (handle-id1 line))
   (when (= group-identifier ID2)
 (handle-id2 line))
   (when (= group-identifier ID3)
 (handle-id3 line)))

 Thank you.
 -- christian




Hi

Maybe something like

(defn parse-group [group-identifier line]
  (condp = group-identifier
ID1 (handle-id1 line)
ID2 (handle-id2 line)
ID3 (handle-id3 line)))

or, if you want to leverage the fact that maps are functions:

(defn parse-group [group-identifier line]
  (({ID1 handle-id1
 ID2 handle-id2
 ID3 handle-id3} group-identifier) line))

but then you lose some readability IMO.

On Monday, May 21, 2012 6:54:28 PM UTC+3, Christian Guimaraes wrote:

 Hi all,

 I'm struggling with when code structures and my imperative mindset.

 What is the better approach (or functional approach) to work with a code 
 like the below?

 (defn parse-group [group-identifier line]
   (when (= group-identifier ID1)
 (handle-id1 line))
   (when (= group-identifier ID2)
 (handle-id2 line))
   (when (= group-identifier ID3)
 (handle-id3 line)))

 Thank you.
 -- christian




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Jonas


On Wednesday, May 2, 2012 7:24:04 AM UTC+3, Sean Neilan wrote:

 Hi,

 I'm sure this has been discussed to death but I can't figure it out. 

 I've got a file-seq sequence from
 (file-seq (java.io.File. /DirectoryWithMillionsOfFiles/)) that will 
 cause an out of memory error if realized.

 I want to call a function such as println on every element in the sequence.

 I understand that naming the sequence will cause it to be realized.

 The problems

1. I can't use map as in (map println (file-seq (java.io.File. 
/DirectoryWithMillionsOfFiles))). Map realizes the sequence.
2. I can't use for as in (for [x (files)] (println x)). For realizes 
the sequence.

 Try doseq instead:

(doseq [x (files)]
  (println x))
 


1. I can't use dorun because even though dorun doesn't realize the 
sequence, it can't execute a function on every element.
2. I can't use loop recur because it also realizes the sequence: (loop 
[a (files) b (first a)] (println b) (recur (rest a) (first a))) 
3. I can't use refs because even though they provide state, they can't 
save the state of the sequence without realizing the sequence.

 My question
 *Should I try the new stream library?*
 *
 *
 Thank you for your time.

 -Sean



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

[ANN] Eastwood - A Clojure lint tool

2012-04-19 Thread Jonas
Eastwood[1] is a Clojure lint tool which uses the analyze[2] library to 
inspect
namespaces and report possible problems. Currently it should work
with projects running Clojure 1.3.0 and newer.

Currently eastwood warns when it finds 
- deprecated java instance methods, static fields, static methods and 
constructors
- deprecated clojure vars
- unused function arguments
- unused private vars
- reflection
- naked (:use ...)
- misplaced docstrings
- keyword typos

I appreciate bug reports and feature requests and I also hope you find it 
useful!

Jonas

[1] https://github.com/jonase/eastwood
[2] https://github.com/frenchy64/analyze

-- 
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: [ANN] Eastwood - A Clojure lint tool

2012-04-19 Thread Jonas


On Thursday, April 19, 2012 4:24:16 PM UTC+3, Ambrose Bonnaire-Sergeant 
wrote:

 Did I do something wrong?


Sorry, I only tested in with lein2. I'll try to make it work with both in 
the next release.
 

-- 
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: [ANN] Eastwood - A Clojure lint tool

2012-04-19 Thread Jonas
I released 0.0.2 to clojars. It should now (hopefully) be possible to use 
eastwood with lein1. Note that eastwood will only work with projects that 
use Clojure version 1.3 and newer. This means that if you want to lint for 
example a leiningen plugin project you better use lein2 because lein1 runs 
on Clojure 1.2.1.

On Thursday, April 19, 2012 4:30:19 PM UTC+3, Jonas wrote:



 On Thursday, April 19, 2012 4:24:16 PM UTC+3, Ambrose Bonnaire-Sergeant 
 wrote:

 Did I do something wrong?


 Sorry, I only tested in with lein2. I'll try to make it work with both in 
 the next release.
  


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

[ANN] kibit 0.0.3

2012-04-01 Thread Jonas
I'm happy to announce the release of kibit[1] version 0.0.3. New in this 
release include:

* much better reporting
* a more advanced rule system
* more rules
* bug fixes

Thanks to all who have contributed!

Jonas

[1] https://github.com/jonase/kibit

-- 
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: Compilable clojure program, but unreadable?

2012-03-11 Thread Jonas
Hi,

Is this inconsistent behaviour:

user= `s/foo
s/foo
user= ::s/foo
#RuntimeException java.lang.RuntimeException: Invalid token: ::s/foo
nil
user= (require '[clojure.string :as s])
nil
user= `s/foo
clojure.string/foo
user= ::s/foo
:clojure.string/foo

I think that ::s/foo should be resolved to :s/foo if there is no alias for 
s (like symbols).

Jonas


On Monday, March 12, 2012 1:50:50 AM UTC+2, Meikel Brandmeyer (kotarak) 
wrote:

 Hi,

 Am 12.03.2012 um 00:09 schrieb Stuart Sierra:

  The syntax ::s/kwd is incorrect syntax: it should be either ::kwd (which 
 will resolve in the current namespace) or :s/kwd (only one colon).

 The reader page says, with :: they are resolved in the current namespace. 
 And this seems to work since they where introduced:

 user= (require '[clojure.string :as s])
 nil
 user= ::s/join
 :clojure.string/join
 user= `s/join
 clojure.string/join

 Just as s/join gets resolved to the clojure.string/join, ::s/join gets 
 resolved to :clojure.string/join. Sounds consistent and not in violation of 
 the reader page.

 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

Compilable clojure program, but unreadable?

2012-03-10 Thread Jonas
Hi

If I have the following short Clojure program:

;; unread.clj
(require '[clojure.string :as s])
(prn ::s/kwd)

The second form can't be read by the clojure reader:

user= (def reader (java.io.PushbackReader. (clojure.java.io/reader 
unread.clj)))
#'user/reader
user= (read reader)
(require (quote [clojure.string :as s]))
user= (read reader)
java.lang.Exception: Invalid token: ::s/kwd (NO_SOURCE_FILE:0)

But if I load the file, prior to reading it, it works fine:

user= (load-file unread.clj)
:clojure.string/kwd
nil
user= (def reader (java.io.PushbackReader. (clojure.java.io/reader 
unread.clj)))
#'user/reader
user= (read reader)
(require (quote [clojure.string :as s]))
user= (read reader)
(prn :clojure.string/kwd)

Can anyone think of a way to read the file without loading/compiling it?

Thanks,
Jonas

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

[ANN] kibit 0.0.2

2012-03-09 Thread Jonas
We have now released kibit[1] 0.0.2 to Clojars.

New in this release is

* Leiningen 2.0 support
* Better at finding source code
* More rules
* Marginalia docs[3]
* Lots of small fixes

Kibit is a simple code analysis tool (and leiningen plugin). The
purpose of the tool is to tell its users that Hey, There's already a
function for that!.

Kibit uses core.logic[2] to search for patterns of code for which
there might exist simpler functions. For example, if the analyzer
finds

(apply concat (apply map ...)

It will make the suggestion to use `(mapcat ...)` instead.

I would like to thank all contributors and especially Paul deGrandis
who has helped me with everything in this release!

Jonas

[1] https://github.com/jonase/kibit
[2] https://github.com/clojure/core.logic
[3] http://jonase.github.com/kibit/

-- 
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: [ANN] kibit, A static code analyzer

2012-03-05 Thread Jonas


On Monday, March 5, 2012 2:51:23 PM UTC+2, David Nolen wrote:

 It should unify:

 (foo ?x . ?y)

 If it doesn't we should open up a ticket for that.


It seems to work, thanks! 

https://github.com/jonase/kibit/commit/4ec52462d3920470be63916928021f266f838f1b


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

[ANN] kibit, A static code analyzer

2012-03-04 Thread Jonas
Kibit[1] is a simple code analysis tool (and leiningen plugin) which
someone hopefully will find interesting or useful. The purpose of the
tool is to tell its users that Hey, There's already a function for
that!.

Kibit uses the core.logic[2] unifier to search for patterns of code
for which there might exist simpler functions. For example, if the
analyzer finds

(apply concat (apply map ...)

It will notify its user about the availability of `mapcat`.

Jonas

[1] https://github.com/jonase/kibit
[2] https://github.com/clojure/core.logic

-- 
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: [ANN] kibit, A static code analyzer

2012-03-04 Thread Jonas


On Sunday, March 4, 2012 9:39:19 PM UTC+2, David Nolen wrote:

 This is just ... fantastic! :D


David, quick question about the core.logic unifier. Is it possible to unify 
on a sequence? For example (when ?x ??body) would unify with both 

(when (some pred)
   a)

and 
 
(when (some pred)
   a 
   b 
   c)

Thanks,
Jonas

-- 
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: [ANN] kibit, A static code analyzer

2012-03-04 Thread Jonas


On Monday, March 5, 2012 12:44:14 AM UTC+2, Alex Baranosky wrote:

 Hi Jonas,

 Kibit just helped me find some good uses for inc, pos? when and when-not 
 in Midje, thanks :)

 https://github.com/marick/Midje/commit/b0525b7237bf615e3013317d2a0c2fc56f14bfe2


That's very nice to hear!
 

-- 
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: options for a function

2012-02-22 Thread Jonas
I'll fix this today. 

Thanks,
Jonas

-- 
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: options for a function

2012-02-22 Thread Jonas
I just pushed the fix to github and released version 0.1.2. Sorry for the 
inconvenience.

I'm not really happy with the write part of data.csv. In the clojure spirit 
of simplicity it complects quoting of values with writing to disk. There 
might be different policies for when an api-user wants there values to be 
quoted:

* Quote everything (this can be done by setting :quote? to (constantly true)
* Quote nothing (this can be done by setting :quote? to (constantly false))
* Quote only when necessary (this is the default)
* Quote only the first row (i.e,, header)
* Quote (for example) the first and third column
* etc.

I thought about this a couple of days ago and the best I could come up with 
was to remove quoting from the writing part and have users quote there 
values as a pre-processing step before writing. If that is the way forward 
then there is almost nothing more to do in the writing part of the 
data.csv, e.g., you could just as well write

(with-open [w (io/writer some-file)]
  (with-binding [*out* w]
(doseq [row data] 
  (println (string/join , row)))

So It's not entirely clear to me if csv-write is needed at all and instead 
have a few helper functions, for example (quote-string s \'), together with 
a good description of how to use with-binding, doseq, str/join etc. in the 
README file.

Ideas welcome.

Jonas




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

[ANN] data.csv 0.1.1

2012-02-13 Thread Jonas
Hi 

data.csv is a csv reader/writer for Clojure. I released version 0.1.1 today 
and it should arrive at maven central soon. New in this release is more 
control over how and when the writer will quote strings. Hopefully, all 
necessary information can be found on github[1]

Jonas

[1]: github.com/clojure/data.csv

-- 
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: filter out null values

2012-02-02 Thread Jonas
Note that `(filter identity ,,,)` will also remove `false` values:

= (filter identity [1 2 nil 3 false 4])
(1 2 3 4)

You could use `remove` instead

= (remove nil? [1 2 nil 3 false 4])
(1 2 3 false 4)

Hope that helps!

Jonas

-- 
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: got trouble when combine use condition-map and doc-string

2012-01-28 Thread Jonas
The docstring goes before the argument list:

(defn another-f 
   doc string here 
   [x] 
   {:pre [(pos? x)]} 
   x)

user= (another-f -1)
java.lang.AssertionError: Assert failed: (pos? x) (NO_SOURCE_FILE:0)
user= (doc another-f)
-
user/another-f
([x])
  doc string here
nil

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

How to use goog.dom.query

2012-01-24 Thread Jonas
Hi all

I was wondering if it's possible to use goog.dom.query[1] from 
ClojureScript or ClojureScript One? It's a third party module but it's 
bundled with the Closure version which is downloaded by scripts/bootstrap. 
I've tried (:require [goog.dom.query :as query]) but that doesn't work out 
of the box for me. Looking at the source code[2] I can see it referenced 
several times which makes me hopeful that I should get it working. It seems 
that maybe I should add 

:libs [closure/library/third_party/closure]

or something similar to my build options but still no luck.

[1]: 
http://closure-library.googlecode.com/svn/docs/closure_third_party_closure_goog_dojo_dom_query.js.html
[2]: 
https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/closure.clj#L555

-- 
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: [ANN] analyze 0.1

2012-01-02 Thread Jonas
Hi Ambrose

I’ve been playing around with your library and find it very intresting. A 
couple of questions:

1. In order to be able to run your examples I have to comment out the 
clojure.test, clojure.stacktrace and clojure.template namespaces. Otherwise 
I get a NullPointerException[1] which I’m unable to track down. It seems to 
originate from the wall-hack function. What does this function do?

2. Is it possible to do some analysis before macroexpansion? For example, 
If I want to look for the pattern

(if (some-test? …)
(some-expr …)
nil)

and print the following: “WARNING: consider using (when …) instead of (if 
test then nil)”. Is this possible since (when test expr) expands to (if 
test (do expr)). Maybe this kind of code analysis is outside the scope of 
your library?

[1]: https://gist.github.com/1553808

-- 
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: [ANN] analyze 0.1

2012-01-02 Thread Jonas
Hi,

I pulled the latest version.

 How are you running the code? Could you pull the latest master and try 
again?

Nothing fancy:
- clone the repo
- lein deps
- start emacs, clojure-jack-in,
- compile e.g., examples/docstring - NullPointerException
- comment out the three namespaces I mentioned - It works perfectly :)
 
 Possibly track down exactly which namespace is causing the Exception.

The following works

(def analyzed
  (map #(apply analyze/analyze-path %) 
   '[#_[clojure/test.clj clojure.test]
 [clojure/set.clj clojure.set]
 [clojure/java/io.clj clojure.java.io]
 #_[clojure/stacktrace.clj clojure.stacktrace]
 [clojure/pprint.clj clojure.pprint]
 [clojure/walk.clj clojure.walk]
 [clojure/string.clj clojure.string]
 [clojure/repl.clj clojure.repl]
 [clojure/core/protocols.clj clojure.core.protocols]
 #_[clojure/template.clj clojure.template]]))

Uncommenting any of the three lines above results in a NullPointerException.

-- 
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: [ANN] analyze 0.1

2012-01-02 Thread Jonas


On Tuesday, January 3, 2012 9:45:04 AM UTC+2, Ambrose Bonnaire-Sergeant 
wrote:

 It seems if the namespace is not already loaded, then there are issues. 


That's it! It's simple to fix. Just require the namespaces in the ns form. 
I can send you a pull request if you want to?

/Jonas 

-- 
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: Really loving Clooj but..

2011-12-30 Thread Jonas
You should take a look at tools.trace [1]. A minimal example:

(ns trc.core
  (:use [clojure.tools.trace :only [deftrace]]))

(deftrace fib [n]
  (if (or (= n 0) (= n 1))
1
   (+ (fib (- n 1)) (fib (- n 2)

the following is printed when (fib 4) is evaluated:

TRACE t2302: (fib 4)
TRACE t2303: | (fib 3)
TRACE t2304: | | (fib 2)
TRACE t2305: | | | (fib 1) 
TRACE t2305: | | | = 1
TRACE t2306: | | | (fib 0)
TRACE t2306: | | | = 1
TRACE t2304: | | = 2
TRACE t2307: | | (fib 1)
TRACE t2307: | | = 1
TRACE t2303: | = 3
TRACE t2308: | (fib 2)
TRACE t2309: | | (fib 1)
TRACE t2309: | | = 1
TRACE t2310: | | (fib 0)
TRACE t2310: | | = 1
TRACE t2308: | = 2
TRACE t2302: = 5


[1]: https://github.com/clojure/tools.trace

-- 
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 accessing java methods?

2011-12-21 Thread Jonas
You can also do (.. boxWidget GetProp3D (SetUserTransform t)) or (- 
boxWidget .GetProp3D (.SetUserTransform t))

-- 
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: - vs - and names vs anonymous function

2011-11-02 Thread Jonas


On Wednesday, November 2, 2011 11:37:32 AM UTC+2, HamsterofDeath wrote:

 hi there,

 i stumbled over two odd things
 1) - and - have the same source code. why is that?

Similar, but not the same [1]:
(~(first form) ~x ~@(next form)) vs. (~(first form) ~@(next form) ~x)
 

 2) why can't i use (- hi #(println %)) directly? why do i have to
 put my function into a symbol first? is there a way to avoid this?

#(println %) expands to (fn [%] (println %)) so (- hi #(println %)) 
expands to (fn hi [%] (println %)). 

Note also that (- hi println) would work since it's transformed into 
(println hi). Also, the form (- hi (#(println %))) should also work 
fine.

/jonas

[1] 
https://github.com/clojure/clojure/blob/f5f827ac9fbb87e770d25007472504403ed3d7a6/src/clj/clojure/core.clj#L1528
 

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

2011-11-01 Thread Jonas
Hi

Have you looked at the interleave function[1]? I'd guess that's the one you 
want.

/Jonas

[1] 
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/interleave

-- 
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: updating some values in map

2011-10-23 Thread Jonas
Another way to do it

(defn apply-map-fn [m f  ks] 
  (reduce #(update-in %1 [%2] f) m ks))

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

A simple mistake to make when translating Javascript to ClojureScript

2011-07-26 Thread Jonas
First of all, thanks a lot for ClojureScript. A lot of interesting new stuff 
to learn and it has been very educational to read the ClojureScript source 
code. 

The following had me scratching my head for far too long. I translated some 
quite simple code from the closure book (the one with the bird on the cover) 
and I couldn’t get it to work. The problematic part of the program was the 
following js function:

example.main = function() {
  var root = goog.dom.getElement('root');
  root.addEventListener('click', example.click, false /* capture */);
  root.addEventListener('mouseover', example.mouseover, false /* capture 
*/);
  root.addEventListener('mouseout', example.clearHighlight, false /* capture 
*/);
};

which I translated to:

(defn ^:export main []
  (let [root (dom/getElement root)]
(doto root
  (.addEventListener 'click' click false)
  (.addEventListener 'mouseover' mouseover false)
  (.addEventListener 'mouseout' clear-highlight false

No compile-time errors, warnings or runtime errors. And no events fired. Can 
you spot the mistake? It’s kind of a special case but I wonder if it would 
be possible for the compiler to generate a warning. It’s a mistake that I 
think experienced javascript developers might have a hard time to spot. 

Thanks,
Jonas


(The problem, of course, is that ‘click’ is a string in javascript but 
evaluates to the symbol click’ in clojurescript so it’s easy to make 
copy-paste errors)

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

proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
Hi.
I'm trying to create a java.io.Writer proxy (which writes to a
JTextArea) but I can't get it to work.
Here is my clojure code so far:

(def text-area (javax.swing.JTextArea.))

(def frame
     (let [f (javax.swing.JFrame.)]
       (.. f getContentPane (add text-area))
       (.setMinimumSize f (java.awt.Dimension. 200 200))
       (.setVisible f true)
       f))

(def text-area-writer
     (proxy [java.io.Writer] []
       (close [])
       (flush [])
       (write [^chars chrs ^int offs ^int len]
         (.append text-area (String. chrs offs len)

When I load the code above I get an IllegalArgumentException: Unable
to resolve classname: int so I think I'm not type hinting correctly.

Here is a similar piece of java code which works as expected:

public class Main extends JFrame {
  private JTextArea text;
  public Writer writer;

  public Main() {
text = new JTextArea();
getContentPane().add(text);
setVisible(true);
setMinimumSize(new Dimension(200, 200));
writer = new TextAreaWriter();
  }

  class TextAreaWriter extends Writer {
public void close() throws IOException {}
public void flush() throws IOException {}

public void write(char[] chrs, int offs, int len) throws IOException {
  String str = new String(chrs, offs, len);
  text.append(str);
}
  }

  public static void main(String[] args) throws IOException {
Main m = new Main();
m.writer.write(Hello, World!);
  }
}

Any help is much appreciated!

/Jonas

-- 
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: proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson kwess...@gmail.com wrote:
 On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund jonas.enl...@gmail.com wrote:
 Hi.
 I'm trying to create a java.io.Writer proxy (which writes to a
 JTextArea) but I can't get it to work.
 Here is my clojure code so far:

 (def text-area (javax.swing.JTextArea.))

 (def frame
      (let [f (javax.swing.JFrame.)]
        (.. f getContentPane (add text-area))
        (.setMinimumSize f (java.awt.Dimension. 200 200))
        (.setVisible f true)
        f))

 (def text-area-writer
      (proxy [java.io.Writer] []
        (close [])
        (flush [])
        (write [^chars chrs ^int offs ^int len]
          (.append text-area (String. chrs offs len)

 When I load the code above I get an IllegalArgumentException: Unable
 to resolve classname: int so I think I'm not type hinting correctly.

 Indeed. You can't (in 1.2 at least) type hint int though you can
 ints (array of int). Note that int is a primitive type while array
 of int is a reference type.

 Type hinting as Integer shouldn't throw exceptions, but you can
 probably omit all but the chars hint and have the correct String
 constructor overload selected.

I tried with 1.3.0-alpha5. With type hints I get CompilerException
java.lang.IllegalArgumentException: Only long and double primitives
are supported. If I only keep the ^chars hint I get an ArityException
when I do (.write text-area-writer hello).

Is this problem unsolvable with proxy? Should I look into gen-class
and AOT compilation instead?


 Also note that while text area .append is safe to call from off the
 EDT, other Swing methods mostly aren't, and it's something to watch
 for if you do anything similar to this with other Swing components,
 and wherever you construct your text area and its surrounds.

 --
 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: proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
On Sun, Jan 30, 2011 at 8:39 PM, Ken Wesson kwess...@gmail.com wrote:
 On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund jonas.enl...@gmail.com wrote:
 On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson kwess...@gmail.com wrote:
 On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund jonas.enl...@gmail.com 
 wrote:
 Hi.
 I'm trying to create a java.io.Writer proxy (which writes to a
 JTextArea) but I can't get it to work.
 Here is my clojure code so far:

 (def text-area (javax.swing.JTextArea.))

 (def frame
      (let [f (javax.swing.JFrame.)]
        (.. f getContentPane (add text-area))
        (.setMinimumSize f (java.awt.Dimension. 200 200))
        (.setVisible f true)
        f))

 (def text-area-writer
      (proxy [java.io.Writer] []
        (close [])
        (flush [])
        (write [^chars chrs ^int offs ^int len]
          (.append text-area (String. chrs offs len)

 When I load the code above I get an IllegalArgumentException: Unable
 to resolve classname: int so I think I'm not type hinting correctly.

 Indeed. You can't (in 1.2 at least) type hint int though you can
 ints (array of int). Note that int is a primitive type while array
 of int is a reference type.

 Type hinting as Integer shouldn't throw exceptions, but you can
 probably omit all but the chars hint and have the correct String
 constructor overload selected.

 I tried with 1.3.0-alpha5. With type hints I get CompilerException
 java.lang.IllegalArgumentException: Only long and double primitives
 are supported. If I only keep the ^chars hint I get an ArityException
 when I do (.write text-area-writer hello).

 Does it work with 1.2? Where exactly is the ArityException being
 thrown -- for what function or method?

It didn't work in 1.2 either. Here is some more info on the exception
thrown (this is with 1.3.0-alpha5)

user= (.write text-area-writer Hello, World!)
ArityException Wrong number of args (2) passed to: user$fn--38$fn
clojure.lang.AFn.throwArity (AFn.java\
:439)
user= (pst)
ArityException Wrong number of args (2) passed to: user$fn--38$fn
user.proxy$java.io.Writer$0.write (:-1)
sun.reflect.NativeMethodAccessorImpl.invoke0
(NativeMethodAccessorImpl.java:-2)
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke (Method.java:616)
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:90)
clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:28)
user/eval47 (NO_SOURCE_FILE:4)
clojure.lang.Compiler.eval (Compiler.java:6223)
clojure.lang.Compiler.eval (Compiler.java:6190)
clojure.core/eval (core.clj:2680)
clojure.main/repl/read-eval-print--5617 (main.clj:180)
nil
user=

Thanks for helping out with this Ken!


 --
 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: A simple csv parsing library

2010-06-11 Thread Jonas Enlund
On Thu, Jun 10, 2010 at 1:01 AM, Daniel Werner
daniel.d.wer...@googlemail.com wrote:
 Jonas,

 Thanks for stepping forward and publishing your work. From the short
 glance I had at it already, your code seems very low-level (probably
 for performance), but sound. The only thing that, compared to other
 CSV libraries I've used, I miss somewhat is explicit support for
 dialects. While the developer can set the separator, quote and
 newline chars herself, it would be nice if there were a number of pre-
 made maps for commonly used CSV dialects, e.g. Excel, whose values can
 just be passed to the read and write functions.

 To give an example, Python's approach is quite simple yet effective.
 Their use of class inheritance to define new dialects that are similar
 to old ones would translate well to Clojure maps, by assoc'ing or
 merge'ing the changes in.

 http://docs.python.org/library/csv.html#csv-fmt-params

I'll take a look at how python does things. Dialects sounds like a good idea.

I have now added the lib to clojars so it should be ready for use with
either leiningen or maven.

-- 
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: A simple csv parsing library

2010-06-09 Thread Jonas Enlund
When I say that it supports the RFC I mean that the library should be
able to read any file that follows that standard. It might (and it
does) read files that do not follow the standard. Here are some
examples:

1) quotes can appear anywhere, not only as the first and last
character in a cell.
2) records can be of different length.
3) any character can be used as quote or separator.
4) The problem you raised, i.e., that the file might end in a quoted
state and still be read without exceptions.

I'll consider adding a :strict flag which would throw an exception for
points 2 and 4. However, I don't want to sacrifice performance since I
consider that to be the most important feature in any csv reading
library (people often have Gb+ sized csv files).

Jonas



On Wed, Jun 9, 2010 at 6:54 AM, Kyle R. Burton kyle.bur...@gmail.com wrote:
 I've added my work on the csv reader/writer library to github
 (http://github.com/jonase/cljcsv). Please let me know If anyone finds
 it useful.

 Thanks for the implementation, I'm very encouraged that you followed
 the RFC (I've seen lots of implementations that haven't).

 I took a quick look at both yours and clojure-csv [1].  I'm not using
 the 1.2 snapshots so I wasn't able to try out your implementation, but
 I did notice clojure-csv is lax about invalidly formatted files - if a
 quoted field ends the file but is not terminated before eof, it does
 not signal an error.  I think I recognize the same behavior in cljcsv
 as well (though as I said I could not try it).  It might be nice to at
 least have an option which allows an unterminated field to be
 recognized.

 Best Regards,

 Kyle

 [1] http://github.com/davidsantiago/clojure-csv

 On Wed, May 26, 2010 at 6:40 AM, Jonas Enlund jonas.enl...@gmail.com wrote:
 Hi there

 I built a simple csv parsing library[1] last weekend which I want to
 show you guys. It follows the RFC 4180[2] pretty closely but it allows
 for any character as separator and quote mark. It would be great if
 someone would take time and read the code. I would like to know:

 a) Can performance still be improved?
 b) Is it idiomatically written?
 c) What should an idiomatic csv parsing API look like in Clojure?
 Currently there is only one public function, 'parse' (like
 clojure.xml).

 The end of the file contains a few usage examples.

 happy hacking!
 /Jonas

 [1] http://gist.github.com/414023
 [2] http://tools.ietf.org/html/rfc4180


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



 --
 --
 kyle.bur...@gmail.com                            http://asymmetrical-view.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: A simple csv parsing library

2010-06-08 Thread Jonas Enlund
I've added my work on the csv reader/writer library to github
(http://github.com/jonase/cljcsv). Please let me know If anyone finds
it useful.

Thanks,
Jonas

On Wed, May 26, 2010 at 6:40 AM, Jonas Enlund jonas.enl...@gmail.com wrote:
 Hi there

 I built a simple csv parsing library[1] last weekend which I want to
 show you guys. It follows the RFC 4180[2] pretty closely but it allows
 for any character as separator and quote mark. It would be great if
 someone would take time and read the code. I would like to know:

 a) Can performance still be improved?
 b) Is it idiomatically written?
 c) What should an idiomatic csv parsing API look like in Clojure?
 Currently there is only one public function, 'parse' (like
 clojure.xml).

 The end of the file contains a few usage examples.

 happy hacking!
 /Jonas

 [1] http://gist.github.com/414023
 [2] http://tools.ietf.org/html/rfc4180


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


Recur on a function which uses keyword arguments?

2010-06-06 Thread Jonas Enlund
The function definition below fails with
java.lang.IllegalArgumentException: Mismatched argument count to
recur, expected: 1 args, got: 2

(defn countdown [ {:keys [from]
:or {from 10}}]
  (println from)
  (when (pos? from)
(recur :from (dec from

Is it not possible to recur on a function which uses keyword
arguments? If so, is using loop/recur the correct workaround?

- Jonas

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


A simple csv parsing library

2010-05-25 Thread Jonas Enlund
Hi there

I built a simple csv parsing library[1] last weekend which I want to
show you guys. It follows the RFC 4180[2] pretty closely but it allows
for any character as separator and quote mark. It would be great if
someone would take time and read the code. I would like to know:

a) Can performance still be improved?
b) Is it idiomatically written?
c) What should an idiomatic csv parsing API look like in Clojure?
Currently there is only one public function, 'parse' (like
clojure.xml).

The end of the file contains a few usage examples.

happy hacking!
/Jonas

[1] http://gist.github.com/414023
[2] http://tools.ietf.org/html/rfc4180

-- 
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: how to use with-bindings*

2010-02-15 Thread Jonas Enlund
On Mon, Feb 15, 2010 at 7:25 AM, Аркадий Рост arkr...@gmail.com wrote:
 Hi!
 I was playing a bit with with-bindings* function, but I got error
 every time.

 I've tried:

 (def a 5)

 (with-bindings* {a 3} println a) ;; got java.lang.Integer cannot be
 cast to clojure.lang.Var

 (with-bindings* [{a 3}] println a) ;;got
 clojure.lang.PersistentArrayMap cannot be cast to
 clojure.lang.IMapEntry

 (with-bindings* [a 3] println a) ;;got java.lang.Integer cannot be
 cast to clojure.lang.IMapEntry

 and others variants...So what's the syntaxes of this function?

 Someone show code example, please.

Hi,

Try one of the following:

user= (with-bindings* {#'a 3} println a)
5 ; It seems as if args doesn't have the new bindings yet since this prints 5
nil

user= (with-bindings {#'a 3} (println a))
3
nil

user= (with-bindings* {#'a 3} #(println a))
3
nil

-- 
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 the only one with deftype/defprotocol problems?

2010-01-04 Thread Jonas Enlund
I think you simply need to get the syntax right. The following works
fine for me:

user=  (defprotocol p (foo [this]))
p
user=  (deftype a [f] p (foo []))
#'user/a
user= (foo (a nil))
nil
user= (deftype a [f] :as this p (foo [] [this]))
#'user/a
user= (foo (a nil))
[#:a{:f nil}]




On Mon, Jan 4, 2010 at 6:37 AM, Raoul Duke rao...@gmail.com wrote:
 hi,

 i've only heard crickets so far, am i really the only one who can't
 get this to work? help? :-} thanks. i figure i must be doing something
 dirt simple wrong?

 Clojure 1.1.0-new-SNAPSHOT
 user= (defprotocol p (foo [this]))
 p
 user= (deftype a [f] [p] (.foo [this]))
 java.lang.RuntimeException: java.lang.ClassCastException:
 clojure.lang.PersistentVector cannot be cast to clojure.lang.Symbol
 (NO_SOURCE_FILE:0)

 --
 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: Creating deftype instance from inside a protocol method

2010-01-02 Thread Jonas Enlund
(note the .)

(deftype Bar
  [i]
  Foo
(foo [] (Bar. (inc i

/Jonas

-- 
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: Creating deftype instance from inside a protocol method

2010-01-02 Thread Jonas Enlund
Sorry, I think my reply got lost...

Inside deftype methods the symbol Bar is the name of the class. You
can use the constructor (Bar. (inc i)) instead. Again, note the .
after Bar.

On Sat, Jan 2, 2010 at 1:23 PM, Konrad Hinsen
konrad.hin...@fastmail.net wrote:
 On 01.01.2010, at 23:56, Hugo Duncan wrote:

 I want to create a new instance of a deftype from inside one of its
 methods.

 I ended-up using extend-type for this case.

 That's probably the cleanest solution, but you lose the performance
 benefit of defining methods right in the type definition.

 After looking at the deftype code, I came up with the following
 solution:

 (defprotocol Foo
   (foo [x]))

 (deftype Bar
   [i]
   Foo
     (foo [] (new Bar (inc i

 (foo (Bar 0))


 Its drawback is relying on an undocumented feature: the value of Foo
 inside the methods is the class Foo being defined.

 Konrad.

 --
 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: Datatypes and Protocols - early experience program

2009-11-16 Thread Jonas Enlund
On Mon, Nov 16, 2009 at 6:27 PM, Stuart Sierra
the.stuart.sie...@gmail.com wrote:
 On Nov 14, 8:28 am, Jonas Enlund jonas.enl...@gmail.com wrote:
 I have built a simple Matrix datatype with defprotocol and deftype.
 You can take a look at it athttp://gist.github.com/234535
 (constructive criticism welcome!).

 Small thing: I would expect (count a-matrix) to return rows*columns,
 not the number of rows.

I made count return the number of rows because that way (count
a-matrix) == (count (seq a-matrix)). I don't know if it's the right
thing to do, maybe rows*cols would make more sense.

/Jonas


 -SS

 --
 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: Datatypes and Protocols - early experience program

2009-11-14 Thread Jonas Enlund
Hi there!

I have built a simple Matrix datatype with defprotocol and deftype.
You can take a look at it at http://gist.github.com/234535
(constructive criticism welcome!). Some simple examples are provided
at the end of the file.

I have a few questions.

- Why must i write (matrix/Matrix ...) instead of (Matrix ...) inside
the deftype body? Is this a bug? I didn't have to write it that way in
earlier versions of the new-branch.
- Am I supposed to have all the interface implementations inside the
deftype body? I didn't figure out how to move the implementation of
the clojure.lang.* interfaces to (extends ...).

/Jonas

-- 
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: transient quicksort

2009-08-05 Thread Jonas Enlund

Hi,

Thank's for pointing this out for me. I didn't realize how to use
these constructs correctly. Seeing the !-mark i just thought that
assoc! was to be used like set! set-car! set-cdr! in Scheme... my
mistake.

On Tue, Aug 4, 2009 at 8:49 PM, Jarkko Oranenchous...@gmail.com wrote:

 On Aug 4, 11:08 am, Jonas jonas.enl...@gmail.com wrote:
 Hi

 I'm playing with the new transient/persistent! features in Clojure. I
 have implemented quicksort as described on wikipedia (http://
 en.wikipedia.org/wiki/Quicksort#Algorithm). Here is the code:

 (defn swap-index! [v i j]
   (let [tmp (v i)]
     (assoc! v i (v j))
     (assoc! v j tmp)))

 I think Rich mentioned on IRC that you should not reuse the transient
 vector binding after an operation; that it works is merely an
 implementation detail. The transient documentation page also says
 tells to capture return value, use for next call. So:

 (defn swap-index! [tv i j]
  (let [tmp (tv i)]
    (- tv
      (assoc! i (v j))
      (assoc! j tmp

 And similar modifications for the quicksort below.


 (defn partition! [v left-index right-index pivot-index]
     (let [pivot-value (v pivot-index)]
       (swap-index! v pivot-index right-index)
       (loop [i left-index store-index left-index]
         (if ( i right-index)
           (if (= (v i) pivot-value)
             (do (swap-index! v i store-index)
                 (recur  (inc i) (inc store-index)))
             (recur (inc i) store-index))
           (do (swap-index! v store-index right-index)
               store-index)

 (defn qsort! [v left right]
   (when ( right left)
     (let [pivot-index left
           pivot-new-index (partition! v left right pivot-index)]
       (qsort! v left (dec pivot-new-index))
       (qsort! v (inc pivot-new-index) right

 (defn qsort [v]
   (let [tv (transient v)]
     (qsort! tv 0 (dec (count v)))
     (persistent! tv)))

 This sorts a vector of doubles in about 6000-7000 msec on my machine:

 user= (def s (time (qsort (rvector 100
 Elapsed time: 6681.35889 msecs

 This is much faster than the classical functional programming
 quicksort:

 ; Fromhttp://rosettacode.org/wiki/Quicksort#Clojure
 (defn qsort-rs [[pivot  xs]]
   (when pivot
     (let [smaller #( % pivot)]
       (lazy-cat (qsort (filter smaller xs))
                 [pivot]
                 (qsort (remove smaller xs))

 user= (def s (time (doall (qsort-rs (rvector 100)
 Elapsed time: 32565.537389 msecs

 The Java sort however is about 5 times faster then the transient
 version:

 user= (def s (time (sort (rvector 100
 Elapsed time: 1354.427239 msecs

 Can you give any hints on how I can make the transient sort faster? I
 would like to get as close as possible to the native Java speed.

 This is partially comparing apples to oranges though: sort returns a
 lazy seq, while
 the quicksort algorithm produces a proper vector.

 Anyway, (nth v i) might be somewhat faster than (v i) because it gets
 inlined. I did not try, though.
Ok, I will try that


 Below is code that avoids reusing the reference to v:

 (defn swap-index! [v i j]
  (let [tmp (nth v i)]
    (- v
        (assoc! i (nth v j))
        (assoc! j tmp

 (defn partition! [v left-index right-index pivot-index]
    (let [pivot-value (nth v pivot-index)
           new-v (swap-index! v pivot-index right-index)]
      (loop [v new-v, i left-index, store-index left-index]
        (if ( i right-index)
          (if (= (nth v i) pivot-value)
            (recur (swap-index! v i store-index) (inc i) (inc store-
 index))
            (recur v (inc i) store-index))
          [(swap-index! v store-index right-index)
           store-index]

 (defn qsort! [v left right]
  (if ( right left)
    (let [pivot-index left
           [new-v pivot-new-index] (partition! v left right pivot-
 index)]
      (- new-v
          (qsort! left (dec pivot-new-index))
          (qsort! (inc pivot-new-index) right
    v)

 (defn qsort [v]
  (let [tv (transient v)]
    (qsort! tv 0 (dec (count v)))
    (persistent! tv)))
Nice, thank you!


 --
 Jarkko
 


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



transient quicksort

2009-08-04 Thread Jonas

Hi

I'm playing with the new transient/persistent! features in Clojure. I
have implemented quicksort as described on wikipedia (http://
en.wikipedia.org/wiki/Quicksort#Algorithm). Here is the code:

(defn swap-index! [v i j]
  (let [tmp (v i)]
(assoc! v i (v j))
(assoc! v j tmp)))

(defn partition! [v left-index right-index pivot-index]
(let [pivot-value (v pivot-index)]
  (swap-index! v pivot-index right-index)
  (loop [i left-index store-index left-index]
(if ( i right-index)
  (if (= (v i) pivot-value)
(do (swap-index! v i store-index)
(recur  (inc i) (inc store-index)))
(recur (inc i) store-index))
  (do (swap-index! v store-index right-index)
  store-index)

(defn qsort! [v left right]
  (when ( right left)
(let [pivot-index left
  pivot-new-index (partition! v left right pivot-index)]
  (qsort! v left (dec pivot-new-index))
  (qsort! v (inc pivot-new-index) right

(defn qsort [v]
  (let [tv (transient v)]
(qsort! tv 0 (dec (count v)))
(persistent! tv)))

This sorts a vector of doubles in about 6000-7000 msec on my machine:

user= (def s (time (qsort (rvector 100
Elapsed time: 6681.35889 msecs

This is much faster than the classical functional programming
quicksort:

; From http://rosettacode.org/wiki/Quicksort#Clojure
(defn qsort-rs [[pivot  xs]]
  (when pivot
(let [smaller #( % pivot)]
  (lazy-cat (qsort (filter smaller xs))
[pivot]
(qsort (remove smaller xs))

user= (def s (time (doall (qsort-rs (rvector 100)
Elapsed time: 32565.537389 msecs

The Java sort however is about 5 times faster then the transient
version:

user= (def s (time (sort (rvector 100
Elapsed time: 1354.427239 msecs

Can you give any hints on how I can make the transient sort faster? I
would like to get as close as possible to the native Java speed.

;
Here is the rvector function as used in the timing tests (for
completeness):

(defn rvector [n]
  (loop [i 0 v (transient [])]
(if ( i n)
  (recur (inc i) (conj! v (Math/random)))
  (persistent! v
;

These new clojure features are so much fun!

--~--~-~--~~~---~--~~
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: transient quicksort

2009-08-04 Thread Jonas Enlund

I get ~8% performance boost by turning swap-index! into a macro:

(defmacro swap-index! [v i j]
  `(let [tmp# (~v ~i)]
(assoc! ~v ~i (~v ~j))
(assoc! ~v ~j tmp#)))

--~--~-~--~~~---~--~~
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: transient quicksort

2009-08-04 Thread Jonas Enlund

On Tue, Aug 4, 2009 at 3:55 PM, Albert Cardonasapri...@gmail.com wrote:

 Jonas wrote:
  Can you give any hints on how I can make the transient sort faster? I
  would like to get as close as possible to the native Java speed.


 My guess is that you need primitive type hints. For example:

     (let [pivot-value (v pivot-index)]



 could be:

    (let [pivot-value (int (v pivot-index))]


 ... and so on.

 Albert


I have tried to add type hints but they don't seem to speed things up.
For example, if I add type hints to the partition! loop (where I would
have thought that
type hints would make the biggest difference) I don't see a speedup at all:

(defn partition! []
   ...
   (loop [i (int left-index) store-index (int left-index)]
   ...)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



The :while modifier (list comprehensions)

2009-08-03 Thread Jonas

I find the :while modifier non intuitive

user= (for [x (range 1 10) y (range 1 10) :while (= y 2)] [x y])
()
user= (for [x (range 1 10) y (range 1 10) :while (= x 2)] [x y])
([2 1] [2 2] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9])

My (false) intuition told me that both expressions would have been
evaluated to an empty sequence. Could someone explain the rationale
behind the :while modifier?

--~--~-~--~~~---~--~~
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: The :while modifier (list comprehensions)

2009-08-03 Thread Jonas Enlund

 When you put the :while at the `x` clause you get the expected empty
 seq.

 user= (for [x (range 1 10) :while (= x 2) y (range 1 10)] [x y])
 ()

Interesting, I didn't know that.

Still, the behavior of :while feels strange. I guess I'll get used to it.

In the following example :while and :when are interchangeable, which
is often the case when :while is used last in the list comprehension:

user= (for [x (range 1 10) y (range 1 10) :while ( (+ x y) 5)] [x y])
([1 1] [1 2] [1 3] [2 1] [2 2] [3 1])

user= (for [x (range 1 10) y (range 1 10) :when ( (+ x y) 5)] [x y])
([1 1] [1 2] [1 3] [2 1] [2 2] [3 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
-~--~~~~--~~--~--~---



Newbie macro problems

2009-07-08 Thread Jonas

Hi.

I'm developing a simple pattern matching library for clojure but I am
having
trouble with macros (which I have almost zero experience with).

I have a function `make-matcher`

(make-matcher pattern)

which returns a function that can pattern match on data and returns a
map of bindings (or nil in case of a non-match).

((make-matcher '(list x y z w)) (list 1 2 3 4))
; = {x 1 y 2 z 3 w 4}
((make-matcher '(list x y z x)) (list 1 2 3 4))
; = nil
((make-matcher '(list 1 x 2 _)) (list 1 2 3 4))
; = nil
((make-matcher '(list 1 x 2 _)) (list 1 3 2 9))
; = {x 3}

I have been trying to write the following 'match' macro:

(match data
  pattern-1 body-1
  pattern-2 body-2)

The macro should work like this:

(match (list 1 2 3)
   (list 1 x)   (+ x x)
   (list 1 x y) (+ x y))
; = 5

I have the following macros (none of which works correctly):

; (letmap {a 1 b 2} (+ a b))
; =(should) expand to=
; (let [a 1 b 2] (+ a b))
(defmacro letmap [dict  body]
  `(let ~(into [] (reduce concat (eval dict)))
 (do ~...@body)))

; (match (list 1 2 3)
;   (list 1 x)   (+ x x)
;   (list 1 x y) (+ x y))
; =should expand to something like=
; (let [dict (matcher.. (list 1 2 3))]
;   (if dict
;  (letmap dict (+ 1 x))
;  (match (list 1 2 3) (list 1 x y) (+ x y
(defmacro match [data  clauses]
  (when clauses
(let [pattern(first clauses)
  body   (second clauses)
  matcher (make-matcher pattern)]
  `(let [dict# (~matcher ~data)]
 (if dict#
   (letmap dict# ~body)
   (match ~data (next (next ~clauses

Any help is appreciated. Also pointers to documents and books where I
can
learn more about macros.

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: Newbie macro problems

2009-07-08 Thread Jonas Enlund

1. Ok, I'll consider that.

2. Yes, I'll post a link when I have uploaded the code somewhere.

3. It has not yet arrived

4. No. I have two sources of inspiration. Pattern matching in PLT
Scheme and this link:
http://groups.csail.mit.edu/mac/users/gjs/6.945/psets/ps05/ps.txt
(which is almost SICP as it is written by Sussman)

On Wed, Jul 8, 2009 at 7:15 PM, Sean Devlinfrancoisdev...@gmail.com wrote:

 4.  Is this example from SICP?

 On Jul 8, 12:12 pm, Sean Devlin francoisdev...@gmail.com wrote:
 This seems like a good use for a macro.  A couple of thoughts:

 1.  Use arrays instead of lists
 In clojure, it is best practice to use arrays for data.  So, your
 macro call should look like this.

 (match [1 2 3]
        [1 x]   (+ x x)
        [1 x y] (+ x y))

 2.  Could you post the source to match maker?  That would help my play
 around in a REPL

 3.  As for books go, get yourself a copy of Programming Clojure by
 Stuart Holloway

 Sean

 On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote:

  Hi.

  I'm developing a simple pattern matching library for clojure but I am
  having
  trouble with macros (which I have almost zero experience with).

  I have a function `make-matcher`

  (make-matcher pattern)

  which returns a function that can pattern match on data and returns a
  map of bindings (or nil in case of a non-match).

  ((make-matcher '(list x y z w)) (list 1 2 3 4))
  ; = {x 1 y 2 z 3 w 4}
  ((make-matcher '(list x y z x)) (list 1 2 3 4))
  ; = nil
  ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4))
  ; = nil
  ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9))
  ; = {x 3}

  I have been trying to write the following 'match' macro:

  (match data
    pattern-1 body-1
    pattern-2 body-2)

  The macro should work like this:

  (match (list 1 2 3)
         (list 1 x)   (+ x x)
         (list 1 x y) (+ x y))
  ; = 5

  I have the following macros (none of which works correctly):

  ; (letmap {a 1 b 2} (+ a b))
  ; =(should) expand to=
  ; (let [a 1 b 2] (+ a b))
  (defmacro letmap [dict  body]
    `(let ~(into [] (reduce concat (eval dict)))
       (do ~...@body)))

  ; (match (list 1 2 3)
  ;       (list 1 x)   (+ x x)
  ;       (list 1 x y) (+ x y))
  ; =should expand to something like=
  ; (let [dict (matcher.. (list 1 2 3))]
  ;   (if dict
  ;      (letmap dict (+ 1 x))
  ;      (match (list 1 2 3) (list 1 x y) (+ x y
  (defmacro match [data  clauses]
    (when clauses
      (let [pattern    (first clauses)
            body       (second clauses)
            matcher (make-matcher pattern)]
        `(let [dict# (~matcher ~data)]
           (if dict#
             (letmap dict# ~body)
             (match ~data (next (next ~clauses

  Any help is appreciated. Also pointers to documents and books where I
  can
  learn more about macros.

  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: Newbie macro problems

2009-07-08 Thread Jonas Enlund

2. http://gist.github.com/142939

On Wed, Jul 8, 2009 at 7:19 PM, Jonas Enlundjonas.enl...@gmail.com wrote:
 1. Ok, I'll consider that.

 2. Yes, I'll post a link when I have uploaded the code somewhere.

 3. It has not yet arrived

 4. No. I have two sources of inspiration. Pattern matching in PLT
 Scheme and this link:
 http://groups.csail.mit.edu/mac/users/gjs/6.945/psets/ps05/ps.txt
 (which is almost SICP as it is written by Sussman)

 On Wed, Jul 8, 2009 at 7:15 PM, Sean Devlinfrancoisdev...@gmail.com wrote:

 4.  Is this example from SICP?

 On Jul 8, 12:12 pm, Sean Devlin francoisdev...@gmail.com wrote:
 This seems like a good use for a macro.  A couple of thoughts:

 1.  Use arrays instead of lists
 In clojure, it is best practice to use arrays for data.  So, your
 macro call should look like this.

 (match [1 2 3]
        [1 x]   (+ x x)
        [1 x y] (+ x y))

 2.  Could you post the source to match maker?  That would help my play
 around in a REPL

 3.  As for books go, get yourself a copy of Programming Clojure by
 Stuart Holloway

 Sean

 On Jul 8, 11:42 am, Jonas jonas.enl...@gmail.com wrote:

  Hi.

  I'm developing a simple pattern matching library for clojure but I am
  having
  trouble with macros (which I have almost zero experience with).

  I have a function `make-matcher`

  (make-matcher pattern)

  which returns a function that can pattern match on data and returns a
  map of bindings (or nil in case of a non-match).

  ((make-matcher '(list x y z w)) (list 1 2 3 4))
  ; = {x 1 y 2 z 3 w 4}
  ((make-matcher '(list x y z x)) (list 1 2 3 4))
  ; = nil
  ((make-matcher '(list 1 x 2 _)) (list 1 2 3 4))
  ; = nil
  ((make-matcher '(list 1 x 2 _)) (list 1 3 2 9))
  ; = {x 3}

  I have been trying to write the following 'match' macro:

  (match data
    pattern-1 body-1
    pattern-2 body-2)

  The macro should work like this:

  (match (list 1 2 3)
         (list 1 x)   (+ x x)
         (list 1 x y) (+ x y))
  ; = 5

  I have the following macros (none of which works correctly):

  ; (letmap {a 1 b 2} (+ a b))
  ; =(should) expand to=
  ; (let [a 1 b 2] (+ a b))
  (defmacro letmap [dict  body]
    `(let ~(into [] (reduce concat (eval dict)))
       (do ~...@body)))

  ; (match (list 1 2 3)
  ;       (list 1 x)   (+ x x)
  ;       (list 1 x y) (+ x y))
  ; =should expand to something like=
  ; (let [dict (matcher.. (list 1 2 3))]
  ;   (if dict
  ;      (letmap dict (+ 1 x))
  ;      (match (list 1 2 3) (list 1 x y) (+ x y
  (defmacro match [data  clauses]
    (when clauses
      (let [pattern    (first clauses)
            body       (second clauses)
            matcher (make-matcher pattern)]
        `(let [dict# (~matcher ~data)]
           (if dict#
             (letmap dict# ~body)
             (match ~data (next (next ~clauses

  Any help is appreciated. Also pointers to documents and books where I
  can
  learn more about macros.

  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: Clojure goes Git!

2009-06-17 Thread Jonas Bonér

Awesome. Good decision.

On Jun 17, 2:17 am, Rich Hickey richhic...@gmail.com wrote:
 Clojure and contrib repos are now on GitHub:

 http://github.com/richhickey/clojurehttp://github.com/richhickey/clojure-contrib

 Issues and other development collaboration has moved to Assembla:

 http://www.assembla.com/spaces/clojurehttp://www.assembla.com/spaces/clojure-contrib

 General discussions are going to stay right here on Google Groups:

 http://groups.google.com/group/clojure

 And there's a new group for Clojure developers and contributors:

 http://groups.google.com/group/clojure-dev

 non-contributors can follow along:

 http://groups.google.com/group/clojure-dev/feeds

 You can follow Clojure development on Twitter (exact content TBD):

 http://twitter.com/clojuredev

 Some items are still outstanding:

         Importation of existing issues
         Placement of generated contrib documentation
         Patch submission policy

 In particular, please don't send pull requests via GitHub at this
 time.

 The move to git was much requested, but accompanied by a certain
 amount of apprehension from the non-git-savvy and some Windows users.
 If you *are* git-savvy, please do your best to support others on the
 group and irc as they get setup and find their bearings.

 I'm looking forward to these new tools further enhancing the
 collaboration amongst the Clojure community.

 Thanks again to all for your participation!

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

2009-05-04 Thread Jonas Bonér

Big congrats. Fantastic work Rich and all contributors. Thanks for
making this happen.
/Jonas

2009/5/4 Rich Hickey richhic...@gmail.com:

 After a sustained period of API stability and minimal bugs reports,
 I'm happy to announce the release of Clojure 1.0!

 http://clojure.googlecode.com/files/clojure_1.0.0.zip

 Numbered releases will enable people to consume a stable version of
 Clojure and move to bugfix-only incremental versions while preserving
 API stability, and to consume libraries designed to work with specific
 versions. Providing the bugfix-only revisions depends upon the
 community to submit patches for the release branch as well as the
 trunk.

 Clojure represents several years of effort on my part, but has also
 been shaped profoundly by the community in the 18 months since its
 release to the public. I can't thank everyone enough for your
 contributions of ideas, bug reports, suggestions, tests, tools,
 documentation and code - patches and enhancements. Clojure wouldn't be
 where it is today without its community and all of your efforts.

 Of course, there is more to do. Many good ideas have been suggested in
 the discussions preceding this release that were best put off for 1.1.
 Now with the release we can pursue them, and many others:

 http://clojure.org/todo

 I want to give special thanks to those who have made donations - they
 really help! I did the core work on Clojure during a self-funded
 sabbatical that has run its course (i.e. through my savings :) -
 donations help fund the future.

 Clojure 1.0 is a milestone of achievement, but it also represents a
 beginning. With 1.0, Stuart's book, the burgeoning set of libraries in
 and outside of contrib, and the large, friendly community, Clojure is
 poised to enter a period of increased adoption and application in many
 domains.

 Here's to the future!

 Rich

 




-- 
Jonas Bonér | Crisp AB

http://jonasboner.com
http://crisp.se

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: First Release of Chimp available

2008-10-08 Thread Jonas Bengtsson

Hi Meikel,

Trying to get Chimp running under cygwin. It seems like it depends on
the following packages: vim, screen, util-linux (for getopt).

However, when I try to run chimp, screen flashes only to terminate. Is
that the way it's supposed to work?

What are the exact steps to use chimp? Is the idea that I should
launch chimp and then launch vim inside the screen session?

Thanks in advance,
Jonas

On Aug 18, 11:47 pm, Meikel Brandmeyer [EMAIL PROTECTED] wrote:
 Dear vimming Clojurians,

 the first release of Chimp is available. It is similar to Limp, VILisp,
 fvl and the previously mentioned Slime-like plugin.

 Hopefully it provides more comfort out of the box. Current features:
 - send a visual block
 - send inner sexp
 - send outer sexp
 - send whole file
 - automatic namespace handling (based on some heuristics)

 The package obviously works on Unix and (with a few configuration steps)
 it should equally well work on Windows with Cygwin. However the latter
 is not very well tested.

 The homepage is:
    http://kotka.de/projects/chimp.html

 At vim.org:
    http://www.vim.org/scripts/script.php?script_id=2348

 The repository is:
    http://kotka.de/repositories/hg/chimp

 Extraction of sexps depends on the syntax highlighting of the latest
 release of VimClojure (v1.1.1).

 Any feedback is appreciated.

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



Re: First Release of Chimp available

2008-10-08 Thread Jonas Bengtsson

Hi,

Excellent, thanks!

It almost works now, however something fishy is going on when it tries
to launch screen from vim. I've done the following setting:
  :let g:chimp#ScreenCommand=/usr/bin/screen
which means that chimp.vim executes:
  call system('/usr/bin/screen -x 8844.chimp -X eval select 0
readbuf paste .')
but nothing happens. I've tried to run it manually from vim as well to
no avail. However, if I run the command in bash it just works so the
error seems to be in vim. I've tried to do the following in vim as
well, and it works so I know that vim can execute screen:
  :call system(/usr/bin/screen -list  screenlist)

Sorry for getting a bit OT but I'd really like to get this thing
working. If anyone has any idea I would very much appreciate it!

Cheers,
 Jonas

On Oct 8, 11:07 pm, Meikel Brandmeyer [EMAIL PROTECTED] wrote:
 Hello,

 Am 08.10.2008 um 23:16 schrieb Jonas Bengtsson:

  Trying to get Chimp running under cygwin. It seems like it depends on
  the following packages: vim, screen, util-linux (for getopt).

 I use it at work with a Windows vim and Cygwin screen. The idea is to
 start clojure with the chimp wrapper. This sets up the screen and starts
 the clojure REPL:
      chimp.sh -- rlwrap java -cp clojure.jar clojure.lang.Repl

 Or whatever you use to start your clojure. It should give a screen with
 a running REPL. At the bottom you get the so-called Chimp ID. This is
 used to contact the screen from Vim, which runs outside the screen.

 For a cygwin vim, it should actually work as is. For a Windows vim you
 maybe have to adjust the path to the temporary directory. I must
 confess, that I don't know my settings at work by heart. I will check
 tomorrow and provide my settings as an example.

 Hope this helps for the moment.

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