Re: (list* ())

2010-01-23 Thread samppi
The Clojure parser I'm writing needs to differentiate between nil and the empty list. It should parse [1 2 3] and read that as [1 2 3], and the same for lists, maps, and sets. If it parses () and reads that nil, then it's not working correctly. In addition, code in some other libraries I'm

(list* ())

2010-01-22 Thread samppi
This is not a big deal: it is a quibble with a weird and inconvenient behavior of list*: when given an empty sequence, it returns nil instead of the empty list. Why is this? According to list*'s documentation, list* should always return a list. -- You received this message because you are

Re: (list* ())

2010-01-22 Thread samppi
thought list* was to list as vec is to vector. On Jan 22, 2:55 pm, ataggart alex.tagg...@gmail.com wrote: On Jan 22, 1:30 pm, samppi rbysam...@gmail.com wrote: This is not a big deal: it is a quibble with a weird and inconvenient behavior of list*: when given an empty sequence, it returns nil

Re: (list* ())

2010-01-22 Thread samppi
@DeSeno: list*'s doc does indeed say that the last element will be treated as a seq, but the beginning of the same doc definitely says that list* returns a list. The doc is: Creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence. The last

Re: (list* ())

2010-01-22 Thread samppi
? (list* 1 [2 3])) ; Danger false I'll just go back to using #(apply list %). But this is very weird: if list* never returns lists (except when given a single non-empty list argument), why call it list*? And why say in the doc that it returns lists? On Jan 22, 10:36 pm, samppi rbysam...@gmail.com

Re: What's the idiomatic way to parse a binding form

2010-01-12 Thread samppi
Do you also want the binding to act like let's, with unpacking of vectors and maps? If so, there's no public function that I know of that's set apart for doing this—are you trying to do this in a function or a macro? If you're creating a macro, then it's easy: just splice the binding form into a

Monad problem: rewriting a recursive domonad call to not blow up the stack

2009-12-26 Thread samppi
For those of you who are familiar with Clojure monads, please consider the following problem. In the REPL log below, I define a monad parser- m whose monadic values are parser functions (in fact, it's the same as state-m, only with nil indicating failure) and a function rep+ that creates a new

Sequence puzzle

2009-12-24 Thread samppi
I'm having trouble with figuring out something. First, to get the first element of a sequence so that (pred element) is false, you do (first (drop-while pred sequence)). This is lazy, and stops immediately when the element is found. Now, I want to get the element *right before* the element

Re: Sequence puzzle

2009-12-24 Thread samppi
)) And get the last entry of that user=(last (take-until odd? [2 4 6 8 9 10 11])) 8 It's based on take-while, so it's lazy. Sean On Dec 24, 1:34 pm, Chouser chou...@gmail.com wrote: On Thu, Dec 24, 2009 at 1:24 PM, samppi rbysam...@gmail.com wrote: I'm having trouble with figuring

How to modify the last few elements of a vector

2009-12-16 Thread samppi
I'm using a vector as a stack. I want to apply a function–let's call it modify-element, one argument—to the elements from k to (- (count a- vector) k). Right now, I have something like (not tested yet): (reduce #(update-in %1 [%2] modify-element) a-vector (range k (- (count a-vector) k))) Is

Trying to rewrite a loop as map/reduce

2009-12-15 Thread samppi
I'm trying to rewrite a loop to use higher-level functions instead. For pure functions f1, f2, f3, f4, f5, f6?, and f7, and a Clojure object a0, how can one rewrite the following loop to use map, reduce, etc.? (loop [a a0] (let [b (f1 a) c (f2 b) d (f3 c) e (f4

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread samppi
)) (def d (comp f3 c)) (def e (comp f4 d)) (def g (comp f5 c)) (def h (comp f5 f2)) (def return-fn e) (def predicate-fn #(if (or (f6? (b %)) (= (g %) (h % (def recur-fn #(f7 (d a) (b a))) Is it something like that you expected ? 2009/12/15 samppi rbysam...@gmail.com

Re: Code arrangement for understandability

2009-12-10 Thread samppi
If it's for side-effects, then using _ is fine, in my opinion—they're nicely identifiable. They're especially useful for inserting println calls for seeing the value of something when I'm debugging; in fact, this is the primary way I do debugging. I would say, though, that usually if you're going

Re: Is str supposed to be able to output lazy strings?

2009-12-06 Thread samppi
Also, you should also consider simply using the seq function, which is what you should use when you want just to evaluate a lazy sequence: (str (seq (map identity [1 2 3]))) (1 2 3) On Dec 6, 11:20 am, CuppoJava patrickli_2...@hotmail.com wrote: This is expected behavior. eg. (str (map

Code improvement: Can this loop be expressed as higher-level function calls?

2009-12-06 Thread samppi
I've read that loop/recur is less preferable to using higher-level function calls like reduce and for and map, especially when chunked seqs are implemented. But is can the loop below be rewritten to use those functions instead? It's a loop that iterates over one vector and changes both the vector

Re: Code improvement: Can this loop be expressed as higher-level function calls?

2009-12-06 Thread samppi
That's incredible: that my big loop could be collapsed into such little code. Thanks a lot; I'm still wrapping my brain around these functions, but they're so awesome. On Dec 6, 1:20 pm, ataggart alex.tagg...@gmail.com wrote: On Dec 6, 11:28 am, samppi rbysam...@gmail.com wrote: I've read

Modeling a relation: maps or vectors, one ref or many refs

2009-12-04 Thread samppi
I want to create a little Clojure library that creates cached relational systems in the style of Ben Moseley's Out of the Tar Pit (http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf), which is something that I think would serve me better than just nested maps for something. I'm at the planning

Re: Modeling a relation: maps or vectors, one ref or many refs

2009-12-04 Thread samppi
internally: instead of a set of tuples/maps, a map of indexes to tuples/maps. It'd probably be the fastest, but perhaps harder to edit?) On Dec 4, 4:37 pm, Alex Osborne a...@meshy.org wrote: samppi rbysam...@gmail.com writes: I want to create a little Clojure library that creates cached

Small problem: convert [a b c d] into [[[a b] c] d]

2009-11-30 Thread samppi
The title says it all. Is there a nice, concise, Clojurey way to convert a vector [a b c d] into [[[a b] c] d]? It's fine if the vectors are sequences instead. I can't think of a way without a loop, but I suspect there's a much shorter way. -- You received this message because you are subscribed

Re: Small problem: convert [a b c d] into [[[a b] c] d]

2009-11-30 Thread samppi
Dang. I forgot about reduce. Thanks a lot for the really quick answer! On Nov 30, 3:45 pm, Martin DeMello martindeme...@gmail.com wrote: On Tue, Dec 1, 2009 at 4:09 AM, samppi rbysam...@gmail.com wrote: The title says it all. Is there a nice, concise, Clojurey way to convert a vector [a b c

Re: Monad problems: finding an m-zero

2009-11-24 Thread samppi
by deftype with the failed state's metadata attached to it. Thank goodness that metadata doesn't affect equality. On Nov 24, 1:37 am, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 21 Nov 2009, at 06:31, samppi wrote: And no matter what I do, I can't fulfill that second axiom. Has anyone created

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread samppi
Variable-length arguments in protocols seem to be supported, but there's just a weird, stateful behavior. Look what happens when you call foo first with one argument twice (it fails both times), then two arguments (it succeeds), then one argument again (it succeeds now too!). Is this a Clojure

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread samppi
I see; then that of course would be the reason. Thanks for the answer. On Nov 23, 12:24 pm, Rich Hickey richhic...@gmail.com wrote: On Nov 23, 11:36 am, samppi rbysam...@gmail.com wrote: Variable-length arguments in protocols seem to be supported, but there's just a weird, stateful

Re: Monad problems: finding an m-zero

2009-11-22 Thread samppi
Thanks for the help. After working it out, I just figured out that the reason why the second axiom isn't fulfilled by the m-zero above is this part in m- bind: ((product-fn product) new-state)) product-fn, which in the second axiom's case is (fn [x] m-zero), gets

Re: Monad problems: finding an m-zero

2009-11-22 Thread samppi
on the object representing failure. I'm sure I'll figure something out.) Thanks for your help. On Nov 22, 1:31 pm, jim jim.d...@gmail.com wrote: Samppi, Good work on figuring that out. It's by working through those kinds of problems that you really learn about monads. It is indeed the case

Does a standard function exist that acts like assoc except it applies fns to vals

2009-11-22 Thread samppi
Does a function that does this: (vary coll :x fn-x, :y fn-y) ; Equivalent to (assoc coll :x (fn-x (:x coll)), :y (fn-y (:y coll))) exist in the core or contrib APIs? I'm surprised that I can't find any. It's a very natural extension of assoc. But if there really isn't any, is the code below

Re: Does a standard function exist that acts like assoc except it applies fns to vals

2009-11-22 Thread samppi
Ah, update-in is exactly what I need. Excellent, thank you. On Nov 22, 2:38 pm, John Harrop jharrop...@gmail.com wrote: On Sun, Nov 22, 2009 at 4:32 PM, samppi rbysam...@gmail.com wrote: Does a function that does this:  (vary coll :x fn-x, :y fn-y)  ; Equivalent to (assoc coll :x (fn-x (:x

Mysterious errors w/ protocols and types

2009-11-22 Thread samppi
The following code contains an error, and I cannot figure out what it is at all. When I run StateMeta's test once, the statement marked with a comment above fails. When I run it again, it succeeds. This has been causing very weird bugs in my code. I've replicated the behavior in both a script and

Re: Monad problems: finding an m-zero

2009-11-21 Thread samppi
for reasons I can't explain. What is this monad's proper value of m-zero? On Nov 21, 8:28 am, jim jim.d...@gmail.com wrote: Samppi, Here's a parser-m monad I did. (defmonad parser-m           [m-result (fn [x]                         (fn [strn]                             (list x strn

Monad problems: finding an m-zero

2009-11-20 Thread samppi
I'm writing a maybe/state monad using clojure.contrib.monads. I've gotten by fine with using just (state-t maybe-m), but now I need different behavior: I need a monad that behaves precisely like (state-t maybe-m), except that when a monadic value mv is called on a state s and fails, (mv s)

Re: Datatypes and Protocols - early experience program

2009-11-18 Thread samppi
This is wonderful, wonderful, wonderful. It makes my work with FnParse so much easier. Question: are the general mechanisms for accessing and setting fields their keywords and assoc respectively: (deftype Bar [a b c d e]) (def b (Bar 1 2 3 4 5)) (:c b) (def c (assoc b :e 2)) Does (:c b)

Code improvement: incrementing a meta val

2009-11-18 Thread samppi
Is there a more elegant way to phrase this? (defn- inc-index Increments the :index val in the givens state's metadata. [state] (vary-meta state assoc :index (inc (:index ^state -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this

Re: Language request: make key and val work on vector pairs too

2009-11-13 Thread samppi
. On Nov 11, 9:52 am, samppi rbysam...@gmail.com wrote: Clojure 1.1.0-alpha-SNAPSHOT user= (conj (first {1 2}) 3) [1 2 3] user= (conj {1 2} [2 5]) {2 5, 1 2} user= (key (first {1 2})) 1 user= (key [1 2]) java.lang.ClassCastException: clojure.lang.PersistentVector cannot

On defvar's order of arguments

2009-11-02 Thread samppi
I use clojure.contrib.def/defvar a lot. It's really useful for adding docstrings to non-function vars. But I've been tripped up by the same mistake a lot now—I keep expecting the docstring to go after the initial value, because that would be consistent with defn, defmacro, and defmulti. Here are

add-watch's functions' first argument

2009-10-26 Thread samppi
According to the docs, the function passed into an add-watch call receives four arguments. Its first argument is a key. This key seems to be the same key as the key passed into the add-watch call, and so would always be the same, for the same ref and function. What is the point of this argument

Re: add-watch's functions' first argument

2009-10-26 Thread samppi
Well, that's how the key itself is useful. What I'm wondering is why it is useful for the key to be passed to the watching function every time it's called. On Oct 26, 1:13 pm, pmf phil.fr...@gmx.de wrote: On Oct 26, 8:12 pm, samppi rbysam...@gmail.com wrote: According to the docs

with-meta overwrites existing metadata; is there a way to just add

2009-10-25 Thread samppi
with-meta's behavior is annoying for me. I often have something like this: (defn a [blah] (with-meta blah {:type ::incredible})) (defn b [foo] (with-meta (a foo) {::b 2})) I'd like ^(b []) to be {:type ::incredible, ::b 2}. But with-meta overwrites the metadata from a completely. Is there a

Re: with-meta overwrites existing metadata; is there a way to just add

2009-10-25 Thread samppi
Excellent; this is perfect. I wonder why I didn't find it when I searched the docs...thanks a lot, though. On Oct 25, 3:16 pm, Phil Hagelberg p...@hagelb.org wrote: samppi rbysam...@gmail.com writes: with-meta's behavior is annoying for me. I often have something like this:   (defn

binding and threads

2009-10-25 Thread samppi
Here's something that I've been confused about for a long time: I've read many, many times that binding allows you to give to vars thread-specific values, and that vars have a thread-global value too. I think that I understand how vars and binding work, but I don't understand how binding is

Re: Macro newbie: Trying to create a map template

2009-10-24 Thread samppi
Thanks a lot! I didn't know about the existence of gensym. This will help a lot. On Oct 23, 9:54 pm, John Harrop jharrop...@gmail.com wrote: On Sat, Oct 24, 2009 at 12:19 AM, samppi rbysam...@gmail.com wrote: user= (defmacro b [form]  (let [processed-form (a form rec#)]    `(fn [rec

Code improvement: searching a tree

2009-10-24 Thread samppi
I suspect the code below can be improved. The function returns the set of all symbols inside a list-tree that are not at the beginning of a list. Is there a way to make the code more compact or faster? (with-test (defn- find-dependencies [rel-rep] (cond (list? rel-rep)

Re: Code improvement: searching a tree

2009-10-24 Thread samppi
symbol? (tree-seq seq? rest rel-rep - James On Oct 24, 9:55 pm, samppi rbysam...@gmail.com wrote: I suspect the code below can be improved. The function returns the set of all symbols inside a list-tree that are not at the beginning of a list. Is there a way to make the code more compact

Macro newbie: Trying to create a map template

2009-10-23 Thread samppi
I'm trying to create a macro called procedure so that: (procedure (and _x (pos? _y))) expands to (fn [rec#] (and (:x rec#) (pos? (:y rec# I'm stuck because I can't figure out a way to generate a symbol outside. I'm a newbie at macros, so I don't know if there's a better way around this:

Re: Standard calling-a-function function?

2009-10-22 Thread samppi
That is indeed nice. Thanks for the code; I guess I don't really have to settle for #(%) after all. @RandyHudson: apply would work, but it's pretty slow, and not worth switching from #(%). On Oct 21, 11:49 pm, Timothy Pratley timothyprat...@gmail.com wrote: On Oct 22, 3:22 pm, John Harrop

Private multimethods possible?

2009-10-22 Thread samppi
Are private multis possible? I notice that clojure.contrib.def does not have a defmulti-, which doesn't bode well, but it's still worth a question at the mailing list. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

Standard calling-a-function function?

2009-10-21 Thread samppi
Is there a standard function that takes one argument and calls it? That is, the function equivalent to #(%). Or is that the best idiom there is? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post

Re: Standard calling-a-function function?

2009-10-21 Thread samppi
[_ 500] (apply a))) Elapsed time: 0.923 msecs nil On Oct 21, 5:04 pm, James Reeves weavejes...@googlemail.com wrote: apply On Oct 22, 12:49 am, samppi rbysam...@gmail.com wrote: Is there a standard function that takes one argument and calls it? That is, the function equivalent

Re: Standard calling-a-function function?

2009-10-21 Thread samppi
...@gmail.com wrote: On Wed, Oct 21, 2009 at 7:49 PM, samppi rbysam...@gmail.com wrote: Is there a standard function that takes one argument and calls it? That is, the function equivalent to #(%). Or is that the best idiom there is? #(%) is only four characters. Calling apply with only one

Re: - vs comp

2009-10-16 Thread samppi
Don't forget about the third piece of the puzzle, #() (and fn). Whenever I need to create a function using -, I just do #(- % ...). It's about as much typing as (comp ...). Personally, I can go either way—I just kind of wish that there was a consistent practice for the placement of the most

vimclojure: commenting lines

2009-10-14 Thread samppi
I realize that this isn't directly related to Clojure proper, but I'm learning Vim while using VimClojure, and I think this is probably the best place to ask—is there a command to comment all the lines through a motion with semicolons? --~--~-~--~~~---~--~~ You

Re: vimclojure: commenting lines

2009-10-14 Thread samppi
Ah, it's a shame that there's no devoted command to commenting. Thanks for that command, though. Maybe I should record a macro for it... On Oct 14, 6:47 pm, Richard Newman holyg...@gmail.com wrote: I realize that this isn't directly related to Clojure proper, but I'm learning Vim while using

Is there a standard function transforming a map's vals

2009-10-10 Thread samppi
Is there a function in the standard libraries that's equivalent to this: (defn transform-map [pred a-map] (into {} (map (comp pred val) a-map))) (is (= {:a 4, :b 3} (transform-map inc {:a 3, :b 2}))) It's not like I can't write this myself; I use this a lot, though, and I'm

Re: Is there a standard function transforming a map's vals

2009-10-10 Thread samppi
differently (defn transform-map [f a-map] ...) The f implies a mapping operation.  pred implies a filter operation. On Oct 10, 8:40 pm, samppi rbysam...@gmail.com wrote: Is there a function in the standard libraries that's equivalent to this:   (defn transform-map [pred a-map

On

2009-10-04 Thread samppi
I want to do this: (defn a ...) (cache a) ; or (cache #'a) or (cache 'a); it doesn't matter to me ...instead of this: (def a (memoize (fn ...))) That way, it separates the concern of what a does from the optimization I'm doing on it. Now, I'm kind of stuck; how should I do it? (defn

On Google App Engine and reference types

2009-10-01 Thread samppi
I've heard a lot that Google App Engine's use of many JVMs makes Clojure refs, etc. less useful than they are on one JVM. I'm curious— what are the consequences of using a ref normally in Google App Engine? How would it be broken? Would each JVM, invisibly, each store a different value for the

Metadata and sequences

2009-09-21 Thread samppi
Why does metadata not work on conj-ed sequences? Clojure 1.0.0- user= (def a (with-meta [1 2 3] {:a 2})) #'user/a user= ^(conj a 4) {:a 2} user= (def b (with-meta (seq [1 2 3]) {:a 2})) #'user/b user= ^b {:a 2} user= ^(conj b 4) nil --~--~-~--~~~---~--~~ You

Re: Metadata: something funny

2009-09-20 Thread samppi
That's perfect. Thanks a lot, everyone. On Sep 20, 11:35 am, Jarkko Oranen chous...@gmail.com wrote: (def b #^{:b 2} (quote (1 2 3))) ... and #^{} applies read-time to the following *form* rather than the value they evaluate to, so that is why neither (list ...) nor (quote ...) work.

On the reader macro #=

2009-08-25 Thread samppi
#= is a real Clojure reader macro. It often shows up when using *print- dup*: Clojure 1.0.0- user= (binding [*print-dup* true] (println {:a 3, :b 2})) #=(clojure.lang.PersistentArrayMap/create {:a 3, :b 2}) nil user= #=(clojure.lang.PersistentArrayMap/create {:a 3, :b 2}) {:b 2, :a 3} It's

Re: On the reader macro #=

2009-08-25 Thread samppi
That's great! Thanks a lot for the explanation. On Aug 25, 2:58 pm, Richard Newman holyg...@gmail.com wrote: Incidentally, you can find this stuff out by reading the source, if   you know where to look. It's a reader macro, so LispReader.java is the   best place to start. Look for the

Re: How to generate a hash map from a list

2009-08-24 Thread samppi
Wonderful; I totally didn't know about zipmap. I've been using into and map this whole time. Was it added right before Clojure 1.0? It seems to be a lot faster than using into: Clojure 1.0.0- user= (time (into {} (for [i [1 2 3]] [i (+ 3 i)])) ) Elapsed time: 0.705 msecs {3 6, 2 5, 1 4} user=

A little discovery: abbreviated-namespace-qualified keywords

2009-08-24 Thread samppi
I just discovered something cool that might seem obvious to some people but is, as as I can tell, undocumented and caught me totally by surprise. It's well known that the reader resolves ::something into :the-current-namespace/something. But what I found out is that if you use require to alias a

Using a map vs. using a metadata map

2009-08-21 Thread samppi
I'm trying to make a decision in a parser library between using regular maps as states (containing a sequence of remaining tokens, as well as other info) vs. using metadata maps attached to the sequence of remaining tokens. In other words: {:remainder [\r \e \m], :index 3, :line 5, :column 2}

Re: New string utilities library ready

2009-08-19 Thread samppi
For me, I'd like it if the core functions had the data as the first argument, but have a special function—I can't come up with a better name than partial-2—so that (partial-2 function opt1 opt2 opt3) is equivalent to (fn [data] (function data opt1 opt2 opt3)). That way, I could do things like

Using the var special-form

2009-08-18 Thread samppi
Why doesn't this work? Clojure 1.0.0- user= (declare aaa) #'user/aaa user= (var (symbol aaa)) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol (NO_SOURCE_FILE:2) user= (var 'aaa) java.lang.ClassCastException: clojure.lang.Cons cannot be cast to

Re: Transient Data Structures

2009-08-10 Thread samppi
Excellent, excellent. But I'm wondering, is it planned (or feasible) for structmap transients to be supported too? I often use and modify protean structmaps in loops, and I'd love to know if the concept of transients can be applied to them. On Aug 6, 4:53 am, Rich Hickey richhic...@gmail.com

Re: binding and bundles of variables

2009-08-10 Thread samppi
, samppi rbysam...@gmail.com wrote: I have about six variables that are often rebound together using binding; these variables are used to access and set data in a state object (whose type is of the user's choice). These variables' values (the accessors and setters) are often used

Re: binding and bundles of variables

2009-08-07 Thread samppi
Great, thanks. Is clojure.lang.Var/pushThreadBindings a public, supported part of the API? Can I use it without fear of suddenly dropped support? On Aug 6, 10:56 pm, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Aug 7, 7:12 am, samppi rbysam...@gmail.com wrote: So is this possible without

binding and bundles of variables

2009-08-06 Thread samppi
I have about six variables that are often rebound together using binding; these variables are used to access and set data in a state object (whose type is of the user's choice). These variables' values (the accessors and setters) are often used together. I'd like to be able to bundle these

Re: Newbie question about anonymous functions

2009-08-02 Thread samppi
Also, identity works too: #(identity foo) ; equivalent to (fn [] foo) On Aug 2, 10:04 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 02.08.2009 um 17:56 schrieb Sean Devlin: 1.  Use quote #(quote foo) For this approach I would recommend `do`: (let [x 5] #(quote x)) ; *meeep*

Re: Has anyone tried using Clojure with JavaFX?

2009-07-31 Thread samppi
layer from any defined set of functions with certain metadata on them. That's the current direction I'm thinking of taking the idea. If you are interested, I can ship over the Netbeans project of it all. Sam Griffith Jr. On Jul 29, 6:19 pm, samppi rbysam...@gmail.com wrote: I haven't

Has anyone tried using Clojure with JavaFX?

2009-07-29 Thread samppi
I haven't tried JavaFX much myself, but has anyone tried or thought about using Clojure to manage the logic and data of a JavaFX application yet? What limitations would there be, other than having to compile its Clojure code? --~--~-~--~~~---~--~~ You received this

Function of clojure.templates

2009-07-20 Thread samppi
I've just discovered the clojure.templates library [1], and I'm wondering what's the difference between its function and that of regular functions: (apply-template '[x] '(+ x x) '[2]) ((fn [x] (+ x x)) 2) [1]

Is there a standard function testing if a sequence starts with a sequence

2009-07-17 Thread samppi
Is there a function in clojure.core or clojure.contrib so that: (and (mystery-fn '(a b c d) '(a b)) (not (mystery-fn '(a b c d) '(a b d --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To

Re: Is there a standard function testing if a sequence starts with a sequence

2009-07-17 Thread samppi
Awesome, thanks for the quick answer. I think that it'd be a useful thing to add to seq-utils or something. :) On Jul 17, 1:41 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Fri, Jul 17, 2009 at 1:32 PM, samppirbysam...@gmail.com wrote: Is there a function in clojure.core or

Re: ANN: FnParse, a functional parsing library

2009-07-14 Thread samppi
MacGyver wmacgy...@gmail.com wrote: Thanks for the tip on looking at clojure.contrib. I keep forgetting to check there. On Jul 5, 2009, at 4:20 PM, samppi rbysam...@gmail.com wrote: If you need a JSON parser, there's already a good one included with clojure.contrib. The one

Re: Idea for contrib.def: defmemo

2009-07-09 Thread samppi
Excellent. This will be a lifesaver—thanks a lot. On Jul 9, 8:21 am, Chouser chou...@gmail.com wrote: On Jul 8, 11:53 pm, samppi rbysam...@gmail.com wrote: In clojure.contrib.def, I'd love to have a defmemo macro that acts just like defn, only with memoize. I'm planning to change a lot

Idea for contrib.def: defmemo

2009-07-08 Thread samppi
In clojure.contrib.def, I'd love to have a defmemo macro that acts just like defn, only with memoize. I'm planning to change a lot of functions to use memoize, and I'm not looking forward to changing nice, clean defns with docstrings to (def {:doc docstring} function (memoize (fn ...)))s. Would

Re: ANN: FnParse, a functional parsing library

2009-07-05 Thread samppi
timely, I need to parse a bunch on JSON files on Monday :) good work Sent from my iPhone On Jul 4, 2009, at 3:16 PM, samppi rbysam...@gmail.com wrote: I'm pleased to announce FnParse, a monadic functional parsing library for Clojure, half a year in the making. I started on FnParse

ANN: FnParse, a functional parsing library

2009-07-04 Thread samppi
I'm pleased to announce FnParse, a monadic functional parsing library for Clojure, half a year in the making. I started on FnParse in December as my first Clojure project, and now it has matured to something that I believe is very and immediately useful. Currently, I'm writing a YAML parser using

Speedy accessors for the trees of clojure.xml

2009-06-29 Thread samppi
clojure.xml/parse returns a PersistentStructMap. Is there a way to refer to its struct template? I wish to create accessors for its keys, such as :tag, :attrs, and :content, with the accessor function for speed. --~--~-~--~~~---~--~~ You received this message

Re: Speedy accessors for the trees of clojure.xml

2009-06-29 Thread samppi
Wonderful. Thanks for the answer. On Jun 29, 2:47 pm, Rich Hickey richhic...@gmail.com wrote: On Jun 29, 4:59 pm, samppi rbysam...@gmail.com wrote: clojure.xml/parse returns a PersistentStructMap. Is there a way to refer to its struct template? I wish to create accessors for its keys

Re: Speedy accessors for the trees of clojure.xml

2009-06-29 Thread samppi
-struct :a :b :c)) (keys (struct st)) (:a :b :c) -Adrian. On Tue, Jun 30, 2009 at 12:14 AM, samppi rbysam...@gmail.com wrote: Wonderful. Thanks for the answer. On Jun 29, 2:47 pm, Rich Hickey richhic...@gmail.com wrote: On Jun 29, 4:59 pm, samppi rbysam...@gmail.com wrote

How to shorten clojure.lang.* classes

2009-06-28 Thread samppi
I use Clojure's classes a lot in my multimethods. Is there any way to abbreviate them; that is, is there a method to refer to clojure.lang.APersistentList as APersistentList? I've tried (use 'clojure.lang) and (require ['clojure.lang :as 'c]), but neither seem to work.

Re: How to shorten clojure.lang.* classes

2009-06-28 Thread samppi
Wonderful. Thanks for the answers. On Jun 28, 12:39 pm, Stephen C. Gilardi squee...@mac.com wrote: On Jun 28, 2009, at 3:03 PM, samppi wrote: I use Clojure's classes a lot in my multimethods. Is there any way to abbreviate them; that is, is there a method to refer

Re: Small question: inserting something at the beginning of a vector

2009-06-26 Thread samppi
Thanks for the replies, everyone. @Mr. Gilardi, this is for a one-time only thing. I have a function, called rep*, that builds up a vector from left to right. Another, separate function, called rep+, calls rep*, but it needs to slip in an element at the vector's beginning. I'm considering

Re: Small question: inserting something at the beginning of a vector

2009-06-26 Thread samppi
Thanks for the replies. Mr. Brandmeyer's solution is exactly what I needed; I don't really want to change rep+'s return value from a vector, which would sort of break backwards compatibility. On Jun 26, 8:25 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 26.06.2009 um 17:09 schrieb samppi

Are keywords and symbols garbage-collected?

2009-06-24 Thread samppi
Are keywords and symbols garbage-collected? If I generated a lot of keywords or symbols, put them into a collection, and then removed them, would they disappear and free up space? I'm wondering if they're similar to Ruby symbols, which are never garbage collected.

Re: Are keywords and symbols garbage-collected?

2009-06-24 Thread samppi
Thanks for the answers. I need to generate symbols to distinguish them from strings in a parser. It seems, then, that it's better to use symbols rather than keywords in this case. On Jun 24, 10:52 am, Stephen C. Gilardi squee...@mac.com wrote: On Jun 24, 2009, at 1:30 PM, Four of Seventeen

Small question: inserting something at the beginning of a vector

2009-06-24 Thread samppi
Currently, if I want to do this: (mystery-fn [0 1 2 3 4] -1) - [-1 0 1 2 3 4]), I use vec and cons: (vec (cons a-vec obj-to-insert)). Is there a better way? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure

Small question: Best way to create a map with vector vals

2009-06-23 Thread samppi
The idiom (into {} coll-of-entries) is often used to create a map from a collection of entries or two-sized vectors. But what if I want to do something like this: (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]]) ; returns {:a [1], :b [3 5], :c [1]}) The only way I can think of doing this is with a

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread samppi
Thanks everyone. They all seem to take less time than the filter way too. On Jun 23, 4:05 pm, Cosmin Stejerean cstejer...@gmail.com wrote: On Tue, Jun 23, 2009 at 5:09 PM, samppi rbysam...@gmail.com wrote: The idiom (into {} coll-of-entries) is often used to create a map from a collection

In let: unpacking maps with accessors too

2009-06-08 Thread samppi
I'd love to be able to do this: (defstruct person-s :name :gender) (def name-a (accessor person-s :name)) (def gender-a (accessor person-s :gender)) (def person-1 (struct person-s Jane :female)) (let [{name name-a, gender gender-a, :as person} person-1] (println name gender person))

Using (into {} ...) on a sequence of lists vs. vectors

2009-06-01 Thread samppi
Why does using a list with into and a map throw an exception, while using a vector is fine? Clojure 1.0.0- user= (def a (list :a 1)) #'user/a user= (into {} [a]) java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry (NO_SOURCE_FILE:0) user= (def b [:a 1])

error-kit: passing a variable error type into a handle statement

2009-05-18 Thread samppi
I want to create a function that takes a variable of an error-kit error type and inserts it into a handle statement, but when I try, I get a strange error. What does the error mean, and is there a way to pass a variable error type into a handle statement without resorting to macros? Clojure

Re: More trouble with m-seq in a macro

2009-05-12 Thread samppi
konrad.hin...@laposte.net wrote: On 11.05.2009, at 23:17, samppi wrote: user= (defmacro b [ xs] `(with-monad maybe-m (m-seq ~xs))) #'user/b user= (b [1 2 3]) java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector (NO_SOURCE_FILE:0) So there's

Re: More trouble with m-seq in a macro

2009-05-12 Thread samppi
) java.lang.IllegalArgumentException: Wrong number of args passed to: monads$m-PLUS-m-seq-PLUS-m (NO_SOURCE_FILE:0) Trying both ~ and ~@ in this case gets me two kinds of errors. Thanks for your patient help. On May 12, 7:59 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On May 12, 2009, at 16:40, samppi wrote: I

Re: More trouble with m-seq in a macro

2009-05-12 Thread samppi
That works perfectly. I forgot about macroexpand-1...but I also didn't think that the (1 2 3) list would be evaluated using 1 as a function too. Thanks both of you for the great help. On May 12, 8:33 am, J. McConnell jdo...@gmail.com wrote: On Tue, May 12, 2009 at 11:22 AM, samppi rbysam

More trouble with m-seq in a macro

2009-05-11 Thread samppi
I'm having trouble using clojure.contrib.monads/m-seq in a macro. Let's say that I just want to create a macro version of m-seq. Clojure 1.0.0- user= (use 'clojure.contrib.monads) nil user= (with-monad maybe-m (m-seq [1 2 3])) (1 2 3) user= (defn a [ xs] (with-monad maybe-m (m-seq [1 2 3])))

Composing functions with or

2009-05-10 Thread samppi
Is there a core Clojure function that does this: (fn mystery [ subfunctions] (fn [ args] (some #(apply % args) subfunctions))) ...in other words, composing the functions with or. (mystery nil? (partial = the)) would be equivalent to #(or (nil? %) (= the %)).

Re: Using a monad's m-plus function inside a macro

2009-05-09 Thread samppi
Wow, I've never seen ~' before. But it works great. Thanks a lot. On May 9, 5:41 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On 09.05.2009, at 03:50, samppi wrote: I'm trying to use m-plus inside a macro like this:   (defmacro alt     [ subrules]     (with-monad parser-m

  1   2   >