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 Cloju

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 no

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

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

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

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

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

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

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

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

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,

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 Googl

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

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 Goog

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 subscribe

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

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)

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 cloj

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 c

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 a

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,

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

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

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 perfec

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 No

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 ti

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

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 solv

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

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

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"

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 dynam

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 t

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* [t

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

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 t

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

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

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

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 t

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

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

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 no

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

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

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 m

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 e

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 n

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\", :key

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

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 subsc

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 func

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

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

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

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 la

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 abou

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 #'use

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 wi

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 be

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

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 ,

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 p

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

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 li

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 expressio

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 G

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

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 unsubsc