Re: Possible heisenbug in test suite (not in individual test runs) with memoization

2014-01-06 Thread Justin Kramer
Shot in the dark: check that arguments passed to your memoized functions 
use consistent typing. A BigDecimal such as 1M does not necessarily equal 1 
(a Long):

 (= 1 1M)
false
 (== 1 1M)
true

Your memoized functions could be recomputing values unnecessarily if you're 
giving them different types of numbers.

Justin

On Monday, January 6, 2014 12:57:49 PM UTC-5, David James wrote:

 I've got a Clojure test suite that fails when run as whole but passes when 
 run piecemeal. This just started happening. I've tested the code 
 thoroughly. The bug pops up in a part of the code that I did not change. 
 So, at present, it feels like a heisenbug!

 These may be some relevant pieces:
 * I'm using memoization; the failures happen in memoized functions.
 * I'm doing a lot of various precision BigDecimal math.

 Some tentative guesses:
 * Somehow one test is affecting another test

 Questions (there are speculative):
 * What are some possible ways that memoization might fail (e.g. return an 
 incorrect value)?
 * Is it possible that higher memory usage could cause memoization results 
 to get lost?

 Unfortunately, it is a sizable code base, and I don't have a small, 
 reproducible example. Any suggestions?

 -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/groups/opt_out.


Re: [ANN] Counterclockwise - Clojure plugin for Eclipse

2013-10-11 Thread Justin Kramer
Congratulations on the release, and thank you for your hard work! CCW is a 
great tool that makes my life easier.

Justin

On Thursday, October 10, 2013 9:36:01 AM UTC-4, Laurent PETIT wrote:

 Hi, a new version of Counterclockwise, the Clojure plugin for the 
 Eclipse IDE, has just been released. 

 Hot new features 
  
 - auto indentation as you type 
 - available as a Standalone Product: Download, Unzip, Code! 
 - many bug fixes including (hopefully) stability improvements 

 Install 
 = 
 - Software update site for installing into an existing Eclipse: 
 http://updatesite.ccw-ide.org/stable/ 

 Standalone product for: 
 - Windows 64 bits: 

 http://updatesite.ccw-ide.org/branch/master/master-0.20.0.STABLE001/products/ccw-win32.win32.x86_64.zip
  
 - Windows 32 bits: 

 http://updatesite.ccw-ide.org/branch/master/master-0.20.0.STABLE001/products/ccw-win32.win32.x86.zip
  
 - Linux 64 bits: 

 http://updatesite.ccw-ide.org/branch/master/master-0.20.0.STABLE001/products/ccw-linux.gtk.x86_64.zip
  
 - Linux 32 bits: 

 http://updatesite.ccw-ide.org/branch/master/master-0.20.0.STABLE001/products/ccw-linux.gtk.x86.zip
  
 - OS X 64 bits: 

 http://updatesite.ccw-ide.org/branch/master/master-0.20.0.STABLE001/products/ccw-macosx.cocoa.x86_64.zip
  

 Create a folder, unzip the product inside this folder, and double 
 click on the Counterclockwise executable! (only pre-requisite: Java 
 7 in your path) 

 Release Note 
 == 
 https://code.google.com/p/counterclockwise/wiki/ReleaseNotes#Version_0.20.0 


 Cheers, 


 -- 
 Laurent Petit 


-- 
-- 
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: Clojure in the Large style JDBC library

2013-09-06 Thread Justin Kramer
clojure.java.jdbc is transitioning to an API that uses explicit passing of 
db context - see e.g. the db-find-connection and query functions. The 
functions that look for a dynamically-scoped db are deprecated - 
e.g., find-connection, with-query-results.

Justin

On Friday, September 6, 2013 8:20:11 AM UTC-4, Jason Gilman wrote:

 It looks like java.jdbc would work since it offers the get-connection 
 function that returns a new connection that can be passed to most of the 
 functions that operate on the database. I'm still concerned by the 
 preponderance of functions with documentation like Executes SQL commands 
 on the open database connection. or Returns the current database 
 connection (or throws if there is none). It smells like there are vars 
 being held onto by the library that hold database connections or other 
 state. It could still work out if I'm careful about which functions I call. 

 What I'd really like is a library that returns some kind of context object 
 when it connects and all functions that operate on the database take that 
 context as an arguments. This is way more flexible, easier to test and fits 
 more in line with the style I was going for. I'm still curious if there are 
 other people out there who want use that same style and have to work with a 
 relational database. I'd like to know if they just accept that's the way 
 the libraries are written or if they have ways to get around it.




 On Fri, Sep 6, 2013 at 7:17 AM, Shantanu Kumar 
 kumar.s...@gmail.comjavascript:
  wrote:

 Hi Jason,

 Did you look at (URLs below) clojure/java.jdbc and HoneySQL? I'd be 
 interested to know if you are looking for anything different from these:

 http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html

 https://github.com/clojure/java.jdbc/

 https://github.com/jkk/honeysql

 Shantanu


 On Friday, 6 September 2013 16:28:09 UTC+5:30, Jason Gilman wrote:

 I've been trying to setup all my projects in the style Stuart Sierra 
 documented in Clojure in the 
 Largehttp://www.infoq.com/presentations/Clojure-Large-scale-patterns-techniques
  and My Clojure Workflow, 
 Reloadedhttp://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded.
  
 I've been trying to only use libraries that don't store any explicit 
 mutable state in vars. I've been having trouble finding a Clojure JDBC 
 library that does this. It seems like they all put the connection in some 
 kind of var or other area. I know I could just use the Java JDBC APIs 
 directly but I was hoping to avoid concatenating a bunch of SQL in my 
 Clojure and dealing with these lower level APIs. Does anyone have any 
 recommendations for Clojure libraries that might allow this? I'm also 
 wondering if there might be a Java library with a higher level API that 
 might allow this style. I'm betting other people have run into this issue 
 with relational databases and if they have any tips for how to avoid it. 
 (and yes I'm aware of Datomic :) )

  -- 
 -- 
 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 a topic in the 
 Google Groups Clojure group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/clojure/CpP0pr7bC-Y/unsubscribe.
 To unsubscribe from this group and all its topics, 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: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Justin Kramer
Besides post-processing results, you can also instruct java.jdbc to return 
Joda dates in the first place.

Using clojure.java.jdbc 0.3.0-alpha4:

(ns example
  (:require [clojure.java.jdbc :as j]
[clj-time.local :as cl]))
...
(extend-protocol j/IResultSetReadColumn
  java.sql.Date
  (result-set-read-column [date]
(cl/to-local-date-time date)))

Note that result-set-read-column's signature has changed in master; you'll 
need to update it to [date _ _] in the next release.

Justin

On Friday, July 5, 2013 4:59:54 PM UTC-4, Colin Yates wrote:

 Hi all,

 I think this is one of those questions which has quite a few answers, but 
 given a map, how do I replace the values by applying a function to those 
 values, but only if they meet a condition?

 I understand the building blocks of (map..), (filter..), (assoc-in..) and 
 (filter..) and I can see how something could work using those pieces but is 
 would be pretty verbose.  I am sure there is probably a much more simple 
 way using a more abstract function.

 The actual use case is I have a list of maps as returned from the 
 clojure.java.jdbc framework and they contain timestamps.  I want to replace 
 all the timestamps with (for example) to a Joda LocalDate using the 
 excellent clj-time library.

 Any pointers?

 Thanks!

 Col


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

2013-06-18 Thread Justin Kramer
As Rob mentioned, I won't be doing further development Loom anytime in the 
near future. However, if critical mass forms around a fork or alterate 
project, I'd be happy to add a prominent link in the readme.

Justin

On Tuesday, June 18, 2013 3:10:23 AM UTC-4, Stephen Kockentiedt wrote:

 My bad. I did only find the original repository of loom and thought it was 
 abandoned. I should have taken more care while looking at it. My approach 
 was apparently the same in abstracting multiple graph implementations under 
 one API. However, I see some problems with Loom's API, namely:

 1. The specifications of the protocol functions are very sparse. E.g., 
 which nodes shall a directed graph return from neighbors? Successors, 
 predecessors or both?
 2. How do I know if the graph implementation works by mutating the given 
 object or returning a new one?
 3. Loom assumes that every graph is editable. That is definitely not the 
 case.
 4. I think a protocol should be as easy to implement as possible. The 
 additional functionality can be given by functions relying on the protocol 
 functions. E.g., in the user API of my code, there is a function 
 direct-predecessors which provides this functionality (albeit slow) for 
 graph implementations which did not implement the corresponding protocol 
 function:

 (defn direct-predecessors
   Returns a set or sequence of all nodes n2 for which
(has-edge? g n2 n) returns true. May not contain
duplicates.
   [g n]
   (if (satisfies? p/PPredecessorGraph g)
 (p/direct-predecessors g n)
 (filter #(p/has-edge? g % n) (p/nodes g

 E.g., implementations of Loom's API need to provide two implementations of 
 neighbors and need to implement add-nodes* instead of only add-node*. 
 This may not be much more work to do. However, the easier the API, the more 
 implementations there will be.

 Please, don't get me wrong. I think that Loom is a great project, has the 
 same goals and, in terms of functionality, is way ahead of my efforts.

 Said all that, I definitely don't want there to be two competing graph 
 APIs. That would be counterproductive. I see the following possible 
 solutions:

 1. I keep the code to myself and let loom be the sole graph API.
 2. We transfer the advantages of my proposal to Loom and change its API. 
 Do you know of any implementations of the API outside Loom itself? If there 
 are none, this should be possible without much trouble. Also, the README 
 states that the API is alpha-stage.
 3. I publish my code and each API can be implemented in terms of the other 
 one. I'm not sure that this is possible in a simple way. Maybe each 
 protocol could be extended to java.lang.Object, which calls the protocols 
 of the other API, but I don't know if that is feasible.

 Please tell me what you think. I will also send Aysylu an email so that 
 she can chime in on the conversation.


 Am Dienstag, 18. Juni 2013 07:02:52 UTC+2 schrieb Rob Lachlan:

 Loom was indeed working on this, and it's a very nice library.  One thing 
 that I particularly liked about Justin's design, was the ability to run a 
 graph algorithm without worrying about conforming to a particular graph 
 representation.  See for example the bread first search function, here:

 https://github.com/jkk/loom/blob/master/src/loom/alg_generic.clj#L110

 All the bfs function requires is a neighbors function and and a start 
 vertex.  Simple and easy to use.

 Justin had said that he won't be actively developing loom for the 
 forseeable future; I was hoping to develop it further, but I only got as 
 far as implementing a max flow algorithm before the rest of my life got 
 in the way of my plans.  I know that Aysylu was doing a fair amount of work 
 on loom, so I'd guess that her repo is the most advanced one.

 Stephen:
 I think the set of protocols above is good, better than Loom's in fact; 
 notably, the decision to make direct-predecessors optional is the correct 
 one, and a lot of graph libraries get that wrong.  

 If you want to compare how loom did it:
 https://github.com/jkk/loom/blob/master/src/loom/graph.clj





 On Monday, June 17, 2013 1:14:34 PM UTC-7, dgrnbrg wrote:

 I think that there's already a project working on this called Loom. The 
 furthest-developed fork is here: https://github.com/aysylu/loom which 
 appears to have protocols for graphs, bindings to Titanium (the 
 Clojurewerkz graph DB library), visualization support, and implementations 
 of several algorithms.

 Maybe there's a way to incorporate these projects?

 On Monday, June 17, 2013 3:38:45 PM UTC-4, Stephen Kockentiedt wrote:

 Hello,

 I want to create a graph API similar to what core.matrix is for 
 matrices. I have created some protocols which every graph implementation 
 has to satisfy and a prototype implementation. Now I want your feedback on 
 these protocols. Which functions do you want to see which aren't there? 
 Which functions should be changed? Are there problems with the general 
 

Re: [ANN] Formative - render, parse, and validate web forms

2013-01-16 Thread Justin Kramer
Hi Bob,

Thanks for sharing your use case. One possible approach to fieldsets (among 
others) is to have the renderer split fields on e.g. :heading and put each 
group into a fieldset. Another would be to create a :fieldset field type 
that itself contains other fields. I've created a GitHub issue for this - 
https://github.com/jkk/formative/issues/4 - and plan on addressing it in 
the near future.

Separating the form buttons should be relatively easy with CSS - the 
default renderer spits out tons of classes for every piece of the form. You 
could also use :submit-label nil to turn off the submit button altogether 
and include your own as an :html type. There are various possibilities.

Justin

On Wednesday, January 16, 2013 8:35:54 AM UTC-5, hutch wrote:


 This is *really* interesting! I'll have a look at this more closely over 
 the next couple of days, but, really, the timing could not be better… you 
 might have just tipped a project I'm working on over to Clojure :-)

 It looks as though you've not put any kind of 'structure' on the fields… 
 they are 'flat'. For example, I don't see fieldsets. One of my projects has 
 its forms in two parts, the input fields which scroll (and have fieldsets) 
 and a second part that consists of things like the submit and cancel 
 buttons. The second part is pulled into a sidebar and fixed on the page 
 (doesn't scroll with the rest of the fields). These forms can be a bit long 
 (but they are a lot more usable than you'd think), so there's also an index 
 in the sidebar that on click moves the scrollable part to make the 
 corresponding fields come into view. In my current project these indexed 
 things aren't fieldsets but they could be. Alternatively, some other kind 
 of grouping structure could be used. Or possibly just a new field type that 
 created an index entry… I'll have a muck about and see what I can come up 
 with.

 Cheers,
 Bob


 Justin


 -- 
 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 javascript:
 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 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] Formative - render, parse, and validate web forms

2013-01-16 Thread Justin Kramer
So I went ahead and implemented the first solution I mentioned: the default 
renderer now groups fields into fieldsets, split by :heading and :submit 
fields. Each fieldset has a class that you can target with css/js. You can 
see the result in the demo - http://formative-demo.herokuapp.com/.

Justin

On Wednesday, January 16, 2013 8:35:54 AM UTC-5, hutch wrote:


 This is *really* interesting! I'll have a look at this more closely over 
 the next couple of days, but, really, the timing could not be better… you 
 might have just tipped a project I'm working on over to Clojure :-)

 It looks as though you've not put any kind of 'structure' on the fields… 
 they are 'flat'. For example, I don't see fieldsets. One of my projects has 
 its forms in two parts, the input fields which scroll (and have fieldsets) 
 and a second part that consists of things like the submit and cancel 
 buttons. The second part is pulled into a sidebar and fixed on the page 
 (doesn't scroll with the rest of the fields). These forms can be a bit long 
 (but they are a lot more usable than you'd think), so there's also an index 
 in the sidebar that on click moves the scrollable part to make the 
 corresponding fields come into view. In my current project these indexed 
 things aren't fieldsets but they could be. Alternatively, some other kind 
 of grouping structure could be used. Or possibly just a new field type that 
 created an index entry… I'll have a muck about and see what I can come up 
 with.

 Cheers,
 Bob


 Justin


 -- 
 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 javascript:
 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 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] Formative - render, parse, and validate web forms

2013-01-16 Thread Justin Kramer
Bob,

1) Because form specifications are data, it's pretty easy to build one up 
at runtime. One tool for mixins -- which I just noticed isn't documented 
in the readme -- is *formative.core/merge-fields*. It makes it easy to 
tweaks fields, or insert new fields before or after existing fields. 

2) Your approach sounds reasonable. Note that you can create your own :type 
with render-field and still use an existing :datatype; you don't 
necessarily have to implement parse-input. If the prepending/appending 
Bootstrap stuff is generalizable, it might be worth adding it to the 
default renderer. I don't actually use Bootstrap much myself so I'm open to 
improvements.

3) Right now only by using the :in validator. I've added an issue for that 
- https://github.com/jkk/formative/issues/6

Let me know how it goes. Feel free to add issues if you find any.

Justin

On Wednesday, January 16, 2013 1:32:21 PM UTC-5, hutch wrote:


 On 2013-01-16, at 11:31 AM, Justin Kramer jkkr...@gmail.com javascript: 
 wrote:

 So I went ahead and implemented the first solution I mentioned: the 
 default renderer now groups fields into fieldsets, split by :heading and 
 :submit fields. Each fieldset has a class that you can target with css/js. 
 You can see the result in the demo - http://formative-demo.herokuapp.com/.


 Heh, that was quick :-) Thanks!

 I don't suppose you've thought much about this situation: I've got a 
 couple of standard (what I'll call) mixin-forms that have fields and 
 validations that I 'mixin' to a form (once or not at all). They aren't 
 forms on their own, just a bunch of fields and validation rules. For 
 example, I have a standard way of describing an entity (name, title, 
 abbreviated description, full description, and a few other things). It's 
 possible to think of tabs this way as well. Dropdowns in a nav bar is 
 similar too, maybe. It's pretty clear how to get started on implementing 
 something like this, but I'm wondering if you've considered anything in 
 this regard.

 I've also got groups of several controls that operate together. The 
 bootstrap prepended and appended inputs are simple examples. These are to 
 some degree like the 'mixin' things I mentioned, but there can be more than 
 one of them and they need to be distinguished, and the validation might be 
 different for each or need to be extended for each instance. It looks to be 
 easy enough to do this by adding new field types (extending the 
 render-field and parse-input multimethods). Is that how you'd approach the 
 problem?

 While I think of it, do you provide a way to validate that a value 
 corresponds to one of the :options?

 Cheers,
 Bob


 Justin

 On Wednesday, January 16, 2013 8:35:54 AM UTC-5, hutch wrote:


 This is *really* interesting! I'll have a look at this more closely over 
 the next couple of days, but, really, the timing could not be better… you 
 might have just tipped a project I'm working on over to Clojure :-)

 It looks as though you've not put any kind of 'structure' on the fields… 
 they are 'flat'. For example, I don't see fieldsets. One of my projects has 
 its forms in two parts, the input fields which scroll (and have fieldsets) 
 and a second part that consists of things like the submit and cancel 
 buttons. The second part is pulled into a sidebar and fixed on the page 
 (doesn't scroll with the rest of the fields). These forms can be a bit long 
 (but they are a lot more usable than you'd think), so there's also an index 
 in the sidebar that on click moves the scrollable part to make the 
 corresponding fields come into view. In my current project these indexed 
 things aren't fieldsets but they could be. Alternatively, some other kind 
 of grouping structure could be used. Or possibly just a new field type that 
 created an index entry… I'll have a muck about and see what I can come up 
 with.

 Cheers,
 Bob


 Justin


 -- 
 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 post to this group, send email to clo...@googlegroups.com javascript:
 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your

[ANN] Formative - render, parse, and validate web forms

2013-01-15 Thread Justin Kramer
Formative is a library for dealing with web forms. Features:

   - Describe forms using simple data
   - Render forms via pluggable renderers (comes with Bootstrap and other 
   renderers built-in)
   - Parse submitted form data from Ring params
   - Validate parsed data using Verily https://github.com/jkk/verily(another 
new but less interesting lib)

A live demo can be seen at http://formative-demo.herokuapp.com/. Demo 
source: https://github.com/jkk/formative-demo

See the README for a usage guide and quick reference:

https://github.com/jkk/formative

It has seem some real-world usage, and I consider the API stable.

Feedback and contributions welcome.

Justin

-- 
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: Coding Standard - ns usage

2012-11-08 Thread Justin Kramer
Current best practice in my view:

For Clojure 1.4+, do not use :use at all. Use :require :refer 
(judiciously). :refer :all is almost never a good idea.

For Clojure 1.3 and below, :use :only is strongly encouraged. Bare :use is 
almost never good.

Justin

On Thursday, November 8, 2012 11:57:21 AM UTC-5, David McNeil wrote:

 I notice the following item at 
 http://dev.clojure.org/display/design/Library+Coding+Standards 

Be explicit and minimalist about dependencies on other packages. 
 (Prefer the :only option to use and require).

 The page was last edited on Mar 29, 2011 and ns usage has been discussed a 
 fair bit since then... this leads to the question: 

Is the item quoted above still the standard for Clojure Libraries?

 Thanks.
 -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: Coding Standard - ns usage

2012-11-08 Thread Justin Kramer
Sorry, yes, to clarify -- :require :as is always good and generally 
preferred over :refer or :use :only.

Justin

On Thursday, November 8, 2012 1:42:26 PM UTC-5, Luc wrote:

 I am pragmatic and quite lazy, I use require with an alias and use mostly 
 with stuff like 
  clojure.tools.trace, clojure.pprint where selecting explicit vars brings 
 no or little value (in my opinion). 
 You either need most of the public vars or the potential name conflict is 
 a remote 
 possibility a few light-years away. 

 I almost never select explicit vars from external name spaces. I find this 
 cumbersome to manage. 

 With (short) aliases, I get auto expansion of all public vars as soon as I 
 type the / 
 in CCW (Eclipse plugin). With a little consistency in choosing aliases, 
 it's then very easy to find out while reading the code where a reference 
 comes from. 

 I am also older than most of you guys so the less stuff resides in my 
 working memory, 
 the easier I can cheat with the slowly eroding aging process :) 
 I leave most of the work to the computer. 

 Mmmh, maybe I should create a pocket guide for elderly Clojure coders 
 someday... 

 Luc P. 

  Current best practice in my view: 
  
  For Clojure 1.4+, do not use :use at all. Use :require :refer 
  (judiciously). :refer :all is almost never a good idea. 
  
  For Clojure 1.3 and below, :use :only is strongly encouraged. Bare :use 
 is 
  almost never good. 
  
  Justin 
  
  On Thursday, November 8, 2012 11:57:21 AM UTC-5, David McNeil wrote: 
   
   I notice the following item at 
   http://dev.clojure.org/display/design/Library+Coding+Standards 
   
  Be explicit and minimalist about dependencies on other packages. 
   (Prefer the :only option to use and require). 
   
   The page was last edited on Mar 29, 2011 and ns usage has been 
 discussed a 
   fair bit since then... this leads to the question: 
   
  Is the item quoted above still the standard for Clojure Libraries? 
   
   Thanks. 
   -David 
   
  
  -- 
  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 
 -- 
 Softaddictslprefo...@softaddicts.ca javascript: sent by ibisMail from 
 my ipad! 


-- 
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: `CompilerException` raised when running `Monger` code snippet

2012-11-08 Thread Justin Kramer
Yours is not actually the same as the one from Monger. Hint: you're missing 
an important character that prevents def from being called.

Justin

On Thursday, November 8, 2012 10:22:39 PM UTC-5, Satoru Logic wrote:

 Hi, all.

 When I try to run the following `macro` in `lein repl` (with clojure1.3 
 and clojure1.4):

(defmacro ^{:private true} defoperator 
[operator] (def ^{:const true} ~(symbol (str operator)) ~(str 
 operator)))

 But a `CompilerException` is raised:

CompilerException java.lang.RuntimeException: First argument to def 
 must be a Symbol, compiling:(NO_SOURCE_PATH:3)

 I found this `macro` in the source code of `Monger`, so I guess it should 
 be a valid `macro`, maybe this can't be run in `repl`?


-- 
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: Correct usage of data-readers

2012-10-16 Thread Justin Kramer
On Tuesday, October 16, 2012 9:07:49 AM UTC-4, Stuart Sierra wrote:

 - is it appropriate to include data_readers.clj in a library - given that 
 file is in the root?

 No. data_readers.clj is intended for application developers. Libraries may 
 define data reader functions and suggest tags for consumers of that library.
  


Really? So take the ordered library as an example:

https://github.com/flatland/ordered

It defines #ordered/map and #ordered/set. That's not proper usage?

If using data_readers.clj is truly discouraged for libs, that should be 
documented - perhaps in 
http://dev.clojure.org/display/design/Library+Coding+Standards? I can 
update it myself once I understand the rationale.

Justin

-- 
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: Correct usage of data-readers

2012-10-15 Thread Justin Kramer
Hi Dave,

The conflicting reader issue is fixed in the Clojure 1.5 master branch.

Using data readers in a lib is perfectly acceptable as long as you 
namespace qualify your tags, as the docs mandate: Reader tags without 
namespace qualifiers are reserved for Clojure. See (doc *data-readers*). 
This allows libs to get along with each other. Clojure will look for all 
data_readers.clj files on the classpath.

If I recall correctly, built-in base64 encoding is planned. Don't quote me 
on that, though.

Justin

On Monday, October 15, 2012 7:55:23 AM UTC-4, Dave Sann wrote:

 Hi all,

 Are there any solid docs/ideas for effective usage of data-readers and 
 data_readers.clj?

 Currently, as I understand it data_readers.clj is placed in the root src 
 folder for a project.

 This worked nicely, however, I do get an error with lein giving 
 conflicting readers if I have data_readers.clj in a jar and then in the 
 same lib in checkouts. Is this expected? Am I doing this wrong?

 - is it appropriate to include data_readers.clj in a library - given that 
 file is in the root?
 - is it the intention that a project will define all of its readers and 
 not expect any from library sources? How will I know which ones to use?
 - what is the correct usage of *data-readers*? Is this perhaps preferred?

 A thought - There may be lots of readers produced by different people and 
 some kind of order may need to be maintainable to avoid possible reader 
 hell of conflicts or possible incompatibilities. 

 Readers do not appear to have namespaces so should I prefix my readers if 
 I want to ensure that they are unique?

 Is there a list of readers that should be added or considered for addition 
 to a standard set? The one I made was b64 encoding for byte arrays - which 
 would seem like an obvious one.

 Thanks for any pointers

 Dave




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

Re: edn

2012-09-06 Thread Justin Kramer
Looks great. What mime type should be used? application/edn?

Justin

On Thursday, September 6, 2012 9:01:15 PM UTC-4, Rich Hickey wrote:

 I've started to document a subset of Clojure's data format in an effort to 
 get it more widely used as a data exchange format, e.g. as an alternative 
 to JSON. 

 Please have a look: 

 https://github.com/richhickey/edn 

 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: ANN: ClojureSphere updated

2012-09-03 Thread Justin Kramer
Michael,

I actually think it's a project.clj parsing issue. Midje's is a little 
non-standard looking. I've opened an issue for it.

Thanks for the feedback and report,

Justin

On Monday, September 3, 2012 2:15:28 AM UTC-4, Michael Klishin wrote:

 2012/9/3 Justin Kramer jkkr...@gmail.com javascript:

 ClojureSphere has been updated with a new domain, refreshed index, and 
 some new features:

 http://www.clojuresphere.com/


 Justin,

 The new version looks great!

 I have noticed that ClojureSphere points to a fork of the Midje repository 
 at
 https://github.com/bmabey/Midje
  while the canonical repository is https://github.com/marick/Midje.

 Is it a data aggregation issue or it actually tries to cover all the forks?
 -- 
 MK

 http://github.com/michaelklishin
 http://twitter.com/michaelklishin

  

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

2012-09-02 Thread Justin Kramer
ClojureSphere has been updated with a new domain, refreshed index, and some 
new features:

http://www.clojuresphere.com/

ClojureSphere lets you browse the dependency graph of the open source 
Clojure ecosystem.

The dependency information is provides now is slightly more accurate and 
useful. There's also an API: http://www.clojuresphere.com/api

Ideas and contributions welcome: https://github.com/jkk/clojuresphere

Justin

-- 
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: Destructuring can create structure..?

2012-08-28 Thread Justin Kramer
Vector-as-map destructuring makes sense when you consider that vectors are 
associative: they map index to value.

(let [{a 1 b 3 :as c} [:a 1 :b 2]] [a b c])
= [1 2 [:a 1 :b 2]]

Justin

On Tuesday, August 28, 2012 8:30:58 AM UTC-4, Douglas Orr wrote:

 One possibly confusing titbit I came across recently relates to how 
 Clojure handles destructuring of variable-length argument lists. The 
 essence is that the destructuring form can appear to influence the 'shape' 
 of the collection of arguments. Here is what I mean:

 take nothing off the head of the vector, then put all remaining elements 
 into a vector c:

 user= (let [[ [:as c]] [:one one :two two]] (seq c))
 (:one one :two two)


 take nothing off the head of the vector, then put all remaining elements 
 into a map c:

 user= (let [[ {:as c}] [:one one :two two]] (seq c))
 ([:one one] [:two two])


 Notice how the structure of 'c' has changed due to the destructuring form, 
 even though in both cases it refers to the whole collection. Digging down 
 into this a bit, it looks like this depends on the type of the collection 
 being destructured:

 user= (let [{:as c} [:one one :two two]] (seq c))
 (:one one :two two)

 user= (let [{:as c} (seq [:one one :two two])] (seq c))
 ([:one one] [:two two])


 I can see why this is necessary for multiple-args destructuring to work, 
 but I think my small mind finds this 'automatic marshalling' of 
 lists-or-seqs into maps a bit confusing. Maybe my only real problem is the 
 destructuring of vectors as maps, which somewhat 'works' in the above 
 example, but isn't really consistent. Any thoughts?


-- 
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: Anybody interested in a Clojure Group in Rochester, NY?

2012-04-03 Thread Justin Kramer
Hi Jeremy,

There's a RocLisp group that meets once in a while (next meeting TBD). 
We've been focussing on Clojure so far.

http://roclisp.org/
https://github.com/roclisp
Twitter: @roclisp

I myself am pretty nuts about Clojure. Looking forward to meeting and 
hacking with you,

Justin
@jkkramer

On Tuesday, April 3, 2012 3:28:58 PM UTC-4, Jeremy Heiler wrote:

 I am wondering if anybody in (or near) Rochester, NY would be interested 
 in forming a Clojure Group? I would like to think that there's more than 
 just me hacking on Clojure in the area! 


-- 
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: Precondition asserts in macros

2012-03-20 Thread Justin Kramer
Another option: create a helper function to do the work and have the macro 
call that:

(defn foo* [bar body-thunk]
  {:pre [(string? bar)]}
  (body-thunk)) ;or whatever

(defmacro foo [bar  body]
  `(foo* ~bar (fn [] ~@body))

Justin

On Tuesday, March 20, 2012 9:07:45 AM UTC-4, Chas Emerick wrote:

 Your second `foo` call fails in 1.2 as well.  If there was ever a time 
 when it would have succeeded, it would have been a bug.  Since `foo` is a 
 macro, it receives its arguments unevaluated, so `(str baz 34)` will 
 always be received as a list of three values.

 The syntax-quote precondition simply expands into a list containing the 
 symbol 'clojure.core/string? and the value of bar; this is a logically-true 
 value, and so does not trigger any error.

 You want something like:

 (defmacro foo
  [bar  body]
  `(let [bar# ~bar]
 (when-not (string? bar#) (IllegalArgumentException. msg))
 ...))

 - Chas

 On Mar 20, 2012, at 8:34 AM, Shantanu Kumar wrote:

  Hi,
  
  The way preconditions are invoked in Clojure 1.3.0 seems to have
  changed since Clojure 1.2:
  
  (defmacro foo
   [bar  body]
   {:pre [(string? bar)]}
   ...)
  
  (foo bar34 ...)  ; doesn't complain, which is OK
  (foo (str baz 34) ...)  ; Error! (I wanted this to pass)
  
  When I write the precondition like this:
  
   {:pre [`(string? ~bar)]}
  
  It doesn't seem to check the precondition at all in 1.3.0.
  
  Can somebody suggest me what am I missing? I want both the examples
  above to be verified and passed as OK.
  
  Shantanu
  
  -- 
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with 
 your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en



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

Re: Clojure 1.3 treatment of integers and longs

2011-10-20 Thread Justin Kramer
Here's a quick proof using an interface-based primitive detector:

(definterface IPrimitiveTester
  (getType [^int x])
  (getType [^long x])
  ;; other types elided
  )

(deftype PrimitiveTester []
  IPrimitiveTester
  (getType [this ^int x] :int)
  (getType [this ^long x] :long)
  ;; other types elided
  )

(defmacro primitive-type [x]
  `(.getType (PrimitiveTester.) ~x))

(comment

  user= (primitive-type 5) ;unboxed
  :long
  user= (primitive-type (Integer/parseInt 5)) ;unboxed
  :int
  user= (class (Integer/parseInt 5)) ;boxed
  java.lang.Long

  )

Justin

-- 
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.3 treatment of integers and longs

2011-10-20 Thread Justin Kramer
Oops, I elided a little too much. Need a method with an Object signature to 
distinguish Integer from int:

(definterface IPrimitiveTester
  (getType [^int x])
  (getType [^long x])
  ;; etc
  (getType [^Object x]))

(deftype PrimitiveTester []
  IPrimitiveTester
  (getType [this ^int x] :int)
  (getType [this ^long x] :long)
  ;; etc
  (getType [this ^Object x] :object))

(defmacro primitive-type [x]
  `(.getType (PrimitiveTester.) ~x))

(comment

  user= (primitive-type (Integer. 5))   
  :object
  user= (primitive-type (Integer/parseInt 5))
  :int

  )


On Thursday, October 20, 2011 1:13:03 PM UTC-4, Justin Kramer wrote:

 Here's a quick proof using an interface-based primitive detector:

 (definterface IPrimitiveTester
   (getType [^int x])
   (getType [^long x])
   ;; other types elided
   )

 (deftype PrimitiveTester []
   IPrimitiveTester
   (getType [this ^int x] :int)
   (getType [this ^long x] :long)
   ;; other types elided
   )

 (defmacro primitive-type [x]
   `(.getType (PrimitiveTester.) ~x))

 (comment

   user= (primitive-type 5) ;unboxed
   :long
   user= (primitive-type (Integer/parseInt 5)) ;unboxed
   :int
   user= (class (Integer/parseInt 5)) ;boxed
   java.lang.Long

   )

 Justin


-- 
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: [Clojuresphere] How do I filter out past dependents?

2011-10-02 Thread Justin Kramer
Not currently. That and a number of other features are in the queue.

Justin

On Sunday, October 2, 2011 12:45:44 AM UTC-4, Daniel wrote:

 Say I want to get a full list of _current_ dependents for clojure-1.2 
 or contrib, for upgrade purposes ... is there currently a way to do 
 that on Clojuresphere?

-- 
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: aquamacs, slime and clojure on OS X

2011-09-23 Thread Justin Kramer


   * install Leiningen
   * install the swank-clojure plugin: lein plugin install swank-clojure 
 1.3.2
   * install clojure-mode (you can do this from git)
   * navigate to a project and do M-x clojure-jack-in

 That's all it takes. It might work with Aquamacs, but since that fork
 is not portable it's impossible for me to test on it. So GNU Emacs is
 recommended.

For what it's worth, I use this setup with Aquamacs and everything works 
perfectly.

Justin

-- 
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: Casting numbers to ints

2011-09-19 Thread Justin Kramer
Here's a fleshed-out version that tests for any type of primitive:

(definterface IPrimitiveTester
  (getType [^int x])
  (getType [^long x])
  (getType [^float x])
  (getType [^double x])
  (getType [^byte x])
  (getType [^short x])
  (getType [^char x])
  (getType [^boolean x])
  (getType [^Object x]))

(deftype PrimitiveTester []
  IPrimitiveTester
  (getType [this ^int x] :int)
  (getType [this ^long x] :long)
  (getType [this ^float x] :float)
  (getType [this ^double x] :double)
  (getType [this ^byte x] :byte)
  (getType [this ^short x] :short)
  (getType [this ^char x] :char)
  (getType [this ^boolean x] :boolean)
  (getType [this ^Object x] :object))

(defmacro primitive-type [x]
  `(.getType (PrimitiveTester.) ~x))

(defmacro primitive? [x]
  `(not= :object (primitive-type ~x)))

(comment

  ;; Clojure 1.2

  (primitive? 1) ;= false
  (primitive-type 1) ;= :object
  (primitive? (Math/pow 2 2)) ;= true
  (primitive? (* 2 (Math/pow 2 2))) ;= false

  ;; Clojure 1.3
  
  (primitive? 1) ;= true
  (primitive-type 1) ;= :long
  (primitive? (Math/pow 2 2)) ;= true
  (primitive? (* 2 (Math/pow 2 2))) ;= true
  
  )

-- 
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: ClojureSphere - browse the Clojure ecosystem

2011-09-06 Thread Justin Kramer
Prompted by a question on IRC a couple days ago, I built a tool that allows 
you to browse the dependency graph of Clojure projects from GitHub  
Clojars:

http://clojuresphere.herokuapp.com/

You can see dependencies of a project, but also projects which depend on it. 
You can also see how many projects depend on a specific version (combined 
current  historical usage).

There are caveats, which you can read about on 
GitHub: https://github.com/jkk/clojuresphere

If anyone is interested in having this sort of thing added to Clojars, 
ClojureDocs, or other community sites, let me know.

Justin

-- 
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: ClojureSphere - browse the Clojure ecosystem

2011-09-06 Thread Justin Kramer
Thanks, glad you like it.

Note that dependents are listed for an artifact ID (clojure-contrib) when 
any version of the dependent depends on any version of that artifact ID. So 
some of those libs may have already migrated to the new clojure contrib 
libs. Clicking a version will show which specific versions are dependent:

http://clojuresphere.herokuapp.com/clojure-contrib/org.clojure/1.2.0

Will probably make some changes to clarify that...

Justin

On Tuesday, September 6, 2011 7:03:23 PM UTC-4, Sean Corfield wrote:

 On Tue, Sep 6, 2011 at 8:17 AM, Justin Kramer jkkr...@gmail.com wrote:
  Prompted by a question on IRC a couple days ago, I built a tool that 
 allows
  you to browse the dependency graph of Clojure projects from GitHub 
  Clojars:
  http://clojuresphere.herokuapp.com/

 This is very cool Justin!

 I see that clojure.contrib has about 1,400 projects that depend on
 it... all of which need to be migrated to the new, modular contrib
 libraries at some point! :)

 http://clojuresphere.herokuapp.com/clojure-contrib
 -- 
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)



-- 
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: Non-binary tree?

2011-08-19 Thread Justin Kramer
There are many ways one could model a tree/graph:

;; collection of edges
[[:a :b] [:b :c] [:b :d] [:c :e] [:d :e]]

;; adjacency list
{:a [:b] :b [:c :d] :c [:e] :d [:e]}

If you're looking for a pre-made solution, the loom graph library 
(https://github.com/jkk/loom) may work:

(ns example
  (:use [loom.graph :only [digraph]]
[loom.alg :only [shortest-path]]))

(def dg (digraph {:a [:b] :b [:c :d] :c [:e] :d [:e]}))

(shortest-path dg :a :e)
; = (:a :b :c :e)

-- 
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: Non-binary tree?

2011-08-19 Thread Justin Kramer
I'm not sure if I'm addressing your needs exactly, but if you want to turn 
an adjacency list into a nested structure, here's one way:

(def adj {:a [:b] :b [:c :d] :c [:e] :d [:e]})

(defn build-tree [adj from to]
  {:name from
   :children (when (not= from to)
   (map #(build-tree adj % to) (adj from)))})

(build-tree adj :a :e)

Here each node is a map with keys :name and :children. Leaves are nodes with 
empty/nil :children. This doesn't handle cycles, of course.

Justin

On Friday, August 19, 2011 11:15:36 AM UTC-4, Ulrik Sandberg wrote:

 Thanks. That looks very interesting. 

  ;; adjacency list 
  {:a [:b] :b [:c :d] :c [:e] :d [:e]} 

 For some reason, I have trouble constructing this recursively. I seem 
 to always end up with something like this: 

 user (build-tree :a :e) 
 (:a (:b (:c (:e)) (:d 
 (:e 

 (defn build-tree [from to] 
   (cons from 
 (for [c (candidates from to)] 
   (build-tree c to 

 I have a start key (:a) and an end key (:e). For each key, I can get 
 candidates: 

 user (candidates :a :e) 
 (:b) 
 user (candidates :b :e) 
 (:c :d) 
 user (candidates :c :e) 
 (:e) 
 user (candidates :d :e) 
 (:e) 
 user (candidates :e :e) 
 () 


 On 19 Aug, 16:12, Justin Kramer jkkr...@gmail.com wrote: 
  There are many ways one could model a tree/graph: 
  
  ;; collection of edges 
  [[:a :b] [:b :c] [:b :d] [:c :e] [:d :e]] 
  
  ;; adjacency list 
  {:a [:b] :b [:c :d] :c [:e] :d [:e]} 
  
  If you're looking for a pre-made solution, the loom graph library 
  (https://github.com/jkk/loom) may work: 
  
  (ns example 
(:use [loom.graph :only [digraph]] 
  [loom.alg :only [shortest-path]])) 
  
  (def dg (digraph {:a [:b] :b [:c :d] :c [:e] :d [:e]})) 
  
  (shortest-path dg :a :e) 
  ; = (:a :b :c :e)

-- 
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: Non-binary tree?

2011-08-19 Thread Justin Kramer
Here's another way, which constructs a sequence of edges using candidates, 
which are then fed into reduce to build an adjacency list.

(defn candidates-edges [candidates from to]
  (when-let [kids (seq (candidates from to))]
(concat (for [k kids] [from k])
(mapcat #(get-edges candidates % to) kids

(defn edges-adj [edges]
  (reduce
   (fn [adj [a b]]
 (update-in adj [a] conj b))
   {} edges))

(edges-adj (candidates-edges candidates :a :e))
; = {:d (:e), :c (:e), :b (:d :c), :a (:b)}

This doesn't handle cycles.

Justin

-- 
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: Non-binary tree?

2011-08-19 Thread Justin Kramer
Oops, renamed the function: get-edges = candidates-edges.

Justin

On Friday, August 19, 2011 4:03:27 PM UTC-4, Ulrik Sandberg wrote:

 And get-edges? 

 On 19 Aug, 20:52, Justin Kramer jkkr...@gmail.com wrote: 
  Here's another way, which constructs a sequence of edges using 
 candidates, 
  which are then fed into reduce to build an adjacency list. 
  
  (defn candidates-edges [candidates from to] 
(when-let [kids (seq (candidates from to))] 
  (concat (for [k kids] [from k]) 
  (mapcat #(get-edges candidates % to) kids 
  
  (defn edges-adj [edges] 
(reduce 
 (fn [adj [a b]] 
   (update-in adj [a] conj b)) 
 {} edges)) 
  
  (edges-adj (candidates-edges candidates :a :e)) 
  ; = {:d (:e), :c (:e), :b (:d :c), :a (:b)} 
  
  This doesn't handle cycles. 
  
  Justin

-- 
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 a map algorithmically

2011-08-10 Thread Justin Kramer
See also David Nolan's post:

http://dosync.posterous.com/lispers-know-the-value-of-everything-and-the

Justin

On Tuesday, August 9, 2011 6:02:00 PM UTC-4, pmbauer wrote:

 For the sieve, if performance matters, clojure's native data structures may 
 not be the best choice.
 A mutable array of boolean primitives could be more apropos.

 (defn prime-sieve [^long n]
   (let [^booleans sieve (make-array Boolean/TYPE (inc n))]
 ...)

 ... using aset/aget to write/read sieve.

 On Tuesday, August 9, 2011 1:18:46 PM UTC-7, Chouser wrote:

 On Tue, Aug 9, 2011 at 12:50 PM, Kevin Sookocheff
 kevin...@gmail.com wrote:
  Hi,
 
  I have a question regarding the map data structure. I'm trying to 
 program a
  Sieve of Eratosthenes using the algorithm at Wikipedia:
 
  Input: an integer n  1
 
  Let A be an array of bool values, indexed by integers 2 to n,
  initially all set to true.
 
  for i = 2, 3, 4, ..., while i^2 ≤ n:
if A[i] is true:
  for j = i^2, i^2 + i, i^2 + 2i, ..., while j ≤ n:
A[j] = false
 
  Now all i such that A[i] is true are prime.
 
  I'm having a problem creating the data structure A.
 
  What I want to do is create a map of integers from 2 to n all 
 initialized to
  true that I can then prune using the algorithm.
 
  Any ideas?

 Since the keys are consecutive integers, you might consider a vector
 of booleans:

 (def A (vec (repeat (inc n) true)))

 You can then use assoc to set any particular index to false:

 (assoc A 5 false)

 Differences using a vector instead of a hash-map: will stay in numeric
 order, doesn't allow arbitrary dissoc, nth and assoc may be faster,
 use less memory, (vector-of :bool) will definitely use less memory,
 and probably others.  Depending on your goals, a vector may or may not
 be preferable to a hash-map.

 --Chouser



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
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: Translating Java code with nested for loops

2011-06-28 Thread Justin Kramer
Here's one way.

(defn tails [coll]
  (take-while seq (iterate rest coll)))

(defn calc [total-values daily-values]
  (map * daily-values (for [tail (tails total-values)]
(reduce #(* %1 (inc (/ %2 100.0)))
1.0
(rest tail)

In translating it, I first tried to visualize the algorithm[1]. Then I
transcribed that visualization into the usual suspects: map/for,
reduce, filter. Having a solid grasp of each of those -- not to
mention the rest of clojure.core -- is very helpful.

[1] http://i.imgur.com/XDZhm.png (crude drawing of the first step)

Hope that helps,

Justin

On Jun 28, 8:20 pm, Bhinderwala, Shoeb
sabhinderw...@wellington.com wrote:
 Hi

 I have been learning clojure for some time but am a bit stumped when
 translating code with nested for loops.

 Can someone help me to translate the following java code to clojure
 elegantly:

 The inputs are two arrays of type double of the same length -
 dailyValues and totalValues. The output is the array contrib of the same
 length.

         int n = dailyValues.length;

         for (int i = 0; i  n; i++)
         {
             sum = 1.0;
             for (int j = i + 1; j  n; j++)
             {
                 sum *= (1.0 + (totalValues[j] / 100.0));
             }

             contrib[i] = sum * dailyValues[i];
         }

 Many thanks for your help.

 -- Shoeb

-- 
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: Ok, so code is data...

2011-05-09 Thread Justin Kramer
'read' and 'read-string' are what you're looking for. They each read a
single Clojure object from an input source (PushbackReader for read,
String for read-string).

Alternatively, something like this can read all top-level forms from a
file:

(defn read-all
  Reads all top-level forms from f, which will be coerced by
  clojure.java.io/reader into a suitable input source. Not lazy.
  [f]
  (with-open [pbr (java.io.PushbackReader. (clojure.java.io/reader
f))]
(doall
 (take-while
  #(not= ::eof %)
  (repeatedly #(read pbr false ::eof))

(read-all /some/clojure/file.clj)
= ((foo :bar) (baz))

Justin

On May 9, 11:36 pm, Bill Robertson billrobertso...@gmail.com wrote:
 How do I actually manipulate it?  I have some complicated logic that I
 would like to transform into html (or maybe xml) for display
 purposes.

 I'm generating the Clojure code by parsing some nasty Java and
 outputting s-expressions.  The Java is basic, but quite deeply
 nested.  I want to generate working Clojure to demonstrate what that
 can do for us, and get this nastiness documented of course.

 Other than going into the source files and transforming it by hand
 into a series of defs and quoted lists e.g.  (def my_func '(+ 1 2))
 How do I actually just load code w/o evaluating it?

 I've found the pretty printer macros, seems like that might be useful
 if I wanted to statically transform the code.  I found the walker,
 that looks like it might be useful in actually generating the output
 (e.g. visit things, spit out (x|ht)ml.

 I looked at the various load functions in clojure.core.  With the
 exception of load (http://clojure.github.com/clojure/clojure.core-
 api.html#clojure.core/load) they all seem to load and evaluate.  Is
 load the answer or is it something I haven't found yet?

 Once I get the code loaded, I don't think I need anything out of the
 ordinary like macros or multi-methods.  I think I can just manipulate
 the lists.  Does that sound correct?

 I'm sorry if this are a stupid questions, but I've never done anything
 in Clojure of any significance, and any helpful answers you provide
 would could save me days of stumbling about.

 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: closed maps / reducing runtime errors due to mistyped keywords

2011-04-22 Thread Justin Kramer
I should be straightforward to implement a closed map (or record)
yourself using deftype. It could implement all the same interfaces as
Clojure's built-in maps, ensuring compatibility with assoc and such.
Here's an example of a map variant implemented using deftype:

https://github.com/clojure/clojure-contrib/blob/master/modules/priority-map/src/main/clojure/clojure/contrib/priority_map.clj

Justin

On Apr 22, 1:44 am, Christian Schuhegger
christian.schuheg...@gmail.com wrote:
 I am taking up a discussion from 
 2010:https://groups.google.com/group/clojure/browse_frm/thread/60dff89149c...

 I would prefer if it would be possible to define closed maps, e.g.
 maps that allow only a certain set of keywords, both for get and
 set (like in assoc, assoc-in, update-in, ...). It would be nice if
 there would be an option on defrecord to mark the map as closed.

 I imagine that this would have some runtime penalty, because for every
 access it has to be verified if the key is a valid one. I understand
 that. Perhaps in that case the language could react differently based
 on the value of a dynamic var (*check-closed-defrecrod-p*) that can be
 set when the unit tests are run and could be false by default.

 I guess this topic was already discussed several times. Could somebody
 point me to previous discussions and their outcome?
 I've found in addition the following thread where the idea of safe
 maps was discussed to some 
 extent:https://groups.google.com/group/clojure/browse_frm/thread/134642cc76d...

 Thanks,
 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: examples in doc strings

2011-04-08 Thread Justin Kramer
Another option is to create a function which pulls examples from
clojuredocs.org on the fly (it has an API) and displays them in the
REPL. I made a proof-of-concept for this but using the now-defunct
Clojure Examples Wiki: https://gist.github.com/470031.

The utility of something like this would be limited if it wasn't
included in clojure.core, of course.

Justin


On Apr 8, 9:27 am, Jeff Rose ros...@gmail.com wrote:
 Yeah, I've got a permanent clojuredocs tab open all the time, but
 still it would be nice to settle this discussion, as currently their
 are doc strings that require a google search or a look at the source
 to see what they mean though, which is not ideal.  Many of us are
 happy to help if we can have a place to direct our energy.
 Using :examples metadata (or even having the examples somewhere on
 contrib) would be fine, as long as they can show up on the repl and in
 tools when you run (doc fn).

 -Jeff

 On Apr 8, 2:18 pm, Meikel Brandmeyer m...@kotka.de wrote:







  Hi,

  it was discussed before whether examples should go into the docstring.
  Or to an :examples metadata to be even executable at the repl. Some
  expressed the opinion that docstring should be short and that such
  additional documentation should go somewhere else. I don't remember
  what the outcome of the discussion was.

  Until this discussion is settled this site might help to scratch your
  itch:http://clojuredocs.org/clojure_core/clojure.core/defmethod. And
  you can help out there easily without CA and such.

  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


Re: Are there sets that keep the insertion order?

2011-03-07 Thread Justin Kramer
https://github.com/ninjudd/ordered-set

Justin

On Mar 7, 1:14 pm, Tassilo Horn tass...@member.fsf.org wrote:
 Hello all,

 does clojure have sets that keep the insertion order, like Java's
 LinkedHashSet?

 Currently, I use lazy vectors in conjunction with `distinct', but that
 seems to perform not too well.

 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: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Justin Kramer
'for' can be handy when unpacking compound lines:

(ns foobar
  (:require [clojure.java.io :as io]))

(defn parse-acl [acl-file]
  (with-open [r (io/reader acl-file)]
(apply
 merge-with into
 (for [[status users path] (map #(.split % \\|) (line-seq r))
   :when (= avail status)
   user (.split users ,)]
   {user [path]}

Justin

On Mar 3, 9:15 pm, Stefan Rohlfing stefan.rohlf...@gmail.com wrote:
 Dear Clojure Group,

 I am currently reading the online book Pro Git http://progit.org/book/. In
 chapter 7.4 http://progit.org/book/ch7-4.html (section “Enforcing a
 User-Based ACL System”) there is a task of reading in an access control list
 (ACL) file, such as the following

 # avail/unavail | users | path
 avail|nickh,pjhyett,defunkt,tpw
 avail|usinclair,cdickens,ebronte|doc
 avail|schacon|lib
 avail|schacon|tests

 and printing out a map of the form { user1 [path 1, path 2], user2
 [path2, path3] ...}.

 The author of the book provides a solution in Ruby, which I find relatively
 easy to follow, despite not having written any Ruby code before:

 def get_acl_access_data(acl_file)
  # read in ACL data
  acl_file = File.read(acl_file).split(\n).reject { |line| line == '' }
  access = {}
  acl_file.each do |line|
    avail, users, path = line.split('|')
    next unless avail == 'avail'
    users.split(',').each do |user|
      access[user] ||= []
      access[user]  path
    end
  end
  access
 end

 I then tried the same in Clojure, but found my solution to be much less
 readable compared to the Ruby code:

 (use '[clojure.string :only (split)])

 (defn get-acl-access-data [file]
  (let [acl (split (slurp file) #\n)]
    (apply merge-with #(into %1 %2)
              (map (fn [[avail users path]]
                          (let [users (split users #,)]
                             (reduce (fn [acc user]
                                             (when (= avail avail)
                                               (assoc acc user [path])))
                                            {} users)))
                        (map #(split % #\|) acl)

 ;; Output:
 ;; {schacon [lib tests],
 ;;  usinclair [doc],
 ;;  cdickens [doc],
 ;;  ebronte [doc],
 ;;  tpw [nil],
 ;;  defunkt [nil],
 ;;  pjhyett [nil],
 ;; nickh [nil]}

 Maybe it is just because I am an ambitious beginner at best, but I am afraid
 I won’t be able to figure out immediately what this code is doing in a few
 weeks.

 However, there probably is a better way of translating the Ruby version into
 Clojure. With better I mean easier to follow. My main goal is on clarity,
 as I often struggle organizing my code in a way I would consider readable.

 I therefore would be glad for any ideas of improvement. Any suggestions are
 highly welcome!

 Best regards,

 Stefan

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


Re: Help writing a simple destructuring function.

2011-02-07 Thread Justin Kramer
Checking out clojure.core/destructure and clojure.core/let might be
helpful.

Here's a macro I hacked together. It doesn't work with :keys, :as,
or :or. I take no responsibility if you use it for anything real. But
maybe it will provide you with some ideas.

(defmacro destructure-map
  [bvec val]
  `(let [~bvec ~val]
 (- {}
 ~@(for [s (remove #(= ' %) (flatten bvec))]
 `(assoc (- (quote ~s) name keyword) ~s)

Example:

(let [v [1 2 [3 4 5 6 7 8]]]
  (destructure-map [a b [c d  e]] v))
= {:e (5 6 7 8), :d 4, :c 3, :b 2, :a 1}


Justin

On Feb 7, 10:49 am, CuppoJava patrickli_2...@hotmail.com wrote:
 Hello everyone,

 I am trying to write the following function:

 ---

 Suppose form = [1 2 [3 4 5 6 7 8]]

 (destructure '(a b (c d  e))  form)

 should return:

 {:a 1 :b 2 :c 3 :d 4 :e [5 6 7 8]}

 

 Now this is not too difficult of a function to write from scratch. BUT
 it really looks like I should be able to piggy-back off the existing
 functionality in the destructuring-let macro. But I cannot figure out
 how I can do that without using eval. I'm not sure if it's even
 possible.

 Does anyone know if it's possible to implement this function in terms
 of let and without using eval? Thank you very much for your help!
   -Patrick

-- 
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: Help with java conversion

2011-01-21 Thread Justin Kramer
If you're setting values in an array, use aset:

(dotimes [i number]
  (aset strip i (.createCompatibleImage gc width height transparency))
  ...)

If you want to get a value, use aget:

(let [stripGC (.createGraphics (aget strip i))]
  ...)

Hope that helps,

Justin

On Jan 21, 11:07 am, WoodHacker ramsa...@comcast.net wrote:
 I'm converting the java code examples in Killer Game Programming in
 Java by Andrew Davison to Clojure and am having great fun doing it.
 But I've hit wall where I can't seem to get the code to work.

 The following code moves an animated gif strip to a java array:

   public BufferedImage[] loadStripImageArray(String fnm, int number)
   {
     if (number = 0) {
       System.out.println(number = 0; returning null);
       return null;
     }

     BufferedImage stripIm;
     if ((stripIm = loadImage(fnm)) == null) {
       System.out.println(Returning null);
       return null;
     }

     int imWidth = (int) stripIm.getWidth() / number;
     int height = stripIm.getHeight();
     int transparency = stripIm.getColorModel().getTransparency();

     BufferedImage[] strip = new BufferedImage[number];
     Graphics2D stripGC;

     // each BufferedImage from the strip file is stored in strip[]
     for (int i=0; i  number; i++) {
       strip[i] =  gc.createCompatibleImage(imWidth, height,
 transparency);   =

       // create a graphics context
       stripGC = strip[i].createGraphics();
 =
       // stripGC.setComposite(AlphaComposite.Src);

       // copy image
       stripGC.drawImage(stripIm,
                   0,0, imWidth,height,
                   i*imWidth,0, (i*imWidth)+imWidth,height,
                   null);
       stripGC.dispose();
     }
     return strip;
   } // end of loadStripImageArray()

 The problem I'm having is with the for loop.   If I create an abject
 array of say 6 buffered images,  how do I reference the indexed image
 array to match the lines pointed to?  In other words what is the
 equivalent of strip[i] in Clojure?

 I'm not exactly a beginner, but this has stumped me.

 Bill

-- 
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: My first Clojure program: request for code review

2010-12-22 Thread Justin Kramer
On Dec 22, 10:59 am, Benny Tsai benny.t...@gmail.com wrote:
  It does, but doesn't that make it less lazy? To reverse something, it
  needs to evaluate the whole sequence. I yet have to learn how to
  deal with lazyness.
 You're right, I hadn't realized 'reverse' is not lazy (I have a lot to
 learn about lazyness management myself :)).  In this case, though, I
 don't think it has too much impact, since:

Just FYI, it's not applicable here but there is also rseq, which
returns a reversed view on a collection in constant time. It only
works on vectors and sorted maps, though.

 By the way, what is fmap?

See the ns declaration:

 (ns karma
  (:use [clojure.contrib.duck-streams :only (read-lines)])
  (:use [clojure.contrib.generic.functor :only (fmap)]))

Justin

-- 
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: My first Clojure program: request for code review

2010-12-21 Thread Justin Kramer
Here's my version. Main points:

* Use with-open  line-seq for worry-free laziness
* Do everything in one swoop (reduce)
* Perform one regexp match per line
* Leverage -

;;

(ns user
  (use [clojure.java.io :only [reader]]))

(def re-vote #([A-z]{1,16})(\+\+|\-\-))

(defn extract-votes
  [line]
  (map rest (re-seq re-vote line)))

(defn reckon
  [log]
  (with-open [r (reader log)]
(let [votes (mapcat extract-votes (line-seq r))]
  (reduce
   (fn [tally [nick vote]]
 (let [inc-or-dec (if (= vote ++) inc dec)]
   (assoc tally nick (inc-or-dec (tally nick 0)
   {}
   votes

(defn -main [ [[log]]]
  (let [tally (- log
   reckon
   (remove (comp zero? val))
   (sort-by (comp - val)))]
(doseq [[nick score] tally]
  (println nick score


Hope that helps,
Justin

On Dec 21, 8:38 pm, Marek Kubica ma...@xivilization.net wrote:
 Hi,

 I wrote a small log file analyzer for IRC logs. We use nickname++ and
 nickname-- to track the karma, so after trying to write it in
 JavaScript (failed due to to the fact that Gjs/Seed are unmature yet),
 Factor (failed because I am just too stupid to understand it), Guile
 (failed because I ran into encoding/regex-problems), so I gave Clojure
 a try.

 I really liked the immutable data stuctures, so I tried to avoid
 mutation.

 So uhm, this is my first Clojure program. I tend to learn a lot from
 code reviews and would be happy if someone could take a look at it and
 tell me what to improve and how to write more idiomatic code.

 Code is here, and reproduced below:
 https://github.com/Leonidas-from-XIV/karmawhore/blob/68ff6b681c5862fa...

 Thanks in advance!

 regards,
 Marek

 (ns net.xivilization.karmawhore
   (:gen-class)
   (:use [clojure.contrib.duck-streams :only (read-lines)]))

 (def allowed-nickname [A-z]{1,16})
 (def nick-plus (re-pattern (format (%s)\\+\\+ allowed-nickname)))
 (def nick-minus (re-pattern (format (%s)\\-\\- allowed-nickname)))

 (defn extract-nicks [regexp line]
   (map second (re-seq regexp line)))

 (defn modify-karma [op h nick]
   (let [current-value (h nick)]
     (if (nil? current-value) (assoc h nick (op 1))
       (assoc h nick (op current-value 1)

 (def increase-karma (partial modify-karma +))
 (def decrease-karma (partial modify-karma -))

 (defn process-line [acc line]
   (let [nicks-add (extract-nicks nick-plus line)
         nicks-sub (extract-nicks nick-minus line)
         after-add (reduce increase-karma acc nicks-add)]
     (reduce decrease-karma after-add nicks-sub)))

 (defn -main [ args]
   (let [file-name (first (first args))
         histogram (reduce process-line (hash-map) (read-lines
 file-name)) nonzero? (comp not zero? second)
         histogram (filter nonzero? histogram)
         sorted-by-karma (sort-by #(- (second %)) histogram)]
     (doseq [item sorted-by-karma]
       (printf %s %d\n (first item) (second item)

 (-main *command-line-args*)

-- 
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: Get sequence of values in arbitrarily nested collection

2010-12-06 Thread Justin Kramer
tree-seq makes this pretty simple:

(defn nested-vals [key coll]
  (for [x (tree-seq coll? seq coll) :when (contains? x key)]
(get x key)))

This works with any type of key and all associative Clojure
structures. It could be made compatible with Java structures by
swapping out the 'coll?' predicate for something more general.

Justin

On Dec 5, 9:12 pm, Alex Baranosky alexander.barano...@gmail.com
wrote:
 Hi guys,

 I would like a function to be able to take an arbitrarily nested collection
 and return a sequence of all values of a given key, such as :name, that
 appears anywhere in the nested collection.

 Does anything like this already exist?

 Thanks for the help,
 Alex

-- 
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: Printing a table of data

2010-11-13 Thread Justin Kramer
print-table was actually just added to the master branch:

https://github.com/clojure/clojure/commit/826ff8486fb3e742cea80ebc43d93afbd85b52d9

Justin

On Nov 13, 1:02 pm, Shantanu Kumar kumar.shant...@gmail.com wrote:
 Does anybody know if a standard 'print-table' kind of function exists
 in some library? Maybe if somebody can give an example of printing a
 table using cl-format or pprint.

 Regards,
 Shantanu

-- 
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: Python is way faster than Clojure on this task

2010-11-07 Thread Justin Kramer
Implementing this in straight Java might help pinpoint whether this is
a JVM issue or a Clojure issue.

Also, FYI, there is clj-glob (https://github.com/jkk/clj-glob) for
finding files based on patterns like */*/*.dat

Justin

On Nov 4, 4:28 pm, Pepijn de Vos pepijnde...@gmail.com wrote:
 Hi all,

 I have written a Python script to analyze Minecraft levels and render a 
 graph. Then I did the same with Clojure. It takes Python 10 seconds to 
 analyze a map, while it takes Clojure over a minute.

 After having tried different options without any significant improvement, I 
 am lost as to why there is such a huge difference. I wouldn't mind an extra 
 pair of eyes/brains to look at this.

 I blogged about it in more detail 
 here:http://pepijndevos.nl/clojure-versus-python
 Clojure version:https://github.com/pepijndevos/Clomian/
 Python version:https://github.com/l0b0/mian

 Clojure spends most of its time in the freqs function, here are a couple of 
 variations:https://gist.github.com/663096

 If you want to run the code yourself, you'll need a Minecraft level and JNBT, 
 which is not on Maven.
 JNBT:http://jnbt.sourceforge.net/
 The level used in the blogpost:http://dl.dropbox.com/u/10094764/World2.zip

 Groeten,
 Pepijn de Vos
 --
 Sent from my iPod Shufflehttp://pepijndevos.nl

-- 
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: Constructing Nested Trees and Memory Consumption

2010-11-03 Thread Justin Kramer
Check out assoc-in, get-in, and update-in. They make working with
nested maps a breeze. Here's a rewrite of your code:

(ns user
  (:require [clojure.string :as str]
[clojure.java.io :as io]))

(def postcode-trie
  (with-open [r (io/reader /path/to/data.csv)]
(reduce
 (fn [trie line]
   (let [[postcode region] (.split line ,)
 postcode (str/replace postcode   )]
 (assoc-in trie postcode region)))
 {}
 (line-seq r

(get-in postcode-trie SW1A2)
;; = 20

This stores keys of the tree (trie) as characters instead of strings,
which lets you use get-in easily.

Using line-seq might help mitigate unnecessary memory usage, though as
Andy mentions, Java objects just carry a lot of baggage.

Justin

On Nov 3, 12:22 pm, Paul Ingles p...@forward.co.uk wrote:
 Hi,

 I've been playing around with breaking apart a list of postal codes to
 be stored in a tree with leaf nodes containing information about that
 area. I have some code that works with medium-ish size inputs but
 fails with a GC Overhead error with larger input sets (1.5m rows) and
 would really appreciate anyone being able to point me in the right
 direction.

 The full code is up as a gist here:https://gist.github.com/661278

 My input file contains something like:

 SW1A 1,10
 SW1A 2,20
 ...

 Which are then mapped to 2 trees:

 {S {W {1 {A {1 10}
 {S {W {1 {A {2 20}

 I then want to continually fold those trees into a master tree. For
 the 2 maps above the merged tree would be:

 {S {W {1 {A {1 10 2 20}

 I'm sure I'm missing all kinds of awesome core/contrib functions to
 make it more concise and would appreciate anyone pointing out
 alternatives also.

 The main problem is that it fails when my input data gets sufficiently
 large. On my MacBook Pro it falls over with an input set of 1.5m
 records (although a lot of these would be branches from the first few
 levels). It reports GC Overhead limit exceeded, although also ran out
 of heap size before I upped that.

 I assume this is because during the tree reduction it's still
 retaining references to nodes eventually causing it to build
 continually larger structures?

 I've included the reduce function (and how that gets called to produce
 results) inline:

 (defn merge-tree
   [tree other]
   (if (not (map? other))
     tree
     (merge-with (fn [x y] (merge-tree x y))
                 tree other)))

 (def results (reduce merge-tree
                      {}
                      (map record-to-tree
                           postcodes-from-file)))

 All help much appreciated,
 Paul

-- 
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: Help to optimize palindrome search from input file

2010-10-12 Thread Justin Kramer
The 'palindrome?' function can be made much faster. Your version --
which is idiomatic and fine when perf isn't a factor -- turns the test
string into a sequence, reverses it, turns it back into a string, then
checks for full equality with the original. There are faster (if
uglier) ways to check for palindromes. This version finds the Level 1
answer in about 150ms on my machine:

(defn palindrome?
  [^String s]
  (let [len (.length s)
mid (quot len 2)]
(loop [i 0
   j (dec len)]
  (if (= i mid)
true
(when (= (.charAt s i) (.charAt s j))
  (recur (inc i) (dec j)))

Also, the built-in function max-key will do what your sort/max-comp
code is doing more concisely:

(apply max-key count (filter palindrome? (all-combs input)))

HTH,

Justin

On Oct 12, 3:02 pm, tonyl celtich...@gmail.com wrote:
 Hi, I just started to learn clojure in a more serious way and I am
 doing the first level of the greplin challenge.

 I made it to work with a short palindrome like the example they give
 me, but when it comes to work with the input file, it takes for ever
 and I have to stop it.

 $ time clj level1.clj
 ^C
 real    11m35.477s
 user    1m44.431s
 sys     9m3.878s

 This is my code:

 (defn palindrome? [s]
   (= s (reduce str (reverse s

 (defn all-combs [in]
   (let [len (count in)]
     (for [i (range 0 (- len 2)), j (range (+ i 1) len)]
       (subs in i j

 (defn max-comp [x y]
   (let [lenx (count x), leny (count y)]
     (cond ( lenx leny) 1
           (= lenx leny) 0
           ( lenx leny) -1)))

 ;;(let [input I like racecars that go fast]
 (let [input (slurp ../_input/level1.in)]
     (println (nth (sort max-comp (filter palindrome? (all-combs
 input))) 0)))

 The input file is thishttp://challenge.greplin.com/static/gettysburg.txt

 It looks a bit procedural. It is long, but I don't think is the
 biggest bottleneck, I think it is my approach to create all the
 combinations possible for substrings. Maybe I should be using a lazy
 seq? How would I go to do that?

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


Re: List folders/ Files recursively

2010-10-06 Thread Justin Kramer
On Oct 6, 8:39 am, B Smith-Mannschott bsmith.o...@gmail.com wrote:
 On Wed, Oct 6, 2010 at 08:49, Abraham vincent@gmail.com wrote:
  ; prints all files
  (import 'java.io.File)
  (defn walk [dirpath]
   (doseq [file (- dirpath File. file-seq)]
      (println (.getPath file)  )))

 This doesn't do what you said you wanted to do above: list all files,
 recursively. It just lists the files contained directly in dirpath.

file-seq is based on tree-seq and does indeed return all files and
directories recursively (and lazily).

 Listing files recursively is a tree recursion. A tree recursion is not an
 iterative process. loop/recur won't help you there. You'll need to use real
 stack-consuming recursion.

Just to be a devil's advocate, a tree recursion can be translated to
loop/recur using an explicit stack:

(defn list-files [dirname]
  (loop [stack [(java.io.File. dirname)]]
(when-let [f (peek stack)]
  (println (.getPath f))
  (recur (into (pop stack) (.listFiles f))

Changing the stack to a queue would make the traversal happen breadth-
first rather than depth-first.

Justin

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


Re: List folders/ Files recursively

2010-10-06 Thread Justin Kramer
I should mention that Ben's solution is still nice and is basically
how tree-seq is implemented under the hood. It is more idiomatic than
using loop/recur (for most use cases).

Justin

On Oct 6, 10:59 am, Justin Kramer jkkra...@gmail.com wrote:
 On Oct 6, 8:39 am, B Smith-Mannschott bsmith.o...@gmail.com wrote:

  On Wed, Oct 6, 2010 at 08:49, Abraham vincent@gmail.com wrote:
   ; prints all files
   (import 'java.io.File)
   (defn walk [dirpath]
    (doseq [file (- dirpath File. file-seq)]
       (println (.getPath file)  )))

  This doesn't do what you said you wanted to do above: list all files,
  recursively. It just lists the files contained directly in dirpath.

 file-seq is based on tree-seq and does indeed return all files and
 directories recursively (and lazily).

  Listing files recursively is a tree recursion. A tree recursion is not an
  iterative process. loop/recur won't help you there. You'll need to use real
  stack-consuming recursion.

 Just to be a devil's advocate, a tree recursion can be translated to
 loop/recur using an explicit stack:

 (defn list-files [dirname]
   (loop [stack [(java.io.File. dirname)]]
     (when-let [f (peek stack)]
       (println (.getPath f))
       (recur (into (pop stack) (.listFiles f))

 Changing the stack to a queue would make the traversal happen breadth-
 first rather than depth-first.

 Justin

-- 
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-contrib master now in submodules

2010-09-22 Thread Justin Kramer
Here's the magic incantation I've been using:

[org.clojure.contrib/complete 1.3.1-SNAPSHOT :classifier bin]

I don't know how official or future-proof that is.

Justin

On Sep 22, 2:02 am, Sean Corfield seancorfi...@gmail.com wrote:
 On Fri, Aug 20, 2010 at 7:22 AM, Stuart Sierra

 the.stuart.sie...@gmail.com wrote:
  For example, to use the clojure.contrib.macro-utils namespace in your
  projects, add a dependency on group org.clojure.contrib, artifact
  macro-utils, version 1.3.0-SNAPSHOT.

 Having built contrib against clojure 1.2.0 (see my note in another
 thread), I can get individual module dependencies to work in lein like
 this:

     :dependencies [ ... [org.clojure.contrib/macro-utils 1.3.0-
  SNAPSHOT] ...]

 However, I can't get the all / complete dependency to work:

  If you want to use ALL contrib libraries, add a dependency on group
  org.clojure.contrib, artifact complete, version 1.3.0-SNAPSHOT.
  This meta-library depends on all other contrib libraries.

 This doesn't work:

   :dependencies [[org.clojure/clojure 1.3.0-master-SNAPSHOT]
                         [org.clojure.contrib/complete 1.3.0-SNAPSHOT]]

 I've tried a few other dependencies based on what seems to be in my
 local maven repo (caveat: I don't know maven), and couldn't find
 anything that works.

 Everything seems to be 1.3.1-SNAPSHOT but
 [org.clojure.contrib/complete 1.3.1-SNAPSHOT] doesn't work either.

 Suggestions?
 --
 Sean A Corfield -- (904) 302-SEAN
 Railo Technologies, Inc. --http://getrailo.com/
 An Architect's View --http://corfield.org/

 If you're not annoying somebody, you're not really alive.
 -- Margaret Atwood

-- 
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: Working with the are macro

2010-09-21 Thread Justin Kramer
Is using 'is' and 'every?' an option?

(deftest test-good-labels
  (is (every? valid-label? good-labels)))

Justin

On Sep 21, 11:53 am, Sean Devlin francoisdev...@gmail.com wrote:
 I'm trying to pass a vector to are, because I need to reuse some
 source data.  Is there a better way to do this?  I don't like the
 eval.

 (def good-labels
    [...])

 (deftest test-good-labels
   (eval `(are [label] (valid-label? label) ~...@good-labels)))

 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


Re: Mapping a function to a map

2010-09-06 Thread Justin Kramer
reduce returns a single value; there's no collection to make lazy.
There is reductions, which returns the intermediate results of reduce
as a lazy sequence.

Justin

On Sep 6, 12:49 pm, Robert McIntyre r...@mit.edu wrote:
 I thought that since into uses reduce, it would be lazy, but I was wrong.
 reduce just plows through everything with a non-lazy recursion.

 Why is reduce not lazy?

 --Robert McIntyre

 On Mon, Sep 6, 2010 at 12:37 PM, Michał Marczyk



 michal.marc...@gmail.com wrote:
  On 6 September 2010 18:29, Robert McIntyre r...@mit.edu wrote:
  walk is good but it's not lazy. If you want to preserve laziness you can 
  do:

  This won't be lazy, because (into {} ...) is a strict operation.

  I'd suggest something like

  (defn mmap [f m]
   (zipmap (keys m) (map f (vals m

  f is expected to care about the value only.

  Sincerely,
  Michał

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

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


Re: clojure-conj registration is now open!

2010-09-03 Thread Justin Kramer
Thanks and congratulations to the Clojure/core team for making this
happen. Can't wait!

Justin

On Sep 3, 3:15 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
 We're happy to announce that the official (first clojure-conj) conference 
 site is now live athttp://clojure-conj.org, and that registration is open.

 To register, visithttp://clojure-conj.organd click Register.

 The conj begins Friday, October 22 and completes the next day, Saturday, 
 October 23. Early-bird tickets are $199, and our venue is the Hilton at 
 Research Triangle Park in Durham, NC. The ticket price covers:

 * two days of single-track presentations and discussion
 * meals between breakfast on Friday and lunch on Saturday
 * a ticket to Clojure's 3rd birthday celebration on Friday night

 Thanks again, and see you all soon!

 The Clojure/core team

-- 
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: multiple parameters passed to fns

2010-09-02 Thread Justin Kramer
A couple other things:
1) (apply identity ...) is the same as (first ...)
2) Consider using the - macro to clean up the let

Here's a quick rewrite:

(defn make-target
  ([file channel sweepidx]
 (make-target file channel sweepidx 0))
  ([file channel sweepidx startidx]
 (make-target file channel sweepidx startidx nil))
  ([file channel sweepidx startidx size]
 (let [target (- (graph-part file channel sweepidx (inc
sweepidx))
   first
   (drop startidx))]
   (if size
 (take size target)
 target

Lastly, if graph-part happened to return something like a vector or
string, there are faster ways of taking a slice than take  drop --
that is, subvec or subs.

HTH,

Justin

On Sep 2, 10:20 am, Miki miki.teb...@gmail.com wrote:
 Hello Glen,

 I'd use the first two forms to set startidx and size and then call the
 full form:

 (def inf java.lang.Double/POSITIVE_INFINITY)

 (defn make-target
   Parses text file for single sweep specified by sweepidx.  If size
 is
   not specified will parse till end of sweep.  If startidx and size
 are
   not spefified will parse from beginning to end
   ([file channel sweepidx]
    (make-target file channel sweepidx 0 inf))
   ([file channel sweepidx startidx]
    (make-target file channel sweepidx startidx inf))
   ([file channel sweepidx startidx size]
    ([file channel sweepidx startidx size]
     (let [collated-target1 (graph-part file channel sweepidx (+ 1

 sweepidx))
           collated-target2 (apply identity collated-target1)
           ;apply starting point and size parameters
           collated-target3 (take size (drop startidx collated-
 target2))]
       collated-target3)))

 On Sep 2, 5:54 am, Glen Rubin rubing...@gmail.com wrote:



  I defined a fn whose execution depends on the number of parameters
  passed to it.  It works fine!  I am just concerned that I am doing
  this in a way that is not as concise as it could or should be.  Here
  is my fn:

  (defn make-target

  Parses text file for single sweep specified by sweepidx.  If size is
  not specified will parse till end of sweep.  If startidx and size are
  not spefified will parse from beginning to end

  ([file channel sweepidx]
    (let [collated-target1 (graph-part file channel sweepidx (+ 1
  sweepidx))
          ;break open double parens
          collated-target2 (apply identity collated-target1)]
      collated-target2))

  ([file channel sweepidx startidx]
    (let [collated-target1 (graph-part file channel sweepidx (+ 1
  sweepidx))
          collated-target2 (apply identity collated-target1)
          ;;apply starting point
          collated-target3 (drop startidx collated-target2)]
      collated-target3))

  ([file channel sweepidx startidx size]
    (let [collated-target1 (graph-part file channel sweepidx (+ 1
  sweepidx))
          collated-target2 (apply identity collated-target1)
          ;apply starting point and size parameters
          collated-target3 (take size (drop startidx collated-target2))]
      collated-target3)))

-- 
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: Why do is used in this function?

2010-08-31 Thread Justin Kramer
Another tip: per the doc for 'empty?', (seq s) is preferred over (not
(empty? s)). Oh, and 'str' isn't necessary since 'println' adds spaces
between arguments:

(defn printall [s]
  (when (seq s)
   (println Item: (first s))
   (recur (rest s

Justin

On Aug 31, 10:57 am, Nicolas Oury nicolas.o...@gmail.com wrote:
 One solution to remove it is to use when.

  (when (not (empty? s)
           (println (str Item:  (first s)))
           (recur (rest s

 As there is only one case for a when, you can give multiple
 instructions for this case without grouping them
 Even better:

 (when-not (empty? s)
      (println (str Item:  (first s)))
           (recur (rest 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


Re: Feedback on idiomatic clojure

2010-08-19 Thread Justin Kramer
Meikel's suggestions are all good and I would follow them.

There are a number of built-in functions you can take advantage of if
you're using 1.2 (they're also available in contrib for 1.1):

clojure.string/lower-case
clojure.java.io/reader -- obviates java.io.BufferedReader and friends:
(reader /usr/share/dict/words)

As a point of comparison, I did a similar code kata recently. I've
posted it here, with a few lines added to show the top 10:

http://gist.github.com/537945

It runs in a couple seconds on my machine. For maximum speed,
transients might help.

Justin

On Aug 18, 6:46 pm, Damon Snyder drsny...@gmail.com wrote:
 Hi Everyone,
 I'm looking for some feedback on a small get-your-feet wet program I
 wrote in clojure (my first). In particular, I hope to get feedback on
 how to better make use of clojure's data structures and functional
 programming in general.

 Below is the toy program and the sample output. It reads in words from
 the OS X dictionary file, catalogs the anagrams, and then prints out
 the top ten by frequency. Although performance is not my primary
 concern here, it is a bit slow. It takes about 15s on my mac book
 pro.

 As an example, is this the proper way to update multiple fields at
 once in a nested hash-map:

 (update-in (update-in anagrams [akey :count] inc) [akey :words] conj
 word)))

 I understand this as returning an copy of an updated copy of an
 updated copy.

 Any feedback would be appreciated. Thanks,
 Damon

 ## begin
 (defn f-to-seq[file]
   (with-open [rdr (java.io.BufferedReader.
                     (java.io.FileReader. file))]
     (doall (line-seq rdr

 (defn str-sort[str]
   (if (nil? str)
     str
   (String. (into-array (. Character TYPE) (sort str)

 (defn str-to-lower[str]
   (if (nil? str)
     str
     (.toLowerCase str)))

 (defn anagram-add[anagrams akey word]
   (if (empty? (get anagrams akey))
     (assoc anagrams akey (hash-map :count 1, :words (list word)))
     (update-in (update-in anagrams [akey :count] inc) [akey :words]
 conj word)))

 (defn word[seq] (first seq))

 (defn build-anagrams[seq]
   (loop [seq seq
          akey (str-sort (str-to-lower (word seq)))
          anagrams {}]
     (if (empty? seq)
       anagrams
       (recur (rest seq)
              (str-sort (str-to-lower (word (rest seq
              (anagram-add anagrams akey (word seq))

 (defn print-anagram[v]
   (println (str (:count (first (rest v)))   (first v) :  (:words
 (first (rest v))

 (defn print-anagrams[ana]
   (doseq [v ana]
     (print-anagram v)))

 (defn anagram-key[elem] (:count (first (rest elem

 (def *words* (f-to-seq /usr/share/dict/web2))
 (def *anagrams* (sort-by anagram-key (build-anagrams *words*)))
 (print-anagrams (take 10 (reverse *anagrams*)))

 ## output
 11 agnor: (Ronga rogan organ orang Orang nagor groan
 grano goran argon angor)
 10 aelps: (speal spale slape sepal saple salep Pales
 Lepas lapse Elaps)
 9 eerst: (tsere terse stree stere steer reset reest
 estre ester)
 9 aeerst: (teaser staree seater saeter reseat Eastre
 easter Easter asteer)
 9 aacinr: (narica crania Crania carina Carian canari
 Canari arnica acinar)
 9 acert: (trace recta react creta creat crate cater
 carte caret)
 8 ailr: (rial rail lira liar lari Lari lair aril)
 8 aelpt: (tepal pleat plate petal pelta patel palet
 leapt)
 8 airst: (Trias tisar tarsi stria stair sitar astir
 arist)
 8 aemrt: (Trema trame terma tamer ramet metra mater
 armet)

-- 
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.2 Release

2010-08-19 Thread Justin Kramer
Woohoo, congrats! Can't wait to see all the new goodies that are in
store for the next version.

Justin

On Aug 19, 11:25 am, Rich Hickey richhic...@gmail.com wrote:
 I'm pleased to announce today the release of Clojure 1.2.

 http://clojure.org/downloads

 For maven/leiningen users, your settings to get the beta from
 build.clojure.org/releases are:

          :dependencies [[org.clojure/clojure 1.2.0]
                     [org.clojure/clojure-contrib 1.2.0]

 This release includes many significant new features, such as protocols
 and datatypes; enhancements to existing features like the sequence
 library, destructuring and agents; support for annotations, etc. In
 addition, it incorporates many enhancements first developed and
 nurtured in clojure-contrib like I/O, string and pretty printing
 facilities.

 This release reflects the work of many people in addition to myself,
 and I'd like to thank all of the contributors who've submitted fix and
 enhancement patches, and everyone in the community who has
 participated in terrific dialog that surrounds the development and use
 of Clojure.

 Congrats and thanks to the contrib authors whose work has made it into
 the release:

 Chas Emerick
 Tom Faulhaber
 Stephen Gilardi
 Christophe Grand
 Stuart Halloway
 Chris Houser
 David Liebke
 Michel Salim
 Stuart Sierra

 I'd especially like to thank Stuart Halloway and the rest of the
 Clojure/core team for their tireless effort in authoring, screening
 and applying patches, setting up build machines, monitoring the
 mailing list, cutting releases etc. Their help greatly facilitates my
 ability to concentrate on the core design issues, and builds the
 foundation for increasing community involvement. A lot of work goes
 into Clojure. The team's effort is enabled and funded by the Clojure/
 core practice (http://clojure.com).

 The full list of enhancements and changes is here:

 http://github.com/clojure/clojure/blob/1.2.x/changes.txt

 and the fixed tickets are here:

 http://www.assembla.com/spaces/clojure/tickets?milestone_id=149827ti...

 What's next? Plenty! There are a few fixes and enhancements too
 impactful to squeeze into this release that we hope to get out there
 ASAP. I've done a ton of work already on enhanced primitive support
 and call linkage that will be moving into master. Design work is
 proceeding on many fronts. I'm looking forward to the increasing
 capability and maturity of Clojure, and the growth of the community.

 Thanks to all involved!

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

2010-08-18 Thread Justin Kramer
On Aug 18, 2:42 am, Michael Wood esiot...@gmail.com wrote:
 nils replace nils when there are fewer substitutions than nil
 positions was one of the requirements.

 From the first post:

  If nil is encountered in the first sequence and the second sequence is
  exhaused, nil will be returned:

  e.g.  user (nil-coalesce (nil 1 2 3 nil nil) (4 5))
  (4 1 2 3 5 nil)

_Returning_ nil is the requirement, which is what happens in the code
I posted (it behaves the same as other submissions as far as I can
tell). Replacing nil with nil in the result vector isn't necessary for
that to happen.

Justin

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

2010-08-17 Thread Justin Kramer
With the precondition that the first collection is a vector:

(use '[clojure.contrib.seq-utils :only [positions]])

(defn nil-coalesce [v subs]
  (apply assoc v (interleave (positions nil? v) subs)))

Justin

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

2010-08-17 Thread Justin Kramer
Another one that works with all collections. Short, but not
necessarily the most efficient:

(use '[clojure.contrib.seq-utils :only [positions]])

(defn nil-coalesce [coll subs]
  (map-indexed (zipmap (positions nil? coll) subs) coll))

Justin

On Aug 17, 4:10 pm, Justin Kramer jkkra...@gmail.com wrote:
 With the precondition that the first collection is a vector:

 (use '[clojure.contrib.seq-utils :only [positions]])

 (defn nil-coalesce [v subs]
   (apply assoc v (interleave (positions nil? v) subs)))

 Justin

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

2010-08-17 Thread Justin Kramer
On Aug 17, 4:42 pm, Alan a...@malloys.org wrote:
 Devious! The OP wanted to handle underflow of the subs collection
 though, so you need a tweak:
 (apply assoc v (interleave (positions nil? v)
                            (concat subs (repeat nil

interleave stops once either collection is exhausted. In your modified
version, nils replace nils when there are fewer substitutions than nil
positions, which is unnecessary. Unless I'm missing something...which
is entirely possible.

It does fail when subs is empty, though. So:

(defn nil-coalesce [v subs]
  (if (empty? subs) v
(apply assoc v (interleave (positions nil? v) subs

Off the golf course, I would probably use something like Meikel's or
ataggart's. I agree with Meikel that the lazy-seq approach is straight-
forward to understand, assuming you're familiar with lazy-seq idioms.

Justin

-- 
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: let binding and recursive function

2010-08-02 Thread Justin Kramer
I think you want:

(defn- do-traversal [tree idx  [tree-traversal]]
  ...)

Note the extra brackets for destructuring.

Another alternative is using multiple arg lists:

(defn- do-traversal
  ([tree idx]
(do-traversal tree idx []))
  ([tree idx traversal]
...))

Lastly, FYI, the form (if foo foo bar) can be simplified to (or foo
bar).

Hope that helps,

Justin

On Aug 2, 5:04 pm, John Sanda john.sa...@gmail.com wrote:
 I've just implemented an inorder traversal function for a vector-based tree.
 The functions look like,

 (defn- do-traversal [tree idx traversal]
   (cond
    (not (node-exists? tree idx)) traversal
    (leaf? tree idx) (conj traversal (tree idx))
    :else (apply conj
         (do-traversal tree (left-child idx) traversal)
         (tree idx)
         (do-traversal tree (right-child idx) traversal

 (inorder-traversal [tree]
   (do-traversal tree root-idx []))

 This works as expected but now I am looking to refactor the code some. I
 wanted to see if I could do away passing an empty vector to the do-traversal
 function. So I updated do-traversal to look like,

 (defn- do-traversal [tree idx  tree-traversal]
   (let [traversal (if tree-traversal tree-traversal [])]
    (cond
     (not (node-exists? tree idx)) traversal
     (leaf? tree idx) (conj traversal (tree idx))
     :else (apply conj
          (do-traversal tree (left-child idx) traversal)
          (tree idx)
          (do-traversal tree (right-child idx) traversal)

 When the expected traversal for a tree is [10 20 30] I instead get ([] 30 20
 10 [])) in my unit test. Can someone explain to me why using let as I have
 done does not work, and what another solution might be?

 Thanks

 - John

-- 
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: ClojureDocs.org

2010-07-09 Thread Justin Kramer
I've told Zack that he is free to pull any examples from the wiki for
use on his site.

I don't know about collaboration beyond that. The wiki is open source
and written in Clojure; anyone is free to contribute/fork. At least
one person has expressed interest in making code contributions.

Zack, you had mentioned you planned to keep the source of your site
proprietary -- is that set in stone?

Justin

On Jul 9, 12:21 pm, David Nolen dnolen.li...@gmail.com wrote:
 On Fri, Jul 9, 2010 at 4:32 AM, zkim zachary@gmail.com wrote:

  Questions / thoughts?

  -Zack

 This is great. I think the main thing is not duplicating effort. This and
 clojure-examples.appspot.com should really join forces.

 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: ClojureDocs.org

2010-07-09 Thread Justin Kramer
An examples function for the REPL that pulls from the wiki:

http://gist.github.com/470031

I'm sure something like it could be made for ClojureDocs.org once the
API is in place.

General comments on ClojureDocs.org: I think an important aspect of a
collaborative tool like this is quality control. There needs to be
people watching recent updates, making sure examples meet certain
standards (formatted correctly, idiomatic, etc.). To that end, a
complete list of recent updates (with diffs) to go along with the
short list on the homepage would be really nice.

Having a category-based outlines would also be nice. I have one here
for clojure.core, adapted from the Cheatsheet:

http://clojure-examples.appspot.com/clojure.core

Feel free to nab it.

FYI, I'll probably be implementing a mass export feature for the wiki,
so you could write a script or something to automate an import.

Awesome work, Zack.

Justin

On Jul 9, 2:25 pm, Alex Miller alexdmil...@yahoo.com wrote:
 I've actually been thinking about this exact same kind of site for a
 while now and I'm thrilled that I was too lazy to do it so that you
 could do it instead. :)

 One idea that I have that I think would be killer would be to provide
 an API to look up one your examples at the repl so I could do
 something like:

 = (use 'clojuredocs)
 = (example map)
 clojure.core/map (since 1.0)

 (map inc [1 2 3 4 5])
 (2 3 4 5 6)

 There are of course many variants of some functions and different
 forms of use, so dealing with the best way to provide useful help
 without an overwhelming number of examples is tricky in the repl, but
 I think worth doing.  Along with doc and source, I think example would
 be a killer addition to allowing you to explore the libraries from the
 comfort of your repl.

 Alex

 On Jul 9, 3:32 am, zkim zachary@gmail.com wrote:



  Hi All,

  I'll try to keep this short.

  I've gotten a lot out of Clojure: I can honestly say that learning
  this language, and being part of this community has made me a better,
  happier developer, and I wanted to give something back.

  One of the pain points that I encountered when learning the language
  was a lack of examples specific to the individual functions I was
  trying to wrap my head around at any given time. So I took a whack at
  the problem, and came up withhttp://clojuredocs.org.  It's a site
  that (I'm hoping) will fill this need by providing a centralized
  examples database, along with solid search capabilities across both
  core and third party libraries (core being the focus).

  Implementation:
  ClojureDocs.org is a rails site backed by MySQL, along with some
  clojure code to pull the namespaces / metadata / source and dump them
  into the database.

  Highlights:
  1. Documentation and source for Clojure core, contrib, and a few third
  party libraries (random selection out of what I'm personally familiar
  with, and whatever was on the github trends page that day).

  2. Search for a var across the whole ecosystem or in a specific
  library.

  3. Per var wiki-style examples section.

  4. Per var comments section.

  5. Per var vars-in-this-var and this-var-used-in section (my personal
  favorite).  Looking for a real-world example of a specific function?
  This is for you. For example,http://clojuredocs.org/v/1978, just
  below the source section.

  Lowlights:
  1. Ugly URLs!  There's a problem in the way that URLs with encoded
  question marks are being handled, so I had to move 
  fromhttp://clojuredocs.org/clj-ssh/clj-ssh.core/file-pathtohttp://clojure
    I've got an email out to the Phusion
  Passenger mailing list (http://groups.google.com/group/phusion-
  passenger/browse_thread/thread/ed2eadfdac5c166f) but if you've got any
  experience in this area drop me a line.

  2. Strange var names (http://clojuredocs.org/v/781).  Probably a bug
  in the import process.

  3. General rough-around-the-edges-ness.

  I'm treating this as an alpha, and I'd really like feedback as to:
  a. How useful this would be to the community.
  b. Specific likes / dislikes about this alpha release.
  c. Feature requests.

  I've set up a feedback mechanism directly through the site (User
  Voice), which allows voting on specific posts.  I'm also considering
  setting up a google group for general discussion.  Feel free to
  contact me directly through email.

  Questions / thoughts?

  -Zack

-- 
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: examples (like doc)

2010-07-08 Thread Justin Kramer
One use case I was thinking of for the Wiki is that IDEs could make
API requests for individual functions on-the-fly, or do a mass export
periodically. A basic version of the former exists now:

http://clojure-examples.appspot.com/clojure.core/conj?format=json

The result could be displayed plain text or as HTML in a popup/overlay/
etc.

One could even pull the examples from the Wiki and attach them to
metadata via John's set-examples!. This could be done by a function
that's only called when in REPL mode (similar to 'source' etc.).

Or it could follow the approach of the 'javadoc' function: open your
browser to a page with detailed examples.

Just some ideas,

Justin


On Jul 8, 11:38 am, Chas Emerick cemer...@snowtide.com wrote:
 I think there's a lot of value to having good documentation and  
 examples available directly in your development environment.  I'm not  
 sure what a reasonable alternative would be for that context other  
 than having the examples and docs included (or at least, adjacent, as  
 set-examples! allows for).  It certainly seems reasonable to ensure  
 that such information is not included in whatever distribution of  
 clojure you would ship (whatever that means in your context).

 The details are sticky though, and would involve touching processes  
 that aren't the most forgiving AFAICT (i.e. the core clojure build and  
 surrounds).

 - Chas

 On Jul 7, 2010, at 4:35 PM, Moritz Ulrich wrote:



  I don't think examples should be integrated in the
  function-definition. It's *way* to much bloat.

  I like the wayhttp://clojure-examples.appspot.com/clojure.coregoes.
  A wiki-like documentation for examples, linked to every
  clojure-namespace. These examples could be serialized into some data
  structure and integrated in clojure.jar. This would result in no bloat
  for core.clj etc. and nice, accessible examples for our
  development-tools.

  On Wed, Jul 7, 2010 at 9:05 PM, John Cromartie  
  jcromar...@gmail.com wrote:
  I've whipped up a proof-of-concept of how to implement built-in
  examples for functions and macros. The general idea is to add an
  attribute to the var that contains a list of docstrings and arg lists
  or code that illustrate common usage.

  Let me know what you think:http://gist.github.com/466743

  It could also be useful for generating documentation.

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

  --
  Moritz Ulrich
  Programmer, Student, Almost normal Guy

 http://www.google.com/profiles/ulrich.moritz

  --
  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: examples (like doc)

2010-07-08 Thread Justin Kramer
They are separated: in the HTML version (html-content JSON
property), code is wrapped in pre class=code, results in pre
class=output, and verbiage in p. For the Markdown version (raw-
content), there are plain-text delineations.

I will change the mime-type, though...

Justin

On Jul 8, 1:31 pm, Chas Emerick cemer...@snowtide.com wrote:
 That's nifty.  Suggestion though: if you really want to have tools  
 pull those examples so that they could be used systematically, the  
 json should really be structured to clearly separate code, expected  
 results, and verbiage -- linebreaks aren't enough, as I could imagine  
 many functions having a *lot* of examples, and just popping up a chunk  
 of scrolling text may or may not be what a typical IDE user would find  
 useful.

 - Chas

 On Jul 8, 2010, at 1:05 PM, Justin Kramer wrote:



  One use case I was thinking of for the Wiki is that IDEs could make
  API requests for individual functions on-the-fly, or do a mass export
  periodically. A basic version of the former exists now:

 http://clojure-examples.appspot.com/clojure.core/conj?format=json

  The result could be displayed plain text or as HTML in a popup/
  overlay/
  etc.

  One could even pull the examples from the Wiki and attach them to
  metadata via John's set-examples!. This could be done by a function
  that's only called when in REPL mode (similar to 'source' etc.).

  Or it could follow the approach of the 'javadoc' function: open your
  browser to a page with detailed examples.

  Just some ideas,

  Justin

  On Jul 8, 11:38 am, Chas Emerick cemer...@snowtide.com wrote:
  I think there's a lot of value to having good documentation and
  examples available directly in your development environment.  I'm not
  sure what a reasonable alternative would be for that context other
  than having the examples and docs included (or at least, adjacent, as
  set-examples! allows for).  It certainly seems reasonable to ensure
  that such information is not included in whatever distribution of
  clojure you would ship (whatever that means in your context).

  The details are sticky though, and would involve touching processes
  that aren't the most forgiving AFAICT (i.e. the core clojure build  
  and
  surrounds).

  - Chas

  On Jul 7, 2010, at 4:35 PM, Moritz Ulrich wrote:

  I don't think examples should be integrated in the
  function-definition. It's *way* to much bloat.

  I like the wayhttp://clojure-examples.appspot.com/clojure.coregoes.
  A wiki-like documentation for examples, linked to every
  clojure-namespace. These examples could be serialized into some data
  structure and integrated in clojure.jar. This would result in no  
  bloat
  for core.clj etc. and nice, accessible examples for our
  development-tools.

  On Wed, Jul 7, 2010 at 9:05 PM, John Cromartie
  jcromar...@gmail.com wrote:
  I've whipped up a proof-of-concept of how to implement built-in
  examples for functions and macros. The general idea is to add an
  attribute to the var that contains a list of docstrings and arg  
  lists
  or code that illustrate common usage.

  Let me know what you think:http://gist.github.com/466743

  It could also be useful for generating documentation.

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

  --
  Moritz Ulrich
  Programmer, Student, Almost normal Guy

 http://www.google.com/profiles/ulrich.moritz

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

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

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

Re: examples (like doc)

2010-07-08 Thread Justin Kramer
Oh: it probably would have helped if I had said the API returns JSON,
not straight text/HTML.

Justin

On Jul 8, 1:44 pm, Justin Kramer jkkra...@gmail.com wrote:
 They are separated: in the HTML version (html-content JSON
 property), code is wrapped in pre class=code, results in pre
 class=output, and verbiage in p. For the Markdown version (raw-
 content), there are plain-text delineations.

 I will change the mime-type, though...

 Justin

 On Jul 8, 1:31 pm, Chas Emerick cemer...@snowtide.com wrote:



  That's nifty.  Suggestion though: if you really want to have tools  
  pull those examples so that they could be used systematically, the  
  json should really be structured to clearly separate code, expected  
  results, and verbiage -- linebreaks aren't enough, as I could imagine  
  many functions having a *lot* of examples, and just popping up a chunk  
  of scrolling text may or may not be what a typical IDE user would find  
  useful.

  - Chas

  On Jul 8, 2010, at 1:05 PM, Justin Kramer wrote:

   One use case I was thinking of for the Wiki is that IDEs could make
   API requests for individual functions on-the-fly, or do a mass export
   periodically. A basic version of the former exists now:

  http://clojure-examples.appspot.com/clojure.core/conj?format=json

   The result could be displayed plain text or as HTML in a popup/
   overlay/
   etc.

   One could even pull the examples from the Wiki and attach them to
   metadata via John's set-examples!. This could be done by a function
   that's only called when in REPL mode (similar to 'source' etc.).

   Or it could follow the approach of the 'javadoc' function: open your
   browser to a page with detailed examples.

   Just some ideas,

   Justin

   On Jul 8, 11:38 am, Chas Emerick cemer...@snowtide.com wrote:
   I think there's a lot of value to having good documentation and
   examples available directly in your development environment.  I'm not
   sure what a reasonable alternative would be for that context other
   than having the examples and docs included (or at least, adjacent, as
   set-examples! allows for).  It certainly seems reasonable to ensure
   that such information is not included in whatever distribution of
   clojure you would ship (whatever that means in your context).

   The details are sticky though, and would involve touching processes
   that aren't the most forgiving AFAICT (i.e. the core clojure build  
   and
   surrounds).

   - Chas

   On Jul 7, 2010, at 4:35 PM, Moritz Ulrich wrote:

   I don't think examples should be integrated in the
   function-definition. It's *way* to much bloat.

   I like the wayhttp://clojure-examples.appspot.com/clojure.coregoes.
   A wiki-like documentation for examples, linked to every
   clojure-namespace. These examples could be serialized into some data
   structure and integrated in clojure.jar. This would result in no  
   bloat
   for core.clj etc. and nice, accessible examples for our
   development-tools.

   On Wed, Jul 7, 2010 at 9:05 PM, John Cromartie
   jcromar...@gmail.com wrote:
   I've whipped up a proof-of-concept of how to implement built-in
   examples for functions and macros. The general idea is to add an
   attribute to the var that contains a list of docstrings and arg  
   lists
   or code that illustrate common usage.

   Let me know what you think:http://gist.github.com/466743

   It could also be useful for generating documentation.

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

   --
   Moritz Ulrich
   Programmer, Student, Almost normal Guy

  http://www.google.com/profiles/ulrich.moritz

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

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

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group

Re: examples (like doc)

2010-07-08 Thread Justin Kramer
Ah yes, I misread, thanks for clarifying.

One advantage to the semi-freeform approach of the Wiki is that the
writer can take liberties with the arrangement of prose and examples
-- like in a book. Right now most of the examples are Description:
[code] [result] but not all. An example could consist of multiple
parts -- prose-code-result-prose-code-result -- but still hold
together as a single example.

That said, I'm not married to the Wiki idea. If a consensus builds
around a metadata approach, I'd be happy to convert any examples
gathered so far into the new form.

Justin

On Jul 8, 2:40 pm, Moritz Ulrich ulrich.mor...@googlemail.com wrote:
 I think Chas Emerick is suggesting something like the following:

 http://gist.github.com/468401

 It is hard to implement on the server-side, as you store the raw
 markdown-text in the datastore. However, in this form, it's not really
 useful for ide developers, as they have to parse the html their self
 to extract the examples or they have to display the unchanged html in
 the ide.

 Maybe it's worth thinking about storing the examples one-by-one or in
 an array on the server side. It would make many things easier.





 On Thu, Jul 8, 2010 at 7:48 PM, Justin Kramer jkkra...@gmail.com wrote:
  Oh: it probably would have helped if I had said the API returns JSON,
  not straight text/HTML.

  Justin

  On Jul 8, 1:44 pm, Justin Kramer jkkra...@gmail.com wrote:
  They are separated: in the HTML version (html-content JSON
  property), code is wrapped in pre class=code, results in pre
  class=output, and verbiage in p. For the Markdown version (raw-
  content), there are plain-text delineations.

  I will change the mime-type, though...

  Justin

  On Jul 8, 1:31 pm, Chas Emerick cemer...@snowtide.com wrote:

   That's nifty.  Suggestion though: if you really want to have tools
   pull those examples so that they could be used systematically, the
   json should really be structured to clearly separate code, expected
   results, and verbiage -- linebreaks aren't enough, as I could imagine
   many functions having a *lot* of examples, and just popping up a chunk
   of scrolling text may or may not be what a typical IDE user would find
   useful.

   - Chas

   On Jul 8, 2010, at 1:05 PM, Justin Kramer wrote:

One use case I was thinking of for the Wiki is that IDEs could make
API requests for individual functions on-the-fly, or do a mass export
periodically. A basic version of the former exists now:

   http://clojure-examples.appspot.com/clojure.core/conj?format=json

The result could be displayed plain text or as HTML in a popup/
overlay/
etc.

One could even pull the examples from the Wiki and attach them to
metadata via John's set-examples!. This could be done by a function
that's only called when in REPL mode (similar to 'source' etc.).

Or it could follow the approach of the 'javadoc' function: open your
browser to a page with detailed examples.

Just some ideas,

Justin

On Jul 8, 11:38 am, Chas Emerick cemer...@snowtide.com wrote:
I think there's a lot of value to having good documentation and
examples available directly in your development environment.  I'm not
sure what a reasonable alternative would be for that context other
than having the examples and docs included (or at least, adjacent, as
set-examples! allows for).  It certainly seems reasonable to ensure
that such information is not included in whatever distribution of
clojure you would ship (whatever that means in your context).

The details are sticky though, and would involve touching processes
that aren't the most forgiving AFAICT (i.e. the core clojure build
and
surrounds).

- Chas

On Jul 7, 2010, at 4:35 PM, Moritz Ulrich wrote:

I don't think examples should be integrated in the
function-definition. It's *way* to much bloat.

I like the wayhttp://clojure-examples.appspot.com/clojure.coregoes.
A wiki-like documentation for examples, linked to every
clojure-namespace. These examples could be serialized into some data
structure and integrated in clojure.jar. This would result in no
bloat
for core.clj etc. and nice, accessible examples for our
development-tools.

On Wed, Jul 7, 2010 at 9:05 PM, John Cromartie
jcromar...@gmail.com wrote:
I've whipped up a proof-of-concept of how to implement built-in
examples for functions and macros. The general idea is to add an
attribute to the var that contains a list of docstrings and arg
lists
or code that illustrate common usage.

Let me know what you think:http://gist.github.com/466743

It could also be useful for generating documentation.

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

Re: Link to API document in the cheat sheet

2010-07-07 Thread Justin Kramer
As part of the Clojure Examples Wiki experiment, I created a page
adapted from the Cheatsheet, with links to relevant docs and examples
(not many, yet):

http://clojure-examples.appspot.com/clojure.core

It's been reorganized and revised a bit from the Cheatsheet. The
design is a little plain but it's a first cut.

Justin

On Jul 2, 5:11 pm, ngocdaothanh ngocdaoth...@gmail.com wrote:
 Hi,

 This is my nth attempt to learn Clojure.

 I think it will be an improvement if there are links to API document
 for functions in the cheat sheet (http://clojure.org/cheatsheet).
 Clicking a function name will jump right to the description for the
 function is very convenient for newbies.

-- 
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: Documentation and examples (and where is the documentation on reduce)?

2010-07-05 Thread Justin Kramer
I've integrated your suggestions into the wiki's guidelines:

http://clojure-examples.appspot.com/guidelines

Feel free to add anything else that needs mentioning. There's also a
talk page for discussion.

Justin

On Jul 2, 6:37 pm, Mike Meyer mwm-keyword-googlegroups.
620...@mired.org wrote:
 On Fri, 2 Jul 2010 14:50:18 -0700 (PDT)

 Justin Kramer jkkra...@gmail.com wrote:
  Nice, Mike. I stole your work and put it into the Wiki I created to
  see how it fit:

 http://clojure-examples.appspot.com/clojure.core/reduce

 Well, I like it, but I might be a bit biased.

 I think the important part is the rules that went into picking the
 examples. I just picked examples from Walton that followed them,
 tweaked those to build up properly, and then added the edge
 cases.http://clojure-examples.appspot.com/guidelinesactually covers
 it, but my version was more explicit, and gave a why.

 Cleaning mine version up and combining them gives:

 * Keep it simple and self contained
   - the first example shouldn't require knowing anything but clojure syntax
   - the inputs to an example should either be literals or simple expressions
   - the user shouldn't have to figure out anything but the new concept or type
 * Build up examples cumulatively
   - each example should introduce at most one new concept
   - or reinforce the previous example (though that should be kept to a 
 minimum)
   - or show the function working on a new data type

 I'd go ahead and edit the page, but figure you might want to such a
 change beforehand.

        mike
 --
 Mike Meyer m...@mired.org          http://www.mired.org/consulting.html
 Independent Network/Unix/Perforce consultant, email for more information.

 O ascii ribbon campaign - stop html mail -www.asciiribbon.org

-- 
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: Documentation and examples (and where is the documentation on reduce)?

2010-07-02 Thread Justin Kramer
Nice, Mike. I stole your work and put it into the Wiki I created to
see how it fit:

http://clojure-examples.appspot.com/clojure.core/reduce

(Note: reduce seems to be missing a doc string in 1.2 master; for
other functions doc strings show up.)

As cool as walton is, it's kind of a firehose. A curated collection of
examples (perhaps pilfering from walton and others) would be more
valuable, I think.

Justin

On Jul 2, 2:58 pm, Mike Meyer mwm-keyword-googlegroups.
620...@mired.org wrote:
 On Fri, 2 Jul 2010 07:50:45 -0700 (PDT)

 Meikel Brandmeyer m...@kotka.de wrote:
  On Jul 2, 12:18 pm, Walter van der Laan waltervanderl...@gmail.com
  wrote:
   For example you can point your browser 
   athttp://getclojure.org:8080/examples/reduce
   for reduce examples.
  Is it necessary to have 250 examples for a function which has
  effectively five variations?
  (reduce + [])
  (reduce + [1])
  (reduce + [1 2 3])
  (reduce + 0 [])
  (reduce + 0 [1 2 3])

 Seconded.

  I'm all for examples, but please: clear examples focusing on the thing
  being demonstrated. Symbol calling or showing that [1 2 3] and (list 1
  2 3) can be interchanged in the example above are nice to know, but
  don't help to understand reduce itself. They should go to their own
  sections in a tutorial.

 Yes. Symbol calling and the equivalence of [1 2 3] and '(1 2 3) aren't
 really relevant to what reduce can do. Nor is showing someone how to
 extract the arglist from a functions metadata.

 While I think the effort is marvelous, some thought should go into the
 purpose. That page looks like the purpose is to show off the
 cleverness of the person who wrote it. As such, this page is probably
 more confusing than helpful.

  PS: I also think the examples should demonstrate idiomatic clojure. [1
  2 3] is idiomatic while '(1 2 3) is not. Whatever we put in examples
  will show up in code. So be it [] vs. '() or (.java interop) vs. (.
  interop (java)) - we should pay attention!

 Ditto.

 Examples are read in order, and should be presented from simple to
 more complex. In particular, the first example shouldn't require
 knowing anything but clojure syntax. Each further example should
 introduce at most one new concept, reinforce the previous example
 (though that should be kept to a minimum), or show the function
 working on different data types - if they're not doing one of those
 things, why are they there? All the inputs to an example should be
 either literals, or the result of a simple function invocation. If the
 user has to work to figure out what the input is, they're that much
 more likely to skip the example, or - even worse - come up with the
 wrong input and hence wrong result. Finally, maybe provide one example
 (short) that might be considered a real world use.

 They really need to include an explanation. Having the expected
 results there would be nice as well.

  The 0.02€ of a guy who has not put effort in creating examples for the
  core API.

 Not wanting to be that guy (no offense intended to Meikel, he made a
 good point), here's what I think is a nice set of reduce examples:

 ; sum of 0 through 10: 45
 (reduce + (range 10))

 ; Divide 1 by 2 and then 3: 1/6
 (reduce / 1 [2 3])

 ; Build a set from a collection: #{:a :c :b}
 (reduce conj #{} [:a :b :c])

 ; Build a sorted set from multiple collections: #{1 2 3 4 5 6}
 (reduce into (sorted-set) [[3 1 2] [5 4 6]])

 ; Reverse a list: (3 2 1)
 (reduce #(cons %2 %1) [] [1 2 3])

 ; Build a hash-map from n to n squared:
 ; {0 0, 1 1, 2 4, 3 9, 4 16, 5 25, 6 36, 7 49, 8 64, 9 81}
 (reduce #(assoc %1 %2 (* %2 %2)) {} (range 10))

 ; Edge case with one argument: returns argument - 2
 (reduce conj [2])

 ; Edge case with one argument: returns argument - 1
 (reduce conj 1 [])

 ; Note that in the previous two examples, conj is not invoked, as it
 ; always returns a sequence.

 ; Edge case with no arguments: (*) - 1
 (reduce * [])

 ; Broken edge case: Wrong number of arguments passed to function:
 (reduce conj [])

 --
 Mike Meyer m...@mired.org          http://www.mired.org/consulting.html
 Independent Network/Unix/Perforce consultant, email for more information.

 O ascii ribbon campaign - stop html mail -www.asciiribbon.org

-- 
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: usage examples in clojure api docs

2010-07-02 Thread Justin Kramer
Good suggestion about the categories. Making it browsable is
important. A page that uses categories from the cheatsheet is easy to
make. Adding categories/tags and auto-generating such a page is also
doable.

Code contributions are welcome. I'm not attached to App Engine; I just
used it to learn about the platform. The code could be modified to
work with any storage backend.

I'll be spending free time in the next few days writing real examples
and seeing if anyone else follows suit. If it doesn't gain traction,
or someone else has a better approach, adding fancy features and re-
architecting is moot.

Justin

On Jul 2, 5:09 am, kredaxx kred...@gmail.com wrote:
 On 2 Lip, 09:46, Justin Kramer jkkra...@gmail.com wrote:





  Partly in response to this issue and partly to get my feet wet with
  Ring and friends, I spent the last few nights writing a proof-of-
  concept Wiki to collect structured Clojure usage examples:

 http://clojure-examples.appspot.com/

  Here's a sample function page:

 http://clojure-examples.appspot.com/clojure.core/contains%3F

  I tried to come up with something that encourages a many-hands
  approach while maintaining structure and quality. There are plenty of
  missing features, but it should be easy for anyone interested to jump
  in and write some examples. It uses a modified version of Markdown for
  syntax. Content could be exported/parsed en masse relatively easily.

  The source is on GitHub:http://github.com/jkk/clj-wiki

  Does this seem like a worthwhile approach?

  Justin

 Great! I was thinking lately of building something similar with the
 same kind of approach.

 One suggestion: the core functions should be structured into
 categories rather than listed alphabetically., that is for example:

 Maps
  - fn1
  - fn2
  - fn3
 Vectors
  - fn3
  - fn4
  - fn5
 Arithmetic
  - fn6
  - fn7
  - fn8
 etcetera.

 (Similar to what is in the cheat sheet)

 This would eliminate the tersness and it would be much easier to find
 a specific function (handy for newcomers to clojure)

 Other than that great job, I think it has big potential. It's clean,
 and easy to contribute. I will surely add some examples later today.

-- 
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 HashMaps with not more than 8 elements?

2010-05-30 Thread Justin Kramer
   user (loop [thm (transient {}),
                i 0]
           (if (= 10 i)
             (persistent! thm)
             (recur (assoc! thm i i)
                    (inc i
   {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9}


By the way, FYI:

(reduce #(assoc %1 %2 %2) {} (range 10))

or

(persistent! (reduce #(assoc! %1 %2 %2) (transient {}) (range 10)))

Reduce is handy for repeatedly assoc'ing into a hash-map.

Justin

-- 
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: promoting contrib.string to clojure, feedback requested

2010-05-26 Thread Justin Kramer
I've done Perl coding and I still mix up chomp and chop. The meaning
of trim, ltrim, and rtrim is immediately clear to me.

trim, ltrim, and rtrim could take an optional argument for characters
to strip:

(rtrim foo) ;; strip trailing whitespace
(rtrim foo \r\n) ;; equivalent to chomp

If clojure.contrib.string/butlast actually mirrored clojure.core/
butlast, it would do the same as chop (c.c.s/butlast requires an extra
arg).

Justin

On May 26, 2:08 pm, Fogus mefo...@gmail.com wrote:
  chomp has a clear meaning to anyone who's touched Perl/Ruby/shell-
  scripting.

 Believe me I can sympathize with this, but just because they are well-
 known to some doesn't mean that they are good names.  On that note,
 just because rtrim and less make sense to me... you know the
 rest.  :-)

 :f

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


Re: swank-clojure and GNU Emacs 23 - package.el install issues

2010-05-17 Thread Justin Kramer
Per Phil Hagelberg's suggestion on IRC, I downloaded and used his
package.el, which fixed the issue for me:

http://github.com/technomancy/package.el/raw/master/package.el

Phil said the bug hasn't been patched upstream.

Justin

On May 17, 4:18 pm, Terrence Brannon scheme...@gmail.com wrote:
 Hello, I wanted to try out Clojure. It was my understanding that
 swank-clojure was a package GNU Emacs that would download clojure
 automatically. But the docs for it no longer say that.

 Anyway, I successfully installed slime and slime-repl using package.el
 under a manually built GNU Emacs 23 with Ubuntu.

 However, whenever I try to install swank-clojure or clojure, the
 package system reports:

 let: File exists:
 /home/metaperl/.emacs.d/elpa/clojure-mode-1.7.1/clojure-mode.el

 Manually removing the directory
 /home/metaperl/.emacs.d/elpa/clojure-mode-1.7.1 and trying again
 simply leads to the same error.

 Here is the output of M-x report-emacs-bug

 In GNU Emacs 23.2.1 (i686-pc-linux-gnu, GTK+ Version 2.18.3)
  of 2010-05-14 on locohost
 Windowing system distributor `The X.Org Foundation', version 11.0.10604000
 configured using `configure  '--with-x-toolkit=gtk''

 Important settings:
   value of $LC_ALL: nil
   value of $LC_COLLATE: nil
   value of $LC_CTYPE: nil
   value of $LC_MESSAGES: nil
   value of $LC_MONETARY: nil
   value of $LC_NUMERIC: nil
   value of $LC_TIME: nil
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: nil
   locale-coding-system: utf-8-unix
   default enable-multibyte-characters: t

 Major mode: Apropos

 Minor modes in effect:
   desktop-save-mode: t
   shell-dirtrack-mode: t
   show-paren-mode: t
   global-auto-revert-mode: t
   tooltip-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

 Recent input:
 triple-mouse-4 triple-down-mouse-4 triple-mouse-4
 triple-down-mouse-4 triple-mouse-4 triple-down-mouse-4
 triple-mouse-4 triple-down-mouse-4 triple-mouse-4
 help-echo down-mouse-1 mouse-movement mouse-1
 down-mouse-5 mouse-5 double-down-mouse-5 double-mouse-5
 triple-down-mouse-5 triple-mouse-5 triple-down-mouse-5
 triple-mouse-5 triple-down-mouse-5 triple-mouse-5
 help-echo down-mouse-1 mouse-movement mouse-1
 C-x 2 C-x b * m e s return C-p C-p C-p C-p C-p C-p
 C-p C-p C-p C-p C-p C-p C-p C-v C-l help-echo help-echo
 help-echo help-echo help-echo help-echo help-echo
 down-mouse-1 mouse-movement mouse-1 down-mouse-4
 mouse-4 double-down-mouse-4 double-mouse-4 triple-down-mouse-4
 triple-mouse-4 triple-down-mouse-4 triple-mouse-4
 down-mouse-4 mouse-4 down-mouse-4 mouse-4 double-down-mouse-4
 double-mouse-4 down-mouse-1 mouse-movement mouse-1
 i x C-x o C-x o C-x d backspace return g n n n
 n ! r m SPC - r f return g C-x o x y e s return
 ESC  C-x o ESC  C-x b * return ESC  help-echo
 help-echo help-echo help-echo down-mouse-1
 mouse-movement mouse-1 help-echo down-mouse-1
 mouse-movement mouse-movement drag-mouse-1 g
 p p v C-x k return p p p p p v ESC  C-x k return
 help-echo down-mouse-1 mouse-movement mouse-1
 down-mouse-5 mouse-5 double-down-mouse-5 double-mouse-5
 triple-down-mouse-5 triple-mouse-5 triple-down-mouse-5
 triple-mouse-5 triple-down-mouse-5 triple-mouse-5
 triple-down-mouse-5 triple-mouse-5 down-mouse-4
 mouse-4 double-down-mouse-4 double-mouse-4 triple-down-mouse-4
 triple-mouse-4 triple-down-mouse-4 triple-mouse-4
 down-mouse-5 mouse-5 down-mouse-5 mouse-5 help-echo
 help-echo help-echo help-echo help-echo down-mouse-1
 mouse-movement mouse-movement drag-mouse-1 help-echo
 help-echo down-mouse-1 mouse-movement mouse-1
 down-mouse-4 mouse-4 double-down-mouse-4 double-mouse-4
 triple-down-mouse-4 triple-mouse-4 triple-down-mouse-4
 triple-mouse-4 triple-down-mouse-4 triple-mouse-4
 triple-down-mouse-4 triple-mouse-4 down-mouse-1
 mouse-movement drag-mouse-1 down-mouse-5 mouse-5
 double-down-mouse-5 double-mouse-5 triple-down-mouse-5
 triple-mouse-5 triple-down-mouse-5 triple-mouse-5
 triple-down-mouse-5 triple-mouse-5 down-mouse-5
 mouse-5 down-mouse-1 mouse-movement mouse-1
 x down-mouse-1 mouse-movement mouse-1 down-mouse-5
 mouse-5 double-down-mouse-5 double-mouse-5 triple-down-mouse-5
 triple-mouse-5 triple-down-mouse-5 triple-mouse-5
 down-mouse-1 mouse-movement mouse-1 help-echo
 help-echo help-echo down-mouse-1 mouse-movement
 mouse-1 ESC x m e a c s - backspace backspace
 backspace backspace backspace backspace e m
 a c s - b u tab tab tab C-g f1 a b u g return
 C-x o C-v C-s e m a s c ESC x r e p o r t e backspace
 - e m tab return

 Recent messages:
 byte-code: Beginning of buffer
 Mark set
 Contacting host: tromey.com:80
 Reading [text/plain]... 28k of 28k (100%)
 Reading... done.
 let: File exists:
 /home/metaperl/.emacs.d/elpa/clojure-mode-1.7.1/clojure-mode.el
 byte-code: End of buffer [2 times]
 Quit
 Type M-x display-buffer RET to restore 

Re: Check my idioms?

2010-03-21 Thread Justin Kramer
Check out clojure.contrib.io (Clojure 1.2) or clojure.contrib.duck-
streams (Clojure 1.1):

(use 'clojure.contrib.io)
(defn save-map [f m]
  (write-lines f (for [[k v] m] (str k \tab v

Or, using your code...

(defn save-map [f m]
  (spit f (apply str (interleave (apply concat m) (cycle \t\n)


Justin

On Mar 20, 8:22 pm, Mark J. Reed markjr...@gmail.com wrote:
 (I'd say something about my own particular idiom, but that's more of a
 Python thing.)

 Anyway, new to Clojure but not to Lisp or Java.  Writing something to
 interoperate with some Perl code that stores a hash in a simple flat
 file syntax:

 key1tabvalue1newlinekey2tabvalue2newline...

 sorted on the keys.

 These are my load and save routines; the load has nothing to handle
 misformatted files yet, but I'm just looking to get a feel for
 idiomatic Clojure.  Do these look reasonable?  The save routine feels
 a little clunky to me.

 (defn load-map [filename]
     (apply sorted-map (re-seq #[^\n\t]+ (slurp filename

 (defn save-map [the-map filename]
     (doto (java.io.FileWriter. filename)
         (.write (apply str (interleave (apply concat (seq the-map)
 (cycle \t\n (.close)))

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: newbie question about ns and :require

2010-01-25 Thread Justin Kramer
You may find this ns cheatsheet helpful:

http://gist.github.com/284277

Justin

On Jan 24, 10:28 am, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi all,
 I'm stumbling about the very basics.

 Calling clojure like this:

 rlwrap java
 -cp 
 /home/manfred/clojure/clojure.jar:/home/manfred/clojure/clojure-contrib.jar
 clojure.main

 I try:

 user= (ns my (:require clojure.contrib.classpath))
 nil
 my=

 which to me looks fine.

 But why does this fail?

 my= (classpath)
 java.lang.Exception: Unable to resolve symbol: classpath in this
 context (NO_SOURCE_FILE:2)

 --
 Hope it is not too much stupidity on my side,
 Manfred

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