Re: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-28 Thread kyle smith
On Aug 19, 12:08 pm, Brian Goslinga  wrote:
> Here is another trick that works for me in Emacs:  delete most of the
> stack of closing parens, and then spam the ) key until the Emacs
> matches it to the desired opening paren.

this.

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

2010-08-27 Thread kyle smith
I think the root of the misunderstanding is this: doto is NOT -> or -
>>

doto is typically used for initializing mutable java objects.  So,
instead of (let [foo ...] (.bar foo) (.baz foo) foo) , you can use
(doto ... .bar .baz)  It looks like you're trying to return the value
of the last expression, but like the docstring says, doto returns the
initial object itself.  Finally, your last two examples aren't
actually equivalent.  The second example returns the function itself,
but the last example actually calls the function.

-- 
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: Error when tried to compile with C-c C-k in emacs.

2010-04-15 Thread kyle smith
On Apr 8, 10:56 pm, Phil Hagelberg  wrote:
> You'll notice 90% of the "I'm having trouble with Emacs" posts have
> one thing in common: they all start with "I'm trying to install
> without ELPA".

You're assuming people haven't already tried ELPA before resorting to
manual installation.  I tried like hell to get elpa to work, even
after several people posted updated documentation/instructions, but it
seems the version of swank-clojure currently in ELPA doesn't work.
The only way I was able to get everything working again was to follow
the "My non-ELPA Emacs swank-clojure setup" instructions here:
http://groups.google.com/group/clojure/browse_thread/thread/3dba26708b164c55#

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

2010-01-22 Thread kyle smith
user> (defn inc-vals [m]
(into (empty m) (zipmap (keys m) (map inc (vals m)
#'user/inc-vals
user> (inc-vals {:a 1 :b 2})
{:b 3, :a 2}
user> (inc-vals (struct (create-struct :a :b) 1 2))
{:a 2, :b 3}
user> (= *1 *2)
true

So what's the problem (other than printing differently)?

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

2010-01-19 Thread kyle smith
http://groups.google.com/group/clojure/browse_thread/thread/806ebb1cbe671969/82a25385a2a8a18d?lnk=gst&q=unflatten#82a25385a2a8a18d
-- 
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: Recommended JVM flags for Clojure

2010-01-07 Thread kyle smith
First, make sure you have -server. If you can spare more heap, use -
Xmx1g . If you're on a 64bit jvm, -XX:+UseCompressedOops adds a
significant boost. A flag that helps quite a bit is -XX:
+DoEscapeAnalysis .  Finally, if you want to play around with the JIT
threshold, use -XX:CompileThreshold=n , where n defaults to 1.
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Fixing Lisp

2009-12-26 Thread kyle smith
This isn't fully tested, but it should work.  Lisp doesn't need
fixing.

(defmacro switch [choice-seq & clause-maps]
  (let [choice (first choice-seq)
clauses (map #(apply concat %) clause-maps)]
`(condp = ~choice ~@(apply concat (map (fn [clause]
  [(first clause) `(do ~@(next clause))]) 
clauses)

user> (macroexpand-1 '(switch (choice)
{my-choice
(having-fun)
}
{(your-choice)
(being-pragmatic)
}
{(their-choice)
(lisp-is-not-for-everyone)
}) )
(clojure.core/condp clojure.core/= choice my-choice (do (having-fun))
(your-choice) (do (being-pragmatic)) (their-choice) (do (lisp-is-not-
for-everyone)))

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


Re: Using map on multiple collections.

2009-12-23 Thread kyle smith
It's a little shorter if you unconditionally concat & repeat.

(defn append-val [val & colls]
  (let [maxlen (apply max (map count colls))]
(map #(concat % (repeat (- maxlen (count %)) val)) colls)))

user> (apply map + (append-val 0 [1] [2 3] [4 5 6]))
(7 8 6)

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

2009-12-22 Thread kyle smith
I haven't touched it in a while, but I'm going to pick it back up soon.

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

2009-12-21 Thread kyle smith
Here's the macro I used when I dabbled in Genetic Programming:

user> (time (dotimes [_ 1000]
  (intern  'user 'x (rand))
  (eval '(+ (* x x) 5
"Elapsed time: 425.754877 msecs"

user> (defmacro capture-vars [vars expr]
`(fn [...@vars] ~(first (next expr
#'user/capture-vars
user> (time (let [f (eval (capture-vars [x] '(+ (* x x) 5)))]
  (dotimes [_ 100];note the iterations!
(f (rand)
"Elapsed time: 73.936157 msecs"

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

2009-12-21 Thread kyle smith
Martin, you're trying to argue that some hypothetical 'unwashed
masses' of programmers won't like clojure because of parenthesis.  The
problem is you're just assuming it's the parenthesis, and there is no
way to know for sure (short of a peer-reviewed study).  Maybe java
programmers don't know about clojure because they're corporate drones
and couldn't care less.  Maybe they're not allowed to use clojure at
work.  Maybe (as others have said) clojure is just more mental work
per-line and that turns people away.

If you look at the group's history, I think you'll find the clojure
community is more than willing to work with people who have a genuine
problem.  However, if you come in here with unsubstantiated claims and
demand a major language change, you'll need to provide more proof that
there is an actual problem first.

-- 
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: Call for masters thesis ideas (possibly related to Clojure)

2009-12-21 Thread kyle smith
I also vote for static analysis.  People have combined static analysis
with data mining to predict software defects.
http://scholar.google.com/scholar?hl=en&q=data+mining+software+defects&btnG=Search&as_sdt=2000&as_ylo=&as_vis=0
However, it doesn't look like anyone's tried it with any functional
languages.

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


Re: how 'bout a debug-repl?

2009-12-10 Thread kyle smith
Yes, I just figured that out.  Is there a way to use this with slime?

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


Re: how 'bout a debug-repl?

2009-12-10 Thread kyle smith
I'm having some trouble with Alex's macro.  I can type in the debug-
repl, but when I hit enter, it just hangs and nothing happens.

-- 
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: clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread kyle smith

What's wrong with (map + [31 41 59 26] (iterate inc 1))  ?

(use 'clojure.contrib.seq-utils)

(defn sliding-window [coll size]
  (let [idx (into {} (indexed coll))]
(map #(vals (select-keys idx (range (- % size) (+ % size 1
 (range (count coll)

This is the same as your second example if order isn't important.
Someone else might be able to come up with something better.  Do you
have any more/better use cases?
--~--~-~--~~~---~--~~
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: Measuring code complexity

2009-10-26 Thread kyle smith

Rather than the number of nodes in a tree, I think a better metric
would be the number of edges in a graph.  Variables that are
referenced on many different lines should get double counted.  I think
this would explain why imperative spaghetti code is so complex.  On
the other hand,  I suspect functional code is generally more tree-like.
--~--~-~--~~~---~--~~
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: Linear Algebra Package

2009-10-05 Thread kyle smith

clojuratica works with the free mathematica player.  I don't think
there are any licensing issues, but I could be wrong.  I need to do
more benchmarking, but the performance is pretty good so far.
--~--~-~--~~~---~--~~
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: Debugging questions

2009-10-03 Thread kyle smith

select returns a set, so you need to call seq/vec before calling nth.

user> (nth (seq (clojure.set/select #(zero? (mod % 2)) #{1 2 5 10}))
0)
2
--~--~-~--~~~---~--~~
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: Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-22 Thread kyle smith

Clojure data structures can be printed to a string, and the string can
be read back in as a data structure.

user> (def a {:key1 "string" :key2 #{"set" "of" "strings"}})
#'user/a
user> a
{:key1 "string", :key2 #{"set" "strings" "of"}}
user> (def b (str a))
#'user/b
user> b
"{:key1 \"string\", :key2 #{\"set\" \"strings\" \"of\"}}"
user> (def c (read-string b))
#'user/c
user> c
{:key1 "string", :key2 #{"set" "strings" "of"}}
user> (= a c)
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
-~--~~~~--~~--~--~---



Re: clojure shell window?

2009-09-15 Thread kyle smith

repl.clj in the files section of the group is exactly what you want.
--~--~-~--~~~---~--~~
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: Cells for Clojure

2009-09-11 Thread kyle smith

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



Re: best way to make use of association lists

2009-09-07 Thread kyle smith

Why not just use http://clojure.org/api#sorted-map ?
--~--~-~--~~~---~--~~
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: Interactive heuristic

2009-09-06 Thread kyle smith

Are you calling System/exit when you close a window?  Why not just do
(.setDefaultCloseOperation jframe JFrame/DISPOSE_ON_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
-~--~~~~--~~--~--~---



Re: assoc-in-by

2009-08-30 Thread kyle smith

haha, the api page strikes again!  I figured something so basic would
have to be included, but I obviously didn't see update-in.  It would
be nice to have a list of related functions that do not follow the
standard nomenclature.  Will the upcoming documentation push address
this?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



assoc-in-by

2009-08-30 Thread kyle smith

I wrote this based on assoc-in.  If anyone thinks this should be in
core or contrib, feel free to use it.

(defn assoc-in-by
  "'Updates' a value in a nested associative structure, where ks is a
  sequence of keys and (f v) is the new value and returns a new nested
structure.
  If any levels do not exist, hash-maps will be created."
  [m [k & ks] f]
  (if ks
(assoc m k (assoc-in-by (get m k) ks f))
(assoc m k (f (get m k)


user> (assoc-in-by {:1 1 :2 {:3 3}} [:2 :3] inc)
{:1 1, :2 {:3 4}}
--~--~-~--~~~---~--~~
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: replace-subtree for zippers?

2009-08-22 Thread kyle smith

I've dabbled in genetic programming as well.  My approach to crossover
is simply to return a seq of indices to the node.  Then you can just
use nth repeatedly, or if your trees are nested vecs, you can use
assoc-in directly.  Then I just eval'd a fn and map-reduce'd it across
my test data.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Risks of (over-)using destructuring?

2009-07-23 Thread kyle smith

>   He has no other solution than to audit all his code
>   to locate (not necessarily a trivial task) and update the
> destructuring patterns which concern foo data.

As mentioned, this is a problem in any language. However, clojure lets
you do things in much, much less code, so I don't think it will be as
difficult as you suggest.  More importantly, clojure is functional and
has a repl, so you can either create unit tests to check the return
value of the library, or when you encounter a problem, just use the
repl to interactively debug the problem.  I think you'll find clojure
libraries are much less of a black box than in other languages.
--~--~-~--~~~---~--~~
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 Partial Evaluator

2009-07-20 Thread kyle smith

Sounds like a cool project.  Have you thought about adding peephole
optimization?  For example, the form (map inc (map inc (range 1000)))
should be equivalent to (map #(+ 2 %) (range 1000)).  I believe there
are automated methods, but it could even be as simple as a pattern-
matching, rule-based translator.
--~--~-~--~~~---~--~~
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: Simple data structure access macro

2009-07-20 Thread kyle smith

You'll want to look at the -> macro.  Read http://clojure.org/data_structures.
You can also omit nth in two cases.

   (let [nestedDS ["foo", {"hi" "there", "hello", ["buddy"]}, "hi"]
        foo (nestedDS 0)
        there (-> nestedDS (nth 1) (get "hi"))
        buddy (-> nestedDS (nth 1) (get "hello") first)
        hi (nestedDS 2)]
     (print foo there buddy hi)
    )


--~--~-~--~~~---~--~~
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: cells questions

2009-07-20 Thread kyle smith

> It looks to me like you are blowing the stack. You may want to rethink
> your commute-cells function so that it either uses the 'recur'
> operator and is tail recursive, or uses a trampoline of some sort.

When you blow the stack, you'll get an exception saying so, and it
usually happens pretty quick.
commute-cells just never finishes.  My guess is I'm somehow thrashing
the stm or something.
--~--~-~--~~~---~--~~
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.zip and root

2009-07-20 Thread kyle smith

> At the moment "root" works like an "unzip". What you want it is some
> kind of "up-till-root" shortcut.
Yep. For now, I've added root-loc to my local copy of clojure,
although I second the name unzip.

> > It would also be nice if the docs mentioned that a loc is a vector of
> > [node path].
>
> Why do you need to know?
I don't anymore.  I was just looking at the docs and I needed to
figure out how to get what I wanted.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



clojure.zip and root

2009-07-20 Thread kyle smith

I'm trying to learn how to use zippers, and I have some thoughts:  Why
does (root loc) return a node, rather than just the location of the
root?  If the latter were true and you wanted the node, you could just
call (node (root loc)).  As it is, once you call (root loc), you lose
the reference to the zipper structure.

It would also be nice if the docs mentioned that a loc is a vector of
[node path].  The doc for zipper should also say something like
"Creates a new zipper structure. Returns the loc of the root node. ..."
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



cells questions

2009-07-19 Thread kyle smith

I'm trying to use Stuart Sierra's implementation of cells.  I want to
sum the values of a large number of cells.  Rather than linearly
summing all the values, I would like to create a tree of cells whose
root contains the sum.  I added the function commute-cells:

(defn commute-cells [f cells]
  (let [len1 (count cells)
len2 (/ len1 2)]
(cond (= 1 len1)
  (first cells)
  (= 2 len1)
  (cell (f (cv (first cells))
   (cv (second cells
  true
  (cell (f (cv (commute-cells f (take len2 cells)))
   (cv (commute-cells f (drop len2 cells

This seems to work for small numbers of cells, but never finishes for
larger values.

user> (reduce + (range 10))
45
user> (def cells (map #(cell %) (range 10)))
#'user/cells
user> (def sum (commute-cells + cells))
45
user> (reduce + (range 1000))
499500
user> (def cells (map #(cell %) (range 1000)))
#'user/cells
user> (def sum (commute-cells + cells))
; Evaluation aborted.

Do I need to make this a macro?  If so, could someone help me out, and
make a macro for the linear version as well?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



flatten tools

2009-07-10 Thread kyle smith

I wrote these and thought they might be useful.  Feel free to add them
to clojure.contrib.seq-utils

(defn flatten-n [n coll]
  "Like flatten, but only goes n levels deep."
  (if (= n 0)
coll
(recur (dec n) (apply concat (map #(if (sequential? %) % (list %))
coll)

(defn- unflatten* [tree coll]
  (loop [val-tree []
 new-tree tree
 new-coll coll]
(if (nil? (first new-tree))
  [val-tree new-coll]
  (if (sequential? (first new-tree))
(let [[a b] (unflatten* (first new-tree) new-coll)]
  (recur (conj val-tree a) (next new-tree) b))
(recur (conj val-tree (first new-coll)) (next new-tree) (next new-
coll))

(defn unflatten [tree coll]
  "Returns a new tree with the same shape as tree containing the
elements of coll.
   coll must be of length #leaves of tree"
  (first (unflatten* tree coll)))


user> (unflatten [[1] [2 3] 4 [5 [6]] 7] '[a b c d e f g])
[[a] [b c] d [e [f]] g]
--~--~-~--~~~---~--~~
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 example from "A Field Guide to Genetic Programming"

2009-07-07 Thread kyle smith

> I am guessing I need to start reading and using macros at this point?

I also wrote something to do symbolic regression.  I used plain
functions to manipulate quoted trees, and one macro to wrap the
expression in a fn and eval.
--~--~-~--~~~---~--~~
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 for Scientific and other CPU-intensive Computing

2009-06-29 Thread kyle smith

On Jun 30, 2:41 am, fft1976  wrote:
> I would be curious to know if anyone is using Clojure for CPU-
> intensive work where performance really counts.

I'm using clojure for various computational physics tasks:
1. I'm writing a dsl for substructure searching.
2. I'm doing classical molecular dynamics / structure optimization.
Substructures can be included, for coarse grain md.
3. All the parameter fitting codes suck, so I wrote one that works for
atoms and/or coarse grain points.
4. Soon, I will extend my substructure searching into a full-fledged
structure database.

I haven't ran into any performance problems yet.  If I do, there are
some places where I can replace dumb algorithms with better
algorithms.  I will gladly trade the minor low-level inefficiencies of
clojure, for the ability to easily try out high-level, possibly domain
and/or data specific optimizations.  Clojure rocks!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



always-merge-with

2009-06-15 Thread kyle smith

I needed the functionality of merge-with, but need f applied in all
cases.  This version only works for 2 maps, but you can use reduce for
more maps.  This lets me incrementally build up maps whose vals can be
seqs.


(defn always-merge-with [f amap bmap]
  "Like merge-with, but always applies f"
  (loop [bkeys (keys bmap)
 bvals (vals bmap)
 result amap]
(if (nil? bkeys)
  result
  (let [bkey (first bkeys)
bval (first bvals)]
(recur (next bkeys) (next bvals)
   (merge result {bkey (f (get amap bkey) bval)}))

(defn wrap-merge [amap bmap]
  "If key doesn't exist in amap, wraps val from bmap in [].
   Useful when incrementally merging a seq of vals into hashmaps when
the vals can be seqs themselves."
  (always-merge-with #(if (nil? %1) [%2] (conj %1 %2)) amap bmap))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A text about Clojure

2009-06-12 Thread kyle smith

I would summarize your text as "misguided".  If you're using lisp/
clojure simply as a replacement for things that you can do in other
languages, then it's not going to look as attractive.  You seem to
touch on that when you talk about code generating code, but I don't
think you really understand (in a concrete sense) how to actually do
such things.  You don't even have to know about macros to eliminate
the majority of boilerplate code in lisp.  Your text may be a good
summary of the challenges of learning the language, but I don't think
it's an accurate representation overall.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: What books have helped you wrap your brain around FP and Clojure?

2009-06-06 Thread kyle smith

I read Norvig's PAIP.  The concept of first defining a dsl and then
writing an interpreter/compiler for it is amazing.  Even something as
simple as his sentence grammar shows the idea.
--~--~-~--~~~---~--~~
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: performance concerns (again)

2009-06-05 Thread kyle smith

> I am dealing w/ some performance constraints in the current
> implementation of my application.

More information, please.  What in general is your app?  What are the
specs of your machine?  What kind of data does your app deal with?

> So, although Clojure offers some
> features that would solve some of my problems, I am concerned about
> Clojure's and the JVM's performance issues.  I read the "when
> performance matters" thread and, as usual, was struck by the usual
> omission of memory-utilization from the discussion of the JVM's
> performance characteristics.  This has always puzzled me about the
> Java world and the C++ vs Java debate in general.

The reason it's ignored is that it usually only matters in micro-
benchmarks. (and because ram is dirt cheap)
Probably >99% of people spout this off without any hard numbers.
You obviously have numbers, but you should be comparing apps to apps,
not benchmarks to benchmarks.
For example, depending on the problem domain, it may be very possible
to 'cheat'.
--~--~-~--~~~---~--~~
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: New library 'redis-clojure': Feedback and questions

2009-06-05 Thread kyle smith

I just took a quick look, but string-to-seq can be defined as (re-seq
#"\S+" string), and similarly for string-to-map.
--~--~-~--~~~---~--~~
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: regression

2009-06-05 Thread kyle smith

I have generalized the code to allow more than one independent
variable.  The calling convention has changed: instead of separate x
and y seqs, there is one "xylist".  Each element of xylist is a tuple
containing the dependent variable *first*, and then any independent
variables.

I haven't had time to experiment with this version, but intuitively it
should be more difficult to search through a larger space.  If anyone
would like to supplement the code with a better search algorithm
(genetic algorithm, etc.), then feel free.
--~--~-~--~~~---~--~~
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: subtractng sequence?

2009-06-03 Thread kyle smith

How about (map - seq1 seq2) ?

An example or two of the desired output would be helpful.
--~--~-~--~~~---~--~~
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: regression

2009-05-26 Thread kyle smith

Thanks for the feedback Daniel, I've incorporated your ideas and re-
uploaded.  I'm not sure where you're seeing mutable data structures.

Anyhow, I now only call eval once each time scorer is called, which is
massively faster.
This has allowed for additional testing points, and now I get a
perfect fit in under a minute!

On a related note, it looks like I've essentially written a better
version of this:
http://www.jakevoytko.com/blog/2008/12/16/evolving-genetic-algorithms-in-lisp/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



regression

2009-05-26 Thread kyle smith

I have written code that will randomly guess the mathematical form of
a list of xy ordered pairs.  My code and a sample run are in guess-
check.clj in the files section.  The final sum of squares is
fantastic!  This code is just for fun, but I would appreciate some
feedback.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: quote vs quasiquote

2009-05-26 Thread kyle smith

Ahh, of course. I've actually learned that trick before. Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



quote vs quasiquote

2009-05-26 Thread kyle smith

user> (def nums '(1 2 3))
#'user/nums
user> (def funs '((+ (1 2 3)) (- (1 2 3
#'user/funs
user> funs
((+ (1 2 3)) (- (1 2 3)))
user> (def funs `((+ ~nums) (- ~nums)))
#'user/funs
user> funs
((clojure.core/+ (1 2 3)) (clojure.core/- (1 2 3)))

I would expect these two approaches to be the same, but when using
quasiquote, it qualifies my functions.  How can I prevent this
(without copy & paste)?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: 3d viewer

2009-05-20 Thread kyle smith

Import statements added.  Example usage:

(def coords [[0 0 0] [1 1 1] [2 2 2]]);etc
(g3d coords)

That should pop open the viewer.  Left click and drag to rotate, and
use the scroll wheel to zoom in/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
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
-~--~~~~--~~--~--~---



3d viewer

2009-05-19 Thread kyle smith

I have uploaded 3d-viewer.clj to the files section.  If anyone finds
it useful, I would appreciate some feedback.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: tree-utils

2009-05-16 Thread kyle smith

Sounds good.  Unless there are other suggestions, can someone make the
minor changes and commit it to contrib?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



tree-utils

2009-05-13 Thread kyle smith

I've uploaded tree-utils.clj to the files section.
http://groups.google.com/group/clojure/web/tree-utils.clj  Here are
some example usages:

Subtracting two (or more) trees element-by-element:
user=> atree
[[1 2] [3 4 5] [6 7]]
user=> btree
[[2 3] [4 5 6] [7 8]]
user=> (tree-reduce - atree btree)
((-1 -1) (-1 -1 -1) (-1 -1))

Recursively summing all the elements in a tree:
user=>(tree-apply #(reduce + %) true true atree)
28
user=>(tree-apply #(reduce + %) true true btree)
34

I think these are generally useful, so I'm just looking for some
feedback and possible inclusion in contrib.  Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Feature Request: Easily Embeddable Console

2009-04-29 Thread kyle smith

See repl.clj in the files section.  I've embedded it in a few of my
apps, and it's quite nice.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Java interoperability and Clojure

2009-04-04 Thread kyle smith

I wrote some functions to streamline reflection here.
http://groups.google.com/group/clojure/browse_thread/thread/ea23cd11b7bd8999/f32795d9a79eeeb9?lnk=gst&q=accessing+private#f32795d9a79eeeb9
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fully lazy sequences are coming - feedback wanted!

2009-02-15 Thread kyle smith

"It would also break the compatibility of rest with Common Lisp's"
This is of mild concern to me, but I think if there was a prominent
warning on clojure.org, I could get over it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: map across code

2009-02-14 Thread kyle smith

Well, I'm just doing some exploratory programming, so I don't really
have anything yet.

I'd like to do something like (map a-macro some-code)
What I can't do is (map #(a-macro %) some-code) because % evals each
code fragment.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



map across code

2009-02-14 Thread kyle smith

I'm trying to map across code, but map evals each item in the list.
I've been trying to re-implement map as a macro, but so far no
success.  Is there some way to accomplish this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: How to build tree with nodes that 'point' to each other?

2009-02-12 Thread kyle smith

I tackled this exact problem a few days ago.  My solution was to use
atoms (very poorly).  My code is on the group as bsptree.clj
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread kyle smith

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



Re: map-method

2009-02-05 Thread kyle smith

Of course those would work, but I got sick of typing them over and
over.

(map-method length ["mary" "had" "a" "little" "lamb"])
(map-method indexOf ["mary" "had" "a" "little" "lamb"] (int \a))

I find typing # and % repetitive, so this is just a little syntactic
sugar.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



map-method

2009-02-05 Thread kyle smith

I often need to call a java method on each element in a collection.  I
didn't find anything on the group, so I wrote a macro.

(defmacro map-method [method coll & args]
  "Calls the given method on each item in the collection."
  `(map (fn [x#] (. x# ~@(if args
 (concat (list method) args)
 (list method ~coll))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



possible bug with doto and function literals

2009-02-03 Thread kyle smith

(map #(doto %1 (.add 2)) (doto (new java.util.ArrayList) (.add 1)))

This seems like it should work, but does not.  Can anyone confirm?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: removing duplicates from combinatorics/selections

2009-02-03 Thread kyle smith

In general, this function will work for non-integer collections.  I
make no performance/laziness guarantees.

(defn selections-dups [coll n]
  (let [r (range (count coll))
f #(< (last %1) (first %1))
s (remove f (selections r n))]
(map #(map (fn [x] (nth coll x)) %1) 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
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: removing duplicates from combinatorics/selections

2009-02-03 Thread kyle smith

Ok, I'm an idiot.  All I needed was  (remove #(< (last %1) (first %1))
(selections [1 2 3 4] 3))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



removing duplicates from combinatorics/selections

2009-02-01 Thread kyle smith

The selections function in combinatorics returns more than what I
need.  (selections [ 1 2 3 4 5] 3) will return both (1 2 3) and (3 2
1), etc.  However, I still need (1 1 1) (2 2 2), etc.  I've tried
several times to write a function to filter out the 'duplicates', but
haven't quite got it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



improved gview

2009-01-28 Thread kyle smith

I have improved on chouser's gview code (http://blog.n01se.net/?
p=30).  It can now expand java.awt.Container objects.  I haven't
implemented this, but it would be nice to pass in a function to filter
leaves/nodes.

(defn container? [obj]
  (instance? (. (java.awt.Container.) getClass) obj))

(ns gview
  (:import (javax.swing JFrame JScrollPane JTree)))

(defn- make-node
  ([parent obj]
 (if (container? obj)
   (make-node parent obj #'identity #(. %1 getComponents))
   (make-node parent obj #'coll? #'seq)))
  ([parent obj ischildfn getchildfn]
   (proxy [javax.swing.tree.TreeNode] []
 (toString []  (pr-str obj))
 (getAllowsChildren [] (ischildfn obj))
 (getChildAt [i]   (make-node this (nth (getchildfn obj)
i)))
 (getChildCount [] (count (getchildfn obj)))
 (getIndex [n] -1)
 (getParent [] parent)
 (isLeaf [](not (ischildfn obj))

(defn gview [obj]
  (doto (JFrame.)
(.add (JScrollPane. (JTree. (make-node nil obj
(.setTitle (str "gview: " (.getName (class obj
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
(.pack)
(setVisible 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
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: No Indentation in SLIME

2009-01-15 Thread Kyle Smith

Thanks Bill. That's just what I needed.

On Jan 15, 7:58 am, Bill Clementson  wrote:
> Hi Kyle,
>
>
>
> On Wed, Jan 14, 2009 at 11:27 PM, Kyle Smith  wrote:
> > I'm new to Clojure, SLIME, and emacs in general but I've noticed my
> > SLIME REPL does not indent properly when I use  or C-j. This
> > is the error message I see:
>
> > "calculate-lisp-indent: Symbol's function definition is void: clojure-
> > indent-function"
>
> > I've experienced this when setting up Clojure + SLIME via .emacs and
> > also when running Clojure Box. When I open a .clj file indentation
> > works just fine. I just have trouble with the SLIME REPL.
>
> > One thing I noticed is if I evaluate the function clojure-indent-
> > function, function clojure-backtracking-indent, and custom clojure-
> > mode-use-backtracking-indent (from clojure-mode.el) within the
> > *scratch* buffer my SLIME REPL will indent correctly.
>
> > I've seen a few posts with similar problems but I haven't found a
> > solution that works.
>
> The function "clojure-indent-function" is defined in clojure-mode.el
> but clojure-mode.el is only loaded when a Clojure source file is
> opened. Therefore, if for example you opened a Clojure source file and
> then started the slime repl, you would not have the problem. However,
> you don't want to always open a Clojure source file before you start a
> repl, so to fix this, make certain that clojure-mode.el is started
> before you start the repl. This can be done in a number of ways -
> adding the following to your .emacs startup code is probably the
> easiest:
>
> (add-hook 'slime-connected-hook (lambda ()
>                                   (require 'clojure-mode)))
>
> --
> Bill Clementson
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



No Indentation in SLIME

2009-01-15 Thread Kyle Smith

Hello,

I'm new to Clojure, SLIME, and emacs in general but I've noticed my
SLIME REPL does not indent properly when I use  or C-j. This
is the error message I see:

"calculate-lisp-indent: Symbol's function definition is void: clojure-
indent-function"

I've experienced this when setting up Clojure + SLIME via .emacs and
also when running Clojure Box. When I open a .clj file indentation
works just fine. I just have trouble with the SLIME REPL.

One thing I noticed is if I evaluate the function clojure-indent-
function, function clojure-backtracking-indent, and custom clojure-
mode-use-backtracking-indent (from clojure-mode.el) within the
*scratch* buffer my SLIME REPL will indent correctly.

I've seen a few posts with similar problems but I haven't found a
solution that works.


Thanks,
Kyle

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



Re: Cells in Clojure

2008-09-20 Thread kyle smith

Maybe you could attach a cell to a JComponent and call setEnabled as
necessary.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Poll 09/2008

2008-09-13 Thread kyle smith

> What are you doing with Clojure?

I'm trying to write a DSL for molecular dynamics analysis (with
partial success).  Users will be able to compose complex properties
from basic info such as bond lengths/angles, position, velocity, etc.
I'd like to add regression and integrate it with a 3d viewer
eventually.  With some modification, this could allow users to
generate coordinates for complex structures (i.e. bio stuff like dna).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---