Re: Newbie: applying arguments into a macro

2009-02-08 Thread samppi
Oh, yeah. Silly me, I *can* do that. Thanks a lot. It works like a charm now. On Feb 8, 2:17 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 08.02.2009 um 00:40 schrieb samppi: (defn conc* [tokens subrules]  (loop [subrule-queue (seq subrules), remaining-tokens (seq tokens

Re: Newbie at macros: Manipulating a vector of bindings

2009-02-14 Thread samppi
phase. What is the pattern for what is allowed or prohibited in macros? On Feb 13, 10:52 pm, Chouser chou...@gmail.com wrote: On Fri, Feb 13, 2009 at 11:17 PM, samppi rbysam...@gmail.com wrote: I'm trying to write a macro that expands from this: (product-context [n rule0, m rule1)]  (rule

Newbie: Separating and grouping the elements in a bunch of vectors

2009-02-15 Thread samppi
What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either.

Re: Fully lazy sequences are coming - feedback wanted!

2009-02-15 Thread samppi
While it's not the most important issue, I agree with CuppoJava about Sequence vs Seq, while we're talking about names. This pair of terms seems sort of arbitrary, and will probably cause a little semantic pain and confusion to newcomers in the future. Is there a better term than Sequence and Seq

Re: Newbie: Separating and grouping the elements in a bunch of vectors

2009-02-15 Thread samppi
, Feb 15, 2009 at 7:42 PM, David Nolen dnolen.li...@gmail.com wrote: (map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat dog bird]) On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote: What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0

Re: Embed A Struct Within A Struct

2009-02-16 Thread samppi
You can nest structs in structs like this: (defstruct rect :height :width) (defstruct colored-rect :color :shape) (def subject (struct colored-rect :red (struct rect 50 30))) (println subject) ; prints {:color :red, :shape {:height 50, :width 30}} The defstruct macro takes a var and a bunch

Re: Newbie: Separating and grouping the elements in a bunch of vectors

2009-02-16 Thread samppi
Thanks a lot, everyone. Isn't (reduce conj [] (apply map vector [[:a :b] [1 2] ['a 'b]])) equivalent to (into [] (apply map vector [[:a :b] [1 2] ['a 'b]])) though? On Feb 16, 3:55 pm, Laurent PETIT laurent.pe...@gmail.com wrote: And to get the enclosing vector: (reduce conj [] (apply map

Newbie: Where is clojure.jar?

2009-02-19 Thread samppi
So I've downloaded the latest, lazier version of Clojure. But I'm having trouble; there used to be a clojure.jar file in the folder, and it's not there anymore. The distribution's readme.txt still says: To Run java -cp clojure.jar clojure.lang.Repl, but I only see a clojure.iml file.

Re: Newbie: Where is clojure.jar?

2009-02-19 Thread samppi
Oh, of course. Thanks for the help. On Feb 19, 2:22 pm, Vincent Foley vfo...@gmail.com wrote: Run ant On Feb 19, 4:00 pm, samppi rbysam...@gmail.com wrote: So I've downloaded the latest, lazier version of Clojure. But I'm having trouble; there used to be a clojure.jar file in the folder

Re: dotimes suggestion

2009-02-21 Thread samppi
For now, I do: (dotimes [_ 3] (print Ho)) But I also think it would be a nice, natural addition. On Feb 21, 3:07 pm, Timothy Pratley timothyprat...@gmail.com wrote: +1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

Re: arguments to dissoc and select-keys

2009-02-21 Thread samppi
Allowing dissoc and select-keys to accept both keys as arguments and as a collection would be nice, and backwards compatible. In any case, ostensibly it should be consistent; otherwise, it's just an idiosyncrasy in the language that people will have to deal with. I wonder what the reasoning is

Re: arguments to dissoc and select-keys

2009-02-21 Thread samppi
I see—that explains a lot. On Feb 21, 5:01 pm, Rich Hickey richhic...@gmail.com wrote: On Feb 21, 5:58 pm, samppi rbysam...@gmail.com wrote: Allowing dissoc and select-keys to accept both keys as arguments and as a collection would be nice, and backwards compatible. Nope - Collections

Re: Becoming lazy

2009-02-22 Thread samppi
A good summary is here: http://clojure.org/lazier Note that all this has indeed been committed to the latest SVN of Clojure. I think that most of clojure.contrib has been updated too. On Feb 22, 1:32 pm, jim jim.d...@gmail.com wrote: Is there a summary of the changes to Clojure that the lazy

Re: The Application Context Pattern

2009-02-27 Thread samppi
It looks really nice. I have a question about those observers, though-- every time that a context-processing function is called, every observer is called one by one, no matter what the context-processing function was. This seems somewhat inefficient, more so than listeners that listen to only

Re: Question on names of errors in error-kit

2009-03-04 Thread samppi
Yeah. Personally, I don't think they should stand out any more than a struct basis needs to stand out. (defstruct person :fname :lname) (struct person Bob Joe) (deferror parse-error {...}) (raise parse-error ...) Defined errors are just variables in a namespace, whose siblings include the

Re: categorizing forms

2009-03-08 Thread samppi
I like it; it's making me realize the existence of a bunch of functions I've never considered before. If it's practical, consider doing color-coding or somehow indicating the types of the forms: special forms, macros, and functions. :) On Mar 8, 6:30 pm, Mark Volkmann r.mark.volkm...@gmail.com

Re: categorizing forms

2009-03-09 Thread samppi
That's a great idea. I guess the easiest way to implement this is to make it standard to include tags: at the top or bottom of a docstring: (defn pmap tags: parallel, map Blah blah blah. ...) (find-doc parallel) --- (pmap ...) tags: parallel, map Blah blah blah. That'd be a cool,

A syntax feature request: splitting literal strings

2009-04-03 Thread samppi
I wish I could do this: (code... Long error string that doesn't fit within 80 characters but is descriptive, \ which is good, right? ...more code...) (The string above would say, Long error string that doesn't fit within 80 characters but is descriptive, which is good, right?)

Re: A syntax feature request: splitting literal strings

2009-04-04 Thread samppi
-indent) ...more indented code) On Apr 3, 11:35 pm, samppi rbysam...@gmail.com wrote: I don't really want it so much for documentation strings—they're already formatted in a standard way—than just being able to embed large literal text in my code without making

Re: A syntax feature request: splitting literal strings

2009-04-04 Thread samppi
Of course–it's good that Clojure does that. :) Along with the fact that it's intuitive, docstrings are in a standardized style to print nicely with (doc): (defn foo First line is wrapping around and is indented by two spaces. But this is only because (doc) allows for this, indenting the

Re: A syntax feature request: splitting literal strings

2009-04-04 Thread samppi
felt like using                              in my program.)) This is a really long string that I just felt like using in my program. -Stuart Sierra On Apr 4, 11:26 am, samppi rbysam...@gmail.com wrote: I see—perhaps using (str) would indeed be the best answer. I'll be doing

Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread samppi
In addition, it's a bad idea to have these two superficially similar functions have the same name, file. If, in the end, both are to be kept public, then I think they should at least be given different names. On Apr 6, 10:35 am, Victor Rodriguez vict...@gmail.com wrote: Hello, On Mon, Apr 6,

Is there a simple Clojure data schema/validation library?

2009-04-09 Thread samppi
I've been whipping up a simple schema library for validating Clojure data based on their tags, but I'm worried that what I'm doing might be redundant with an already existing library. Is there something, such as in clojure-contrib, that can do things similar to the code below (note the

What is the difference between :type and :tag metadata?

2009-04-13 Thread samppi
In this message (http://groups.google.com/group/clojure/msg/ d88d9319adfc41a6), Mr. Hickey mentioned a supported convention for tagging, the :type metadata. I thought that this was the function of the :tag metadata, though, which isa? and the hierarchy functions use. What is the difference? Do

Simple sequence question: inserting something after blocks of fulfilling elements

2009-04-22 Thread samppi
Let's say I have a sequence of integers: (def a (3 9 1 5 102 -322 ...)) Is there a function for inserting an object—let's say :foo—after elements that fulfill a certain predicate? Furthermore, I mean inserting :foo after any block of elements that fulfill it: (mystery-function (partial 6)

Testing a character with a Unicode range

2009-04-25 Thread samppi
Let's say I want to test if a Unicode character is within a certain range, #x0-#x1F. What can I do? (defn char-in-range? [minimum maximum testee] ???) (def x \3) (char-in-range? \u \u001F x) ; false --~--~-~--~~~---~--~~ You received this message

Re: Testing a character with a Unicode range

2009-04-25 Thread samppi
Wonderful; thank you! On Apr 25, 10:57 am, billh04 h...@tulane.edu wrote: (defn char-in-range? [minimum maximum testee]   (let [int-testee (int testee)]         (and (= int-testee (int minimum)) (= int-testee (int maximum) On Apr 25, 12:47 pm, samppi rbysam...@gmail.com wrote: Let's

32-bit Unicode character literals

2009-04-26 Thread samppi
In the REPL: Clojure user= \u0032 \2 user= \u1 java.lang.IllegalArgumentException: Invalid unicode character: \u1 How would I embed the character as a literal in my Clojure code? --~--~-~--~~~---~--~~ You received this message because you are subscribed

Would it be worth rewriting a parser library to use monads?

2009-04-27 Thread samppi
I have a library called FnParse, and I'm wondering if I should rewrite it using monads. (You can see FnParse's documentation at http:// wiki.github.com/joshua-choi/fnparse and its implementation at http:// github.com/joshua-choi/fnparse/blob/

The function of clojure.contrib.accumulators

2009-04-29 Thread samppi
Could someone give me a simple example of when clojure.contrib.accumulators is useful? Its use seems to involve collections (and numbers) that have the :clojure.contrib.accumulators/ accumulator type, and it has some general multimethods for adding and combining, but what does it add that conj

Re: The function of clojure.contrib.accumulators

2009-04-30 Thread samppi
Okay; thanks for the answer! I understand now. On Apr 29, 11:52 pm, Konrad Hinsen konrad.hin...@laposte.net wrote: On 29.04.2009, at 21:44, samppi wrote: Could someone give me a simple example of when clojure.contrib.accumulators is useful? Its use seems to involve collections

Macro newbie: calling another macro

2009-04-30 Thread samppi
I'm having trouble trying to create a macro that calls domonad with one argument already filled in: (domonad parser-m rest-of-arguments). parser-m is a monad defined in the same namespace. This is what I have right now: (defmacro complex [steps product-expr] `(domonad ~parser-m ~steps

Re: Macro newbie: calling another macro

2009-04-30 Thread samppi
30, 8:47 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 30.04.2009 um 17:39 schrieb samppi:  (defmacro complex    [steps product-expr]    `(domonad ~parser-m ~steps ~product-expr)) Just leave out the ~ in front of parser-m. And I'm not sure how you want to handle product-expr

What's the function that returns the opposite of a predicate?

2009-04-30 Thread samppi
I know there's a core function that takes a predicate and returns its opposite: (defn mystery [predicate] (fn [x] (not (predicate x I'm having a lot of trouble finding the name of it in the docs, though. Could anyone give me its name? Or does this function not exist in the core?

Re: What's the function that returns the opposite of a predicate?

2009-04-30 Thread samppi
Wonderful. I didn't think of searching for opposite. Thanks everyone. On Apr 30, 11:25 am, Stephen C. Gilardi squee...@mac.com wrote: On Apr 30, 2009, at 1:50 PM, samppi wrote: I know there's a core function that takes a predicate and returns its opposite: (defn mystery [predicate

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

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 %)).

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

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

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

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

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

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

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

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

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

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

Newbie question: converting a sequence of map entries into a map

2008-10-28 Thread samppi
I'm new at Clojure, but I'm really liking it, though. I'm having trouble with using map on a map, and turning the resulting sequence of map entries into a new map. In other words, how can you turn this: ([:a 2] [:b 3]) ...into... {:a 2, :b 3}? Thanks in advance.

Newbie question: testing if an object is a Struct of a certain kind

2008-10-29 Thread samppi
Is there a way to test an object if it's a certain kind of struct? (defstruct person :name :age) (def president (struct person Sam 30)) (struct? person president) ; true Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are

Re: Newbie question: testing if an object is a Struct of a certain kind

2008-10-29 Thread samppi
Okay, I understand. Thanks for the answer. On Oct 29, 12:01 pm, Graham Fawcett [EMAIL PROTECTED] wrote: On Wed, Oct 29, 2008 at 2:29 PM, samppi [EMAIL PROTECTED] wrote: Is there a way to test an object if it's a certain kind of struct?  (defstruct person :name :age)  (def president

Simple isa? question—ISeq and Sequential

2008-11-14 Thread samppi
On the type chart (http://clojure.googlegroups.com/web/chart.png? gda=ODsxtzsAAABoLitVpBTEcNIQc_NHg39S4VDJlSuqwy9lITiADmvt9Suq- FEWrXmgYiTWWcOQKecGRdr3QrylPkw2aRbXD_gF), it indicates that ISeq implements Sequential. So why is this false? (isa? clojure.lang.ISeq clojure.lang.Sequential)

Re: Simple isa? question—ISeq and Sequential

2008-11-14 Thread samppi
I see. Yes, I downloaded the latest release on SourceForge, version 20080916. I don't know how to use SVN so I can't get the bleeding edge, but it's okay. I was just puzzled. Thanks for answering! On Nov 14, 8:09 am, Chouser [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 10:04 AM, samppi

Re: Newbie question: Can a collection contain itself?

2008-11-14 Thread samppi
Yeah, I surmised as much. The thing is, I'm writing a YAML library in Clojure, and YAML allows circular recursion like that: --- x - 3 - 2 - 1 - *x ...So I'm wondering what I should do if a document like that were loaded. Ah well, I'll worry about that later. On Nov 14, 4:05 pm,

Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} Anyone have any idiomatic ideas? --~--~-~--~~~---~--~~ You

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this:   (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m]   (if (empty? m) '()     (let [kv (first m)]       (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
Excellent! I must remember about the apply function. Thank you very much. On Nov 14, 9:35 pm, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote: Yeah, I need

Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread samppi
, that's fine, and for the flatten: (interleave (keys m) (vals m)) Rich On Fri, Nov 14, 2008 at 9:42 PM, samppi [EMAIL PROTECTED] wrote: Excellent! I must remember about the apply function. Thank you very much. On Nov 14, 9:35 pm, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14

Newbie question: Sequences from a function

2008-11-15 Thread samppi
Is there a way to make a lazy sequence whose sequential values are derived from some function? I'm thinking about two ways: (recursive-fn-seq f initial [n]) ; returns (initial (f initial) (f (f initial)) ...) n or infinity times (index-fn-seq f initial [n]); returns ((f i) (f (inc i)) (f

Newbie: Optional parameters without multiple definitions

2008-11-15 Thread samppi
Is there a more concise way of expressing an optional parameter with a default other than writing another entire definition? That is, instead of: (defn a-function ; two parameters, x and y, and y is 23 by default ([x] (a-function x 23) ([x y] ...)) ...is it possible to do something

Re: Newbie: Default map parameters

2008-11-17 Thread samppi
Ah! Thank you. On Nov 17, 2:48 pm, Rich Hickey [EMAIL PROTECTED] wrote: On Nov 17, 4:22 pm, samppi [EMAIL PROTECTED] wrote: Inhttp://groups.google.com/group/clojure/browse_thread/thread/62140a28b..., the following example was given: (defn test1 [{x :x, y :y, :or {:y 3}}]         [x y

(Newbie) Are lexically-scoped methods possible?

2008-11-18 Thread samppi
I'm trying to unit-test a library with which a user can define methods on the library's multi-function to change its behavior. So I need to be able to define lexically-scoped methods in each test. Is it possible to use let to create a lexically-scoped method? The problems I'm encountering are

Re: (Newbie) Are lexically-scoped methods possible?

2008-11-18 Thread samppi
Yes, but I meant creating methods rather than regular functions, in a lexical scope. Is it possible to create methods using fn? On Nov 18, 10:47 pm, Allen Rohner [EMAIL PROTECTED] wrote: On Nov 18, 6:48 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to unit-test a library with which a user

Dividing by zero and floating-point infinity

2008-11-19 Thread samppi
I am not familiar with how Java's arithmetic works, but it seems from http://hanuska.blogspot.com/2007/08/arithmeticexception-vs-nan.html and http://www.concentric.net/~Ttwang/tech/javafloat.htm that dividing a double or float by 0 should result in positive or negative infinity (like

(Newbie) Multimethod dispatch by a function other than isa?

2008-11-19 Thread samppi
I'm just wondering—is there a way to match methods' dispatch-values using a function other than isa?—such as with a macro. This is what I'm thinking of: (defmulti foo identity #(re-find %2 %1)) ; uses the last function instead of isa? to match (defmethod foo #xyzzy [x] x)) (defmethod

Newbie: Creating a MapEntry

2008-11-20 Thread samppi
Is it possible to create a MapEntry from scratch? The reason why I'm asking is because I want to mess with sequences of two-sized vectors, and it would be really cool if I could use the key and val functions on them rather than (get % 0) and (get % 1): (map #(str Key: (key %) Value: (val %))

Re: Newbie: Creating a MapEntry

2008-11-20 Thread samppi
Thank you very much. On Nov 20, 10:07 pm, Stephen C. Gilardi [EMAIL PROTECTED] wrote: On Nov 21, 2008, at 12:03 AM, samppi wrote: Is it possible to create a MapEntry from scratch? user= (def a (clojure.lang.MapEntry. 3 4)) #'user/a user= (key a) 3 user= (val a) 4 user= You can also

Re: Newbie: Adding metadata to a method

2008-11-23 Thread samppi
On Sat, Nov 22, 2008 at 7:32 AM, samppi [EMAIL PROTECTED] wrote: I'm trying to unit-test a mutli-function's methods without resorting to a separate test file. I can do this:  (defn foo    ([x] (+ x 2))    {:test (fn [] (= (foo 3) 4))}) ...but how do I do something like this?  ; Does

Working with trampoline and map

2008-11-25 Thread samppi
(declare a2) (defn a1 [x] #(vector :a (a2 x) :e)) (defn a2 [x] (if (coll? x) #(apply vector (map a1 x)) x)) (defn a [x] (trampoline a1 x)) (def b (a [[3 5] 1])) (println b) I'd like this program to print: [:a [[:a [[:a 3 :e] [:a 5 :e]] :e] [:a 1 :e]] :e]. Instead, it

Newbie: Why does .length work on strings but not .isEmpty ?

2008-11-27 Thread samppi
user= (.length ) 0 user= (.isEmpty ) java.lang.IllegalArgumentException: No matching field found: isEmpty for class java.lang.String (NO_SOURCE_FILE:0) Why does .length, but not .isEmpty, work on Strings? --~--~-~--~~~---~--~~ You received this message because

Newbie: Flattening any collection

2008-11-30 Thread samppi
For any given collection [3 2 [3 5 1] 1 [3 4 1] 0], how may I get [3 2 3 5 1 1 3 4 1 0]? Thanks in advance! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Newbie: Flattening any collection

2008-11-30 Thread samppi
Wonderful, thank you! On Nov 30, 9:42 pm, Brian Doyle [EMAIL PROTECTED] wrote: As long as you have the clojure.contrib jar in your path you can do: (use 'clojure.contrib.seq-utils) (flatten [1 2 3 '(4 5 6)]) = (1 2 3 4 5 6) On Sun, Nov 30, 2008 at 9:36 PM, samppi [EMAIL PROTECTED] wrote

License of/permission for Clojure's logo

2008-12-03 Thread samppi
I want to put the Clojure logo: http://clojure.googlegroups.com/web/Clojure-logo.png?gda=y8lqvUIAAABoLitVpBTEcNIQc_NHg39S6iU75fHiOxnOGiH4bfPrlzZZL8wLBEcX9EgDZpMYxIxV4u3aa4iAIyYQIqbG9naPgh6o8ccLBvP6Chud5KMzIQ ...on Wikipedia's article on Clojure. What is the license of Clojure's logo--is it a

Re: License of/permission for Clojure's logo

2008-12-04 Thread samppi
Ah ha ha ha. Wow, my mistake. I'll make sure to spell it correctly. I totally agree with cogfun, though—it's a really nice logo. Did you make it yourself? On Dec 4, 5:23 am, Rich Hickey [EMAIL PROTECTED] wrote: On Dec 3, 11:30 pm, samppi [EMAIL PROTECTED] wrote: I want to put the Clojure

Re: clojure.contrib.test-is: first major rewrite

2008-12-07 Thread samppi
On Dec 7, 8:51 am, Stuart Sierra [EMAIL PROTECTED] wrote: 2. Nested test contexts, as in RSpec and some other testing frameworks. I would wholeheartedly love if tests could be nested. Even if it was as simple as appending a phrase to each nested test: (defcontext str-starts-with? (deftest

Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread samppi
to various criteria. What is the purpose of a nested test context in RSpec?  Can a test belong to more than one nested test context? Bill On Dec 7, 4:20 pm, samppi [EMAIL PROTECTED] wrote: I would wholeheartedly love if tests could be nested. Even if it was as simple as appending a phrase

Re: License of/permission for Clojure's logo

2008-12-08 Thread samppi
PROTECTED] wrote: On Dec 3, 11:30 pm, samppi [EMAIL PROTECTED] wrote: I want to put the Clojure logo:http://clojure.googlegroups.com/web/Clojure-logo.png?gda=y8lqvUIAAABo... ...on Wikipedia's article on Clojure. What is the license of Clojure's logo--is it a free image? Or can Mr. Hickley give

Re: Learning Clojure

2008-12-11 Thread samppi
Great article, but I'm not sure this part in the keyword section is correct: Keywords exist simply because, as you'll see, it's useful to have names in code which are symbol-like but not actually symbols. Keywords have no concept of being namespace qualified as they have nothing to do with

Newbie: Creating a character from a Unicode sequence

2008-12-22 Thread samppi
Is there a way to turn this: [\3 \5 \A \3] ...into this? \u35A3 --~--~-~--~~~---~--~~ You 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

Library's requirements and namespace name

2009-01-01 Thread samppi
Let's say that I have a parser library--let's call it FnParse--that I want to share with the world and let others use. If it requires another library, say, clojure.contrib.test-is, is there a way for me to indicate that that library is required? Or is the only thing I may do is indicate it in the

Newbie: Creating a macro that just calls a function but evaluates its arguments lazily

2009-01-11 Thread samppi
Let's say I have a function, alt: (defn alt [ functions] (fn [tokens] (some #(% tokens) functions))) It creates a function from a bunch of sub-functions that accepts one collection of tokens and figures out which sub-function returns a true value when the tokens are plugged into it. Is

Re: Newbie: Creating a macro that just calls a function but evaluates its arguments lazily

2009-01-11 Thread samppi
. -Stuart Sierra On Jan 11, 4:44 pm, samppi rbysam...@gmail.com wrote: Let's say I have a function, alt: (defn alt [ functions]   (fn [tokens]     (some #(% tokens) functions))) It creates a function from a bunch of sub-functions that accepts one collection of tokens and figures out which

Re: Newbie: Creating a macro that just calls a function but evaluates its arguments lazily

2009-01-13 Thread samppi
Thank you for the explanation; I understand it a lot better now. The reason that I decided to use Delays was that I thought I would need to change less. Now that I've actually changed everything to Delays, it seems that they take much more time (the opposite of what I was trying to do :(. But

Newbie: What is the function of refer-clojure?

2009-01-20 Thread samppi
I'm trying to get into more of how namespaces work. The refer function refers to all the public variables of a library. What is the point of refer-clojure, though? When would you use it? What variables of clojure.core are not normally present in a new namespace?

Newbie: sync vs. dosync

2009-01-23 Thread samppi
sync and dosync's documentation seems to be virtually the same, except for the unimplemented flags-ignored-for-now parameter of sync. What is the difference in their functions? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-01-24 Thread samppi
I'm trying to learn Swing, so I'm writing the most robust Celsius converter app that I can. I've separated the conversion work into a separate SwingWorker thread, so this requires Java 6. Does anyone have any suggestions? (ns org.sample.play-with-swing.multithreaded-celsius-converter

Re: Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-01-27 Thread samppi
? On Jan 27, 9:08 am, Keith Bennett keithrbenn...@gmail.com wrote: samppi - I don't suggest using SwingWorker for this unless you just want to practice using it for education's sake. The calculation time is effectively zero in an application like this where actions are user- triggered, so

Re: Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-01-28 Thread samppi
: samppi - Typical Swing programs create a window with all its components and event handlers in the main thread, and then launch the event handling thread implicitly by calling setVisible(true) on the window (usually a JFrame). I've always done it this way, and have never had a problem. However

Re: Got a Clojure library?

2009-01-29 Thread samppi
Name: fnparse URL: http://github.com/joshua-choi/fnparse Author: Joshua Choi Tags: parsing, rules Licens: EPL Dependencies: clojure-contrib Description: fnparse is a library for creating functional parsers in the Clojure programming language. It presents an easy, functional way to create parsers

How to capture printing in a unit test

2009-02-04 Thread samppi
I want to test if a certain function prints a certain message to the system's standard output. How may I go about doing this? (defn printing-fn [] (print YES)) (deftest test-printing-fn (some-context-that-switches-the-default-target-of-printing (printing-fn) (is (=

Re: How to capture printing in a unit test

2009-02-04 Thread samppi
Awesome. Thanks for the answers, everyone. On Feb 4, 3:07 pm, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 04.02.2009 um 23:01 schrieb Laurent PETIT: this should work for you :    (binding [*out* (java.io.StringWriter.)]       (printing-fn)       (= (.toString *out*) YES)) There

Newbie: Trying to defer evaluation of unbound variable arguments until needed with macros

2009-02-05 Thread samppi
I tried asking about this yesterday, but it seems like I expressed my problem poorly. Anyways, here's another shot. :) I have a little parser library. With its metafunctions, one can create rules that accept tokens and spit out a result or nil if the tokens it receives are invalid. For instance,

  1   2   >