Re: map output to string
I am still having difficulties with this, so let me clarify by showing some sample code. My fn looks like this: (defn report [text] (str string1 string2 (apply str (map-indexed (fn [idx itm] (time-text idx itm)) (filtered-list text)) When I invoke spit in order to output a text file using the above funtion, I only get the first item in my list (filtered-list text) outputted Here is the basic code for my fns used above: (defn filtered-list [text] (let [street (:str (address text)) city (:city (address text)) state (:state (address text)) ;actually there's a bunch of other bindings, 3 will suffice for the example ] (remove nil? (conj '() (if-not (blank? street) (str ADDRESS: street)) (if-not (blank? city) (str CITY: city)) (if-not (blank? state) (str STATE: state)) (defn time-text [time-idx text-var] (str some-string (hour-min time-idx) another-string)) ;this uses the clojure time library (defn hour-min [idx] (format-local-time (plus (local-now) (minutes idx)) :hour-minute-second)) On Tuesday, July 8, 2014 2:28:52 AM UTC-7, Lee wrote: Sometimes you have to manually stamp out laziness, for this among other reasons. In some cases I apply the list function to do this: = (str (map inc (range 10))) clojure.lang.LazySeq@c5d38b66 = (str (apply list (map inc (range 10 (1 2 3 4 5 6 7 8 9 10) -Lee On 8 July 2014 09:49, Glen Rubin rubi...@gmail.com javascript: wrote: my-fn takes a number and a string as argument and outputs a string. I am using map-indexed and my-fn to comprehend a list of items with numbered index as follows, (map-indexed (fn [idx itm] (my-fn idx itm)) '(list-of-crap)) When i run this on the repl everything works well and I get a single long string of output. But, I am trying to use the output of this function in a report and it is not working in that context. The code to generate report looks something like this: (str string1 string2 string3 (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap)) string4etc... ) The code above will just print out 'clojure-lazy-seq' instead of the string output. If I try: (apply str (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap))) Then I get the last item from my list properly formated in the report, but that's all. How do I print out everything? Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: map output to string
Thanks Lee. You are correct there is something wrong with my input to this function that is causing the problem, not the function. Sorry for the error. On Tuesday, July 8, 2014 8:13:36 PM UTC-7, Lee wrote: Hi Glen, You haven't really provided what we would need to replicate your problem. Specifically: - You call but don't provide definitions for address or is-blank? - You refer to unbound symbols some-string and another-string. - You don't provide an input for report, or the top-level call you are making, that produces the problem. In addition, your report function has an extra ) at the end. I tried patching up everything in a minimal way but then I don't see a problem. -Lee On Jul 8, 2014, at 10:38 PM, Glen Rubin rubi...@gmail.com javascript: wrote: I am still having difficulties with this, so let me clarify by showing some sample code. My fn looks like this: (defn report [text] (str string1 string2 (apply str (map-indexed (fn [idx itm] (time-text idx itm)) (filtered-list text)) When I invoke spit in order to output a text file using the above funtion, I only get the first item in my list (filtered-list text) outputted Here is the basic code for my fns used above: (defn filtered-list [text] (let [street (:str (address text)) city (:city (address text)) state (:state (address text)) ;actually there's a bunch of other bindings, 3 will suffice for the example ] (remove nil? (conj '() (if-not (blank? street) (str ADDRESS: street)) (if-not (blank? city) (str CITY: city)) (if-not (blank? state) (str STATE: state)) (defn time-text [time-idx text-var] (str some-string (hour-min time-idx) another-string)) ;this uses the clojure time library (defn hour-min [idx] (format-local-time (plus (local-now) (minutes idx)) :hour-minute-second)) On Tuesday, July 8, 2014 2:28:52 AM UTC-7, Lee wrote: Sometimes you have to manually stamp out laziness, for this among other reasons. In some cases I apply the list function to do this: = (str (map inc (range 10))) clojure.lang.LazySeq@c5d38b66 = (str (apply list (map inc (range 10 (1 2 3 4 5 6 7 8 9 10) -Lee On 8 July 2014 09:49, Glen Rubin rubi...@gmail.com wrote: my-fn takes a number and a string as argument and outputs a string. I am using map-indexed and my-fn to comprehend a list of items with numbered index as follows, (map-indexed (fn [idx itm] (my-fn idx itm)) '(list-of-crap)) When i run this on the repl everything works well and I get a single long string of output. But, I am trying to use the output of this function in a report and it is not working in that context. The code to generate report looks something like this: (str string1 string2 string3 (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap)) string4etc... ) The code above will just print out 'clojure-lazy-seq' instead of the string output. If I try: (apply str (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap))) Then I get the last item from my list properly formated in the report, but that's all. How do I print out everything? Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- Lee Spector, Professor of Computer Science Cognitive Science, Hampshire College 893 West Street, Amherst, MA 01002-3359 lspe...@hampshire.edu javascript:, http://hampshire.edu/lspector/ Phone: 413-559-5352, Fax: 413-559-5438 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit
map output to string
my-fn takes a number and a string as argument and outputs a string. I am using map-indexed and my-fn to comprehend a list of items with numbered index as follows, (map-indexed (fn [idx itm] (my-fn idx itm)) '(list-of-crap)) When i run this on the repl everything works well and I get a single long string of output. But, I am trying to use the output of this function in a report and it is not working in that context. The code to generate report looks something like this: (str string1 string2 string3 (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap)) string4etc... ) The code above will just print out 'clojure-lazy-seq' instead of the string output. If I try: (apply str (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap))) Then I get the last item from my list properly formated in the report, but that's all. How do I print out everything? Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: map output to string
yes, that is exactly my issue. i am trying to get the lazy sequence fully realized as you say, but it's not happening in the context i put it in. On Monday, July 7, 2014 6:04:00 PM UTC-7, Daniel Compton wrote: Hi Glen One thing to keep in mind with lazy sequences is that running them at the REPL will force them to be fully realised, whereas a lazy sequence may not be realised in other contexts. I didn't understand where 'clojure-lazy-seq' is coming from in your question so I'm not sure if that's your issue or not. On 8 July 2014 09:49, Glen Rubin rubi...@gmail.com javascript: wrote: my-fn takes a number and a string as argument and outputs a string. I am using map-indexed and my-fn to comprehend a list of items with numbered index as follows, (map-indexed (fn [idx itm] (my-fn idx itm)) '(list-of-crap)) When i run this on the repl everything works well and I get a single long string of output. But, I am trying to use the output of this function in a report and it is not working in that context. The code to generate report looks something like this: (str string1 string2 string3 (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap)) string4etc... ) The code above will just print out 'clojure-lazy-seq' instead of the string output. If I try: (apply str (map-indexed (fn [idx itm] (my-fn idx itm)) '(listofcrap))) Then I get the last item from my list properly formated in the report, but that's all. How do I print out everything? Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
lazy list comprehension
I have a list that I want to combine in some way with an incremented list, so I was trying to write a for expression like this: (for [i '(my-list-of-crap), j (iterate inc 0)] (str i j)) The problem with this is that it yields an out of memory area. I assume this is b/c of my poor use of the iterate fn. How can I do this in a lazy way? So that iterate only produces as many items as is needed to match the number of items I have in '(my-list-of-crap). Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: lazy list comprehension
yes, map-indexed seems to make the most sense here. thanks On Friday, June 27, 2014 8:13:53 AM UTC-7, Linus Ericsson wrote: You probably want map-indexed http://clojuredocs.org/clojure_core/1.2.0/clojure.core/map-indexed /L 2014-06-27 17:10 GMT+02:00 Leonardo Borges leonardo...@gmail.com javascript:: Try using map : (map str '(my-list-of-crap) (iterate inc 0)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
if else list of commands
Pretty basic question. How do I run a couple commands in the else section on an if-else function? Or can I only run one and need to define a function that does both commands? THanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
delete-file needs to be vector?
I wrote a fn to delete a couple files: (defn del-temps (clojure.java.io/delete-file C:/temp/fs.png true) (clojure.java.io/delete-file C:/temp/fs.txt true)) When I run my program I get the following error: Exception in thread main java.lang.IllegalArgumentException: Parameter declaration clojure.java.io/delete-file should be a vector It didn't look like delete-file takes a vector from the documentation? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
generate rtf
I am writing a program that needs to process some text and then generate an RTF file. I am using the spit command, but the file I generate gives me an error message when I try opening it using Windows Word, it brings up a message box stating: Word was unable to read this document. It may be corrupt If I just 'spit' the file as plain text without any rtf control codes then it will open, but first prompt me with the file conversion dialog box. I tried encoding my file as both cp1252 and cp 437 using the :encode option, but neither made a difference. I know that this question is probably outside the scope of an official clojure question, but hoping somebody can advise on what's wrong or the direction I should look. thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
importing a single function in ns
My namespace currently looks like this: (ns providence.core (:gen-class) (:use seesaw.chooser) (:use seesaw.core) (:use clojure.java.shell)) However, I only use sh from java.shell choose-file from seesaw.chooser and alert from seesaw.core. How do I import these single functions from the namespace? I know that calling use on it's own you can use the :only keyword, however this doesn't seem to work in ns. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
use :only in ns
In my ns i am using a couple of libraries, e.g. (ns providence.core (:gen-class) (:use seesaw.chooser)) However, I only want to use 1 or 2 commands from these libraries, for example (choose-file) from the above seesaw.chooser. How do I specify only a single library? thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: deskewing image
my clojure-fu and java-fu are both pretty weak as I am still rather green. I guess I will put a hold on this for now until I am more advanced. On Monday, June 2, 2014 10:42:35 PM UTC-7, Atamert Ölçgen wrote: On Tue, Jun 3, 2014 at 5:14 AM, Glen Rubin rubi...@gmail.com javascript: wrote: I am interested in automatically deskewing of a scanned image before ocr processing using tesseract. I found the following, which is some java code to do it http://anydoby.com/jblog/en/java/1990 Can anyone give some advice on how to make use of this java code using clojure? It can be utilized just like any other java code. Here is the primer: http://clojure.org/java_interop If you ask more specific questions I believe we can provide better answers. Also, how good is your clojure-fu? Interfacing with Java modules doesn't seem like the best way to start learning Clojure IMHO. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- Kind Regards, Atamert Ölçgen -+- --+ +++ www.muhuk.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
deskewing image
I am interested in automatically deskewing of a scanned image before ocr processing using tesseract. I found the following, which is some java code to do it http://anydoby.com/jblog/en/java/1990 Can anyone give some advice on how to make use of this java code using clojure? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
text processing function
I am doing some text processing using clojure and attempting to extract a person's name by regex and then assign it to a map. The result I get takes one of several forms: nil (if i can't find the name) [fullname] [fullname lastname] [fullname lastname firstname] [fullname lastname firstname middlename] now, basically want to assign these entries to a map like so {:fullname some name, :lastname some name, etc...} if there is no entry than I would like to assign it as nil, e.g. {:fullname nil, lastname nil, etc...} I want to code this in the most proper way. I am thinking I need to define a function that works differently based on how long the vector is? How do I turn the contents of the vector into function arguments? Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: text processing function
These are both very good and usable answers. Thank you both! On Sunday, June 1, 2014 9:36:58 AM UTC-7, James Reeves wrote: What about: {:fullname (get result 0), :lastname (get result 1), :firstname (get result 2), :middlename (get result 3)} If the get function can't find a result, it returns nil. - James On 1 June 2014 17:09, Glen Rubin rubi...@gmail.com javascript: wrote: I am doing some text processing using clojure and attempting to extract a person's name by regex and then assign it to a map. The result I get takes one of several forms: nil (if i can't find the name) [fullname] [fullname lastname] [fullname lastname firstname] [fullname lastname firstname middlename] now, basically want to assign these entries to a map like so {:fullname some name, :lastname some name, etc...} if there is no entry than I would like to assign it as nil, e.g. {:fullname nil, lastname nil, etc...} I want to code this in the most proper way. I am thinking I need to define a function that works differently based on how long the vector is? How do I turn the contents of the vector into function arguments? Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
load-file for lein main function
I am doing text processing on an OCR text file using clojure. Basically, I (slurp) in the ocr text file and then use regular expressions to extract and (def) the bits of data I am interested in. This script to do this is complete, it prompts user for the file to slurp using seesaw.chooser library and then does it's work. I could run it by invoking load-file, but I want to make it into an executable program using Lein. Basically I want to evaluate the clojure file line by line. So, I am guessing the way to do this is make a clojure file with main function that just invokes load-file on the clojure file of interest? Thanks for advice! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
regex strings
I have a string of the general form: Name: Last,First Middle ID: GA88192 I am trying to extract the first name by invoking string.replace function, for example to extract the first name I invoke the following where 'nameidstring' is the general form above: (clojure.string/replace nameidstring #Name:\s(\w+){1},(\w+){1} $2) Unfortunately, this gives me the First name along with ID: GA88192 since i specified a single word {1} in my regex above I don't understand why this is happening. THank you for any advice -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
partitioning iterative list
Can I do the following without using loops?? I have list, e.g. '(4 6 66 33 26 6 83 5) I want to partition it so that I get a subset of lists that build up to the original: ( (4) (4 6) (4 6 66) (4 6 66 33) ) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
replace first n items in sequence
I am looking for a fn that does the following. Let's say i have sequences A B A: '(1 2 3 4 5 6 7 8 9 10) B '(54 666 23) I want to replace A's first items with B's, so that I get: '(54 666 23 4 5 6 7 8 9 10) Is there a fn to do this? Otherwise, I will write one. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: replace first n items in sequence
ok that's looks very succinct, I will use it. Just figured I would ask if it exists, b/c always prefer to use a built-in and it sounded basic enough to be. thanks! On Dec 18, 5:15 pm, Benny Tsai benny.t...@gmail.com wrote: I didn't see a built-in fn for this, and couldn't restrain myself from trying to write one: (defn replace-first-n [xs ys] (let [n (count ys)] (concat ys (drop n xs On Dec 18, 2:38 pm, Glen Rubin rubing...@gmail.com wrote: I am looking for a fn that does the following. Let's say i have sequences A B A: '(1 2 3 4 5 6 7 8 9 10) B '(54 666 23) I want to replace A's first items with B's, so that I get: '(54 666 23 4 5 6 7 8 9 10) Is there a fn to do this? Otherwise, I will write one. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
range with decimal values
If I use the range fn with a decimal number for step I get back something like this: (range 0.05 0.16 0.01) user (0.05 0.060005 0.07 0.08 0.09 0.0 0.10999 0.11998 0.12998 0.13999 0.15) Really I want output more like i get from the following fn: (map float (range 5/100 16/100 1/100)) user (0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: fastest way to remove nils
So, it seems the way I was removing nils using filter was already the best way. still nice to learn about the keep fn. thx! On Nov 17, 8:38 pm, Ken Wesson kwess...@gmail.com wrote: On Wed, Nov 17, 2010 at 7:55 PM, Robert McIntyre r...@mit.edu wrote: So, just to be clear, user (def nil-seq (doall (interleave (repeat 1e5 nil) (repeat 1e5 whatever))) ) #'user/nil-seq user (time (doall (keep identity nil-seq))) Elapsed time: 122.485848 msecs user (time (doall (remove nil? nil-seq))) Elapsed time: 149.71484 msecs I have to run these all a few times before the times quit shrinking (JITting being done). Then: user= (time (do (doall (keep identity nil-seq)) nil)) Elapsed time: 70.24324 msecs nil user= (time (do (doall (remove nil? nil-seq)) nil)) Elapsed time: 40.47016 msecs nil user= (time (do (doall (filter identity nil-seq)) nil)) Elapsed time: 36.70256 msecs nil It seems on my system keep identity is actually almost twice as SLOW as remove nil? and filter identity is slightly faster; filter identity is almost exactly twice as fast as keep identity. Filter identity does, of course, discard falses as well as nils, but when that's acceptable it's worth knowing it's fastest. I wonder if the difference is that I'm using the -server vm? It's especially interesting, in light of the likelihood that identity is probably compiling away to nothing when the JIT is done inlining everything, that both the slowest and the fastest use identity. It suggests that keep is inherently somewhat slow, in particular. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
fastest way to remove nils
What is the fastest way to remove nils from a sequence? I usually use the filter function, but I see there are other functions like remove that should also do the trick. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Mobile Clojure
Are there any mobile platforms that clojure runs well on? I saw that clojure is available for Android, but runs very slowly. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
reducing terms in vector
Hi! A little stuck on how to do this efficiently. I have data that looks like this ( [ [1 2] [3 4] [5 6] ... ] [ [5 6] [7 8] [9 0] ... ] ...) I am trying to sum the vector pairs, e.g [6 8] [10 12] [14 6] thx! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: challenge with vectors
wow, i think you just went way over my head. First off a very naive question: I thought all clojure programming was functional, as long as you are not using refs, agents, or other mutable values etc...?? On Oct 27, 12:26 am, Aravindh Johendran ajohend...@gmail.com wrote: What kind of an answer are you looking for? Just the quickest way to do it? Do you want an idiomatic clojure solution or are you learning functional programming using clojure? There are many ways to do this. Others have provided cool solutions. Here's a way of doing it if you are interested in filled-with-fun bare- bones no-frills functional code. It will NOT be the fastest solution. (defn min-b [vctr collection-function] (let [current-item (first vctr)] (cond (empty? vctr) (collection-function [] -1) (= 1 (count vctr)) (collection-function current-item 1) :else (min-b (rest vctr) (fn [next-item pos] (if ( (second next- item) (second current-item)) (collection-function next-item (inc pos)) (collection-function current-item pos))) The initial function you pass in will contain the logic to print out the result. Over here we are making a simple list out of the result . You can modify it to print out whatever you want done with the result (min-b [ [22 5] [56 8] [99 3] [43 76] ] (fn [x y] (list x y))) or (min-b [ [22 5] [56 8] [99 3] [43 76] ] (fn [x y] (println (str Value: x Position: y If you have a large data set and are worried about blowing the stack, you'll have to use recur and trampoline. Notice the extra # before the returned functions (defn min-b [vctr collection-function] (let [current-item (first vctr)] (cond (empty? vctr) (collection-function [] -1) (= 1 (count vctr)) #(collection-function current-item 1) :else (recur (rest vctr) (fn [next-item pos] (if ( (second next- item) (second current-item)) #(collection-function next-item (inc pos)) #(collection-function current-item pos))) (trampoline (min-b (vec (take 5000 (cycle [ [22 5] [56 8] [99 3] [43 76] ]))) (fn [x y] (list x y This example should demonstrate why hard tail calls are not a mere recursion thing. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: challenge with vectors
awesome dude!!! Thanks for the book recommendation...I'll take a look at those when I can. Right now I am just eager to get my code working ;) On Oct 27, 1:18 pm, Aravindh Johendran ajohend...@gmail.com wrote: On Oct 27, 8:24 am, Glen Rubin rubing...@gmail.com wrote: wow, i think you just went way over my head. First off a very naive question: I thought all clojure programming was functional, as long as you are not using refs, agents, or other mutable values etc...?? You are mostly right. And there are varying degrees of functional programming and various associated styles, meaning you can use functions to do a lot of things that you didn't think was possible. Functional programming is very rich and deep in paradigms and they take time to understand and master. What people refer to as idiomatic clojure, I think, is a style reliant on laziness and higher order functions. It makes for clean and succinct code. But there is a lot more to functional programming than idiomatic clojure. The example I provided is in what's called the Continuation Passing Style. Functions are created on the fly to hold values. It is very thought provoking. It is also very basic, meaning it uses nothing more than the simplest lisp primitives. I highly recommend the books Little Schemer and Seasoned Schemer. They are fun and a LOT of light bulbs went on in my head. Once you are done with those books, terms like Y Combinator, continuations, continuation passing style (CPS), etc will not intimidate you. You'll gain an appreciation for the core tenets of functional programming. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
challenge with vectors
I have a sequence like this: [ [a b] [a b] [a b] [a b] ] where a and b are numbers. I would like to return the vector and its index for which b is the least in this collection. For example, if my data is as follows [ [22 5] [56 8] [99 3] [43 76] ] I would like to return 3rd vector in the collection where b is lowest [99 3], but I also would like to know that it is the 3rd vector, so maybe something like: [99 3 3] any suggestions??? thx a mil!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
problem connecting through slime
Hey!!! Maybe this is not the best place to ask this question, but seeing as how many of you use emacs to code I will give it a shot. I am using emacs, slime, swank combo. When I try to slime-connect, I initially get the following error: error in process filter: Symbol's value as variable is void: paredit- backward-delete-key If I then try again it works. So, it's really annoying having to connect twice all the time! I was able to resolve this by removing a code fragment in my .emacs file, but then end up having problems with undeletable brackets...arghhh. Here is my .emacs file: ;;; This was installed by package-install.el. ;;; This provides support for the package system and ;;; interfacing with ELPA, the package archive. ;;; Move this code earlier if you want to reference ;;; packages in your .emacs. (when (load (expand-file-name ~/.emacs.d/elpa/package.el)) (package-initialize)) (add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1))) ;; Stop SLIME's REPL from grabbing DEL, ;; which is annoying when backspacing over a '(' (defun override-slime-repl-bindings-with-paredit () (define-key slime-repl-mode-map (read-kbd-macro paredit-backward-delete-key) nil)) (add-hook 'slime-repl-mode-hook 'override-slime-repl- bindings-with-paredit) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: exception thrown when passing in nil parameter
yeah, that's what i was thinking of doing, but it didn't seem pretty. thanks! On Sep 27, 5:30 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Here's one popular form: (defn foo ([a b c] (foo a b c nil)) ([a b c d] (if d ...))) Most multi-arity functions have the same behavior for every arity, with some default argument values. -S On Sep 27, 2:13 pm, Glen Rubin rubing...@gmail.com wrote: I have a function that will accept 3 or 4 parameters. Another function I have calls it and passes in 4 arguments. Sometimes, the 4th argument is nil and this causes an error, instead of just calling the main function as if I passed in 3 arguments. Meaning the main function sees a 4th parameter with nil value. How do I get it to act as only 3 parameters were passed in this circumstance? thx- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: finding value nearest x
It occurs to me that another way of doing this is to map a new list and then use the min fn. something like: (apply min (map #(Math/abs (- % 136)) xs)) maybe this is better and involves less calculations? On Sep 25, 2:19 pm, Glen Rubin rubing...@gmail.com wrote: min-key looks good! thx guys!!! On Sep 25, 10:44 am, Nicolas Oury nicolas.o...@gmail.com wrote: On Sat, Sep 25, 2010 at 3:40 PM, Jules julesjac...@gmail.com wrote: Maybe this: (min-key #(abs (- % 136)) xs) Wouldn't that be (apply min-key #(abs (- % 136)) xs)? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
return index of a value
I have a vector of numbers [0 99 3334 53 2 5 99 2 55 63] I'd like to find the first index of a particular value. For example if the value was 99 then I want to return 1, b/c the index of 99 is 1. I can do this with a loop/recur structure comparing each value in the list to my desired value, however am wondering if there isn't a built-in for doing so?? thanks again! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: finding value nearest x
yes correct. but i can write a fn to determine the index of the minimum distance in my new list? that index applied to my original list will give me the value back. and this still would involve fewer calculations i think. On Sep 27, 10:50 am, Michael Gardner gardne...@gmail.com wrote: On Sep 27, 2010, at 9:28 AM, Glen Rubin wrote: It occurs to me that another way of doing this is to map a new list and then use the min fn. something like: (apply min (map #(Math/abs (- % 136)) xs)) maybe this is better and involves less calculations? That gives you the minimum distance from 136, not the value itself. You can't get back the original value afterwards either, because you don't know whether to subtract or add the distance from 136. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: finding value nearest x
ok, thx. just trying to keep myself to a high standard while learning this stuff ;) On Sep 27, 11:12 am, Michael Gardner gardne...@gmail.com wrote: On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote: yes correct. but i can write a fn to determine the index of the minimum distance in my new list? that index applied to my original list will give me the value back. and this still would involve fewer calculations i think. Do you have a particular reason to be concerned about performance here? Don't worry about it unless profiling tells you it's a bottleneck for your program. And I doubt it will actually give better performance anyway, even with min-key evaluating f more times than is necessary, because your f is so inexpensive to calculate. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: return index of a value
interesting! thx guys! On Sep 27, 10:45 am, Glen Rubin rubing...@gmail.com wrote: I have a vector of numbers [0 99 3334 53 2 5 99 2 55 63] I'd like to find the first index of a particular value. For example if the value was 99 then I want to return 1, b/c the index of 99 is 1. I can do this with a loop/recur structure comparing each value in the list to my desired value, however am wondering if there isn't a built-in for doing so?? thanks again! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
exception thrown when passing in nil parameter
I have a function that will accept 3 or 4 parameters. Another function I have calls it and passes in 4 arguments. Sometimes, the 4th argument is nil and this causes an error, instead of just calling the main function as if I passed in 3 arguments. Meaning the main function sees a 4th parameter with nil value. How do I get it to act as only 3 parameters were passed in this circumstance? thx -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
finding value nearest x
I have a list of numbers and I want to find the one that is closest to 136. Is there an operator for performing this kind of operation or do I need to to do it algorithmically? thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: finding value nearest x
min-key looks good! thx guys!!! On Sep 25, 10:44 am, Nicolas Oury nicolas.o...@gmail.com wrote: On Sat, Sep 25, 2010 at 3:40 PM, Jules julesjac...@gmail.com wrote: Maybe this: (min-key #(abs (- % 136)) xs) Wouldn't that be (apply min-key #(abs (- % 136)) xs)? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
multiple parameters passed to fns
I defined a fn whose execution depends on the number of parameters passed to it. It works fine! I am just concerned that I am doing this in a way that is not as concise as it could or should be. Here is my fn: (defn make-target Parses text file for single sweep specified by sweepidx. If size is not specified will parse till end of sweep. If startidx and size are not spefified will parse from beginning to end ([file channel sweepidx] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) ;break open double parens collated-target2 (apply identity collated-target1)] collated-target2)) ([file channel sweepidx startidx] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) collated-target2 (apply identity collated-target1) ;;apply starting point collated-target3 (drop startidx collated-target2)] collated-target3)) ([file channel sweepidx startidx size] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) collated-target2 (apply identity collated-target1) ;apply starting point and size parameters collated-target3 (take size (drop startidx collated-target2))] collated-target3))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: multiple parameters passed to fns
good suggestions guys!! thx so much On Sep 2, 10:44 am, Justin Kramer jkkra...@gmail.com wrote: A couple other things: 1) (apply identity ...) is the same as (first ...) 2) Consider using the - macro to clean up the let Here's a quick rewrite: (defn make-target ([file channel sweepidx] (make-target file channel sweepidx 0)) ([file channel sweepidx startidx] (make-target file channel sweepidx startidx nil)) ([file channel sweepidx startidx size] (let [target (- (graph-part file channel sweepidx (inc sweepidx)) first (drop startidx))] (if size (take size target) target Lastly, if graph-part happened to return something like a vector or string, there are faster ways of taking a slice than take drop -- that is, subvec or subs. HTH, Justin On Sep 2, 10:20 am, Miki miki.teb...@gmail.com wrote: Hello Glen, I'd use the first two forms to set startidx and size and then call the full form: (def inf java.lang.Double/POSITIVE_INFINITY) (defn make-target Parses text file for single sweep specified by sweepidx. If size is not specified will parse till end of sweep. If startidx and size are not spefified will parse from beginning to end ([file channel sweepidx] (make-target file channel sweepidx 0 inf)) ([file channel sweepidx startidx] (make-target file channel sweepidx startidx inf)) ([file channel sweepidx startidx size] ([file channel sweepidx startidx size] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) collated-target2 (apply identity collated-target1) ;apply starting point and size parameters collated-target3 (take size (drop startidx collated- target2))] collated-target3))) On Sep 2, 5:54 am, Glen Rubin rubing...@gmail.com wrote: I defined a fn whose execution depends on the number of parameters passed to it. It works fine! I am just concerned that I am doing this in a way that is not as concise as it could or should be. Here is my fn: (defn make-target Parses text file for single sweep specified by sweepidx. If size is not specified will parse till end of sweep. If startidx and size are not spefified will parse from beginning to end ([file channel sweepidx] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) ;break open double parens collated-target2 (apply identity collated-target1)] collated-target2)) ([file channel sweepidx startidx] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) collated-target2 (apply identity collated-target1) ;;apply starting point collated-target3 (drop startidx collated-target2)] collated-target3)) ([file channel sweepidx startidx size] (let [collated-target1 (graph-part file channel sweepidx (+ 1 sweepidx)) collated-target2 (apply identity collated-target1) ;apply starting point and size parameters collated-target3 (take size (drop startidx collated-target2))] collated-target3))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: trouble using nested map fn
I'm glad my question generated so much discussion! Thank you all for the suggestions...it's all good stuff trying to wrap my head around and improve my facility with clojure. On Aug 24, 1:27 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 24 Aug., 03:08, gary ng garyng2...@gmail.com wrote: (map #(for [s %2] (map * %1 s)) target signal) Though personally I still think the %2 %1 is a bit confusing.- Zitierten Text ausblenden - If you don't like it, don't use it.You can always give things meaningful names. (for [[signals target] (map vector signals-list target-list) signal signals] (map * signal target)) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
misunderstanding collection
After toying around at the REPL I realize that I have been working with a heretofore invalid understanding of collections. For example, working with the following collection(s): signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8))) I wanted to sum each individual list: e.g. (1 2 3 4) = (10) I thought I could do this as follows: (map #(map reduce + %) signal) This resulted in an error, so trying to comprehend why I ran the following: (map #(map identity (take 1 %)) signal) which results in, (((1 2 3 4)) ((3 4 5 6))) So, clojure sees 'signal' as 2 collections, whereas I thought it was a single collection. This makes me concerned that I have been doing everything wrong thus far and getting computational errors. :( So, how should I sum each individual list in the above collections? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
trouble using nested map fn
I am trying to write a fn to correlate 2 signals using 3 nested map fn. I have 2 collections of data. THe first group of signals called target looks something like this. target: ( (1,2,3,4) (2,3,4,5) ...) The second collection is called signal and looks like this: signal: ( ((1,2,3,4)(2,3,4,5)(3,4,5,6)) ((2,3,4,5)(3,4,5,6)(4,5,6,7)) ... ) I would like to take the first list in target and multiply it by every list in the first group of signal. And then continue on processing the second list, etc... which would result in something like: ( ((1,4,9,16)(2,6,12,20)(3,8,15,24)) ((4,9,16,25) (6,12,20,30) (8,15,24,35)) ... ) I try a nested map fns like this, but can't get it to work: (map #(map #(map * %1 %2) %1 %2) target signal) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
take all
I am writing a fn to extract elements from a sequence using optional start and end values. I will do this by testing if 'end' or 'start' values are passed as parameters to the function. If the user does not specify a end value I would like the fn to return the entire sequence from 'start' to end. Is there a way to take all. I know I could just specify a really high number, but that seems kind of messy. Or I am also thinking the fcn could have several branches, but that also seems messy. I think it's best to just assign a default value if there is none. The body of fn would look something like this, where 'start' and 'end' would have number values: (drop start (take end coll)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: take all
I just wrote a fn called takeall that seems to do what I want: (defn takeall [x [y]] (if (and x y) (take x y) x)) On Aug 20, 1:44 pm, Glen Rubin rubing...@gmail.com wrote: I am writing a fn to extract elements from a sequence using optional start and end values. I will do this by testing if 'end' or 'start' values are passed as parameters to the function. If the user does not specify a end value I would like the fn to return the entire sequence from 'start' to end. Is there a way to take all. I know I could just specify a really high number, but that seems kind of messy. Or I am also thinking the fcn could have several branches, but that also seems messy. I think it's best to just assign a default value if there is none. The body of fn would look something like this, where 'start' and 'end' would have number values: (drop start (take end coll)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
multiplying lists
I want to multiply a list of n items by h lists of n items, so that for example if i have list 'a' and 'b' (def a (list 1 2 3)) (def b (list '(4 5 6) '(7 8 9))) when multiplied I will get: ((4 10 18) (7 16 27)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
gobble up a collection 2 at a time
Hi! I want to process a collection 2 elements at a time using map. My function accepts 2 parameters (a,b) and returns a result (c): (myfcn [a b]) = c so I want to iterate myfcn over a collection and create a new sequence for example let's say myfcn sums a and b, then i would like to do something like this: (map myfcn '(1 2 3 4 5 6 7 8) = 3 7 11 15 accept i get the error that myfcn is being passed the wrong number of arguments, since map is passing them in 1 at a time. How do I get map to pass in 2 at a time? thx! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
removing parethesis
I am working with a collection of integer sequences ...(e.g. coll: ((3 7 3 5 9 2 0 8 4 0 1 2323 4 11...) (243 4 664 478 3948...) (6 3 7 4 3335 2 4 5 7 6...)...) I want to create an average sequence such that all of the first elements are averaged, all of the second elements, etc However, I am unable to manipulate the collection. If I try something simple like: (map + coll) I get java.lang.ClassCastException I understand that this is because map is trying to apply + to an entire sequence, but cannot figure out how to remove the parenthesis which enclose this collection. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
(apply partition coll1 coll2 ...)
I am working with a collection of sequences ...(e.g. coll: ((/f /b /c /4 /5 /6 /3 /6 /f /4 /3 /2 /4 /5 /7 /3 /6) (/2 /b /c /4 /2 / 6 /3 /7 /f /4 /3 /2 /4 /5 /7 /3 /6)...) I want to partition the sequences into groups of 4, but when I try the following or something similar it fails saying either partition or apply is being passed the wrong number of args. (map #(apply partition 4 %) coll) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
re-arranging sub-partitions
I am working with a collection of sequences ...(e.g. coll: ((/f /b /c /4 /5 /6 /3 /6 /f /4 /3 /2 /4 /5 /7 /3 /6...) (/2 /b /c /4 / 2 / 6 /3 /7 /f /4 /3 /2 /4 /5 /7 /3 /6...)...) I want to rearange the sequence into groups of 4 where the later 2 elements are moved to the front for example: (/f /b /c /4 /5 /6 /3 /6 /f /4 /3 /2 /4 /5 /7 /3 /6...) I want to transform it as follows: (/c /4 /f /b /3 /6 /5 /6 /3 /2 /f /4) I can break the collection of sequences up into groups of 4 as follows: (map #(partition 4 %) coll) However I am having problems taking the resulting partitioned sequence and further subdividing into groups of 2 before reversing the paired groups order. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
formatting hex string
I have a sequence of hex strings, e.g. ff43 0032 ... (you get the idea) I want to use clojure's short form on them, but short expects an authentic hex input, e.g. (short 0xff43) it will not accept something like (short 0xff43) Any suggestions would be gratefully appreciated!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
regular expression sequence
I am having trouble with the re-seq regular expression form. I am not an expert on regex, so this is probably part of my problem. I have a k12 text file, basically it is hex broken up by '|' . I would like to grab all the hex between two hex numbers (sample text below). For example, I might want all of the text between 49|00 and a4|ff I wrote the following regex to do this: (re-seq #49[0-9a-f|]+|a4|ff|+ slurped) This didn't work and gave me an exception about the + sign being a dangling meta character, So, I rewrote it with the expression placed in parenthesis: (re-seq #(18[0-9a-f|]+|b6|a5|)+ slurped) Now, this works, but is kind of funky b/c it a lot of the sequences I get are empty. It looks kind of like this ([ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [49|00|47|00|2f|00|60|ff|5f|ff|41|ff| 1e|ff|78|ff|35|00|ea|ff|d2|ff|bd|ff|69|00|7e|00|8e|00|5e|00|c2|00|7d| 00|b1|ff|5f|00|be|00|20|00|c9|ff|b5|ff|86|ff|66|00|9b|00|25|00|73|ff| b0|ff|94|ff|e3|ff|8d|00|7a|00|90|ff|70|ff|8a|ff|b1|ff|51|00|a0|ff|b5| ff|91|ff|c6|ff|07|00|c9|ff|b4|ff|9e|ff|be|ff|cd|ff|a6|00|23|01|21|01| a4|00|3d|00|22|00|ab|ff|af|ff|8e|ff|43|ff|51|ff|6b|ff|b6|ff|bf|ff|a4| ff|27|00|84|00|7c|00|82|00|9f|00|5a|00|34|00|27|00|6c|00|77|00|41|00| c0|ff|c6|ff|ad|ff|bd|ff|7c|00|3a|00|90|ff|b8|ff|48|ff|99|00|69|00|48| 00|27|00|7e|ff|83|ff|ca|ff|bf|ff|d9|ff|72|ff|87|ff|c2|ff|c1|ff|b9|ff| e1|ff|94|ff|c7|ff|e4|ff|c7|00|ca|00|be|00|99|00|37|00|c7|ff|d7|ff|36| 00|43|ff|62|ff|2c|ff|73|ff|a4 ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]) Sample k12 hex: +-+---+--+ 01:30:28,579,598 ETHER |a5|a5|a5|a5|a5|a5|a5|a5|a5|a5|a5|a5| +-+---+--+ 01:30:28,646,595 ETHER |b0|ff|db|ff|c1|ff|f2|ff|13|00|57|00|a9|00|d3|00|f3|00|9f|00|49|00|47| 00|2f|00|60|ff|5f|ff|41|ff|1e|ff|78|ff|35|00|ea|ff|d2|ff|bd|ff|69|00| 7e|00|8e|00|5e|00|c2|00|7d|00|b1|ff|5f|00|be|00|20|00|c9|ff|b5|ff|86| ff|66|00|9b|00|25|00|73|ff|b0|ff|94|ff|e3|ff|8d|00|7a|00|90|ff|70|ff| 8a|ff|b1|ff|51|00|a0|ff|b5|ff|91|ff|c6|ff|07|00|c9|ff|b4|ff|9e|ff|be| ff|cd|ff|a6|00|23|01|21|01|a4|00|3d|00|22|00|ab|ff|af|ff|8e|ff|43|ff| 51|ff|6b|ff|b6|ff|bf|ff|a4|ff|27|00|84|00|7c|00|82|00|9f|00|5a|00|34| 00|27|00|6c|00|77|00|41|00|c0|ff|c6|ff|ad|ff|bd|ff|7c|00|3a|00|90|ff| b8|ff|48|ff|99|00|69|00|48|00|27|00|7e|ff|83|ff|ca|ff|bf|ff|d9|ff|72| ff|87|ff|c2|ff|c1|ff|b9|ff|e1|ff|94|ff|c7|ff|e4|ff|c7|00|ca|00|be|00| 99|00|37|00|c7|ff|d7|ff|36|00|43|ff|62|ff|2c|ff|73|ff|a4|ff|32| +-+---+--+ 01:30:28,669,317 ETHER |a5|a5|a5|a5|a5|a5|a5|a5|a5|a5|a5|a5| +-+---+--+ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: regular expression sequence
The result is a little bit strange still, since I am getting dupliates. First, it returns the string I want 49|00|12 12|a9|a4|ff but then it also returns the same string without the first and last 4 characters, e.g. 12|12|a9| Also, how come I don't need to escape the | inside the parenthesis? thanks Meikel!! On Mar 30, 10:59 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you have to escape the |. user= (re-seq #49\|00\|([0-9a-f|]+)\|a4\|ff a5|a5|49|23|49|00|12| fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff|ae) ([49|00|12|fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff 12|fc|5e|a4|ff|a7|49|00| ee|d3]) However this will be greedy... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: regular expression sequence
thx that works great! i guess I can also just leave out the parenthesis all together. but, what if i wanted just the portion inside?? the duplicate I wanted to get rid of? also any way to return the sequence without all those bars or do i have to use a seperate regex and or filter? On Mar 30, 12:52 pm, Mark J. Reed markjr...@gmail.com wrote: Addendum: I highly recommend Jeffrey Friedl's book _Mastering_Regular_Expressions_ if you want to learn how to use regexes well. There are also a number of introductions/tutorials online, but I'm not familiar enough with them to recommend any. On Tue, Mar 30, 2010 at 12:50 PM, Mark J. Reed markjr...@gmail.com wrote: Parentheses capture - anything that matches a parenthesized portion of a regular expression is returned as part of the result of the match: user= (re-seq #a(.)c abc) ([abc b]) If you don't want that behavior, you can use the special non-capturing syntax, (?:...): user= (re-seq #a(?:.)c abc) (abc) You don't have to escape pipes or any other special characters inside a character class (that is, between [...]), because characters lose their special meanings there: [.*] matches either a period or an asterisk and has no relationship to the any character symbol or zero or more repetition operator. The only special things inside a character class are a leading '^', which negates the class, and a '-' in the middle, which makes a range: [^a-z] matches any single character that is not a lowercase letter (of the English alphabet). Position matters: [-^] matches a literal hyphen or caret, and [] is not an empty character class but a syntax error (an unclosed character class that so far includes a literal ']' character). On Tue, Mar 30, 2010 at 12:37 PM, Glen Rubin rubing...@gmail.com wrote: The result is a little bit strange still, since I am getting dupliates. First, it returns the string I want 49|00|12 12|a9|a4|ff but then it also returns the same string without the first and last 4 characters, e.g. 12|12|a9| Also, how come I don't need to escape the | inside the parenthesis? thanks Meikel!! On Mar 30, 10:59 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you have to escape the |. user= (re-seq #49\|00\|([0-9a-f|]+)\|a4\|ff a5|a5|49|23|49|00|12| fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff|ae) ([49|00|12|fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff 12|fc|5e|a4|ff|a7|49|00| ee|d3]) However this will be greedy... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: byte and 2s complement
I guess not, some of the values I am obtaining are off. I have tried searching for a java class that will understand a signed (two's complement) hex (16 bit, 0xff32) This is something so basic, I know there must be some in built function for this?? On Mar 28, 3:06 pm, Glen Rubin rubing...@gmail.com wrote: I am working with 2's complement hex. It looks like i can get the value of any number by just using byte? e.g.: (byte 0xff32) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
convert hex string to number
Hi! I am working with a sequence of hex numbers that are in string format, e.g. (0x34 0xff 0x01 ...) Is there a function for converting these strings into normal hex or numbers?? I tried num, but it didn't work. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: convert hex string to number
thanks...you rock!! On Mar 27, 4:17 pm, Richard Newman holyg...@gmail.com wrote: Is there a function for converting these strings into normal hex or numbers?? I tried num, but it didn't work. user= (read-string 0x44) 68 Safer: (defn hex-num [#^String s] (binding [*read-eval* false] (let [n (read-string s)] (when (number? n) n You could also use parseInt, which will be faster, so long as you can guarantee the format: (defn hex-num [#^String s] (Integer/parseInt (.substring s 2) 16)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
installing libraries
I want to start graphing some data i am woking with. I found and downloaded a library called dejcartes for this purpose http://www.markmfredrickson.com/code/ I am absolutely clueless as how to install this beast...my knowledge of java is extremely. i see there are a bunch of jar files as well clojure ones too! are there any tutorials on installing 3rd party libraries out there?? thx for any advice! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
converting long string to number
I am trying to convert a long string of numbers to a number, but get a java.lang.numberformatexception My long string of numbers has new line characters in it, so I am filtering out the newline characters before converting it back to a string. Then I try to use Integer. on it but get the above exception. Code is as follows: big-num-str is truncated for space's sake, is actually much much longer!! (def big-num-str 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849979408065481931592621691275889832738 44274228917432520321923589422876796487670272189318 47451445736001306439091167216856844588711603153276 70386486105843025439939619828917593665686757934951) (Integer. (apply str (filter #(Character/isDigit %) big-num-str))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: listing factors of a number
it looks like that code will suffice. Thanks!! On Mar 23, 9:38 pm, Per Vognsen per.vogn...@gmail.com wrote: I'm sure that code would be useful if he were looking for a slow implementation of a slow algorithm. I believe he asked for an optimized algorithm. An example might be Lenstra's elliptic curve factorization or the general number field sieve. I don't know of any implementations in Clojure but there seem to be a few floating around in Java. -Per On Wed, Mar 24, 2010 at 3:35 AM, kotor cnbe...@netscape.net wrote: On Mar 23, 1:02 pm, Glen Rubin rubing...@gmail.com wrote: Does anyone know of any existing libraries for clojure that has code which is optimized to list all of the factors of any given integer? (defn factors [x] integer - vector[integers] (loop [xf [] i 2] (if ( (* i i) x) (vec (sort (distinct xf))) (if (zero? (rem x i)) (recur (conj xf i (/ x i)) (inc i)) (recur xf (inc i)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email tocloj...@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email toclojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
determining index number for item in list
I wrote the following code to produce a lazy sequence of the triangle numbers. (triangle numbers are the series of numbers: 1, 1+2, 1+2+3, etc...) (defn tri-nums [] prduce a lazy sequence of triangle numbers (let [triangles (map #(range 1 %) (iterate inc 2))] (map #(reduce + %) triangles))) However, I now have produced a large triangle number (76576500) and want to know which triangle number it is (e.g. the first, second, third, etc...) So, I wrote the following code which should accept a triangle number as input and tell you which one it is in the series: (defn which-tri [z] (loop [x 1 y (first (tri-nums))] (cond (= y z) x ( y z) (recur (inc x) (first (rest (tri-nums true (println no such tri-num The problem is that this function works for the first two triangle numbers (1, 3), but then just sits there doing nothing on any higher (6, 10, etc...). Any thoughts? thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: determining index number for item in list
Of course! I keep making stupid mistakes like thisarg!!! On Mar 24, 9:28 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Mar 24, 2:21 pm, Glen Rubin rubing...@gmail.com wrote: (loop [x 1 y (first (tri-nums))] ... (recur (inc x) (first (rest (tri-nums You call tri-nums twice. So you get fresh seqs each time. You have to work on a single seq. (loop [counter 1 tris (tri-nums)] (let [t (first tris)] (cond ... ... (recur (inc counter) (next tris)) ...))) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: listing factors of a number
Except Mathematica is kind of expensive $250 for the home edition. It looks like there is also Incanter which is a similar project using R free statistical computing environment On Mar 24, 12:55 pm, Mark Engelberg mark.engelb...@gmail.com wrote: Check out clojuratica. It interfaces Clojure to a free version of mathematica which has a very fast implementation called FactorInteger. --Mark -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
listing factors of a number
Does anyone know of any existing libraries for clojure that has code which is optimized to list all of the factors of any given integer? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
lazy-cons
Hey all, I am working through the problems on project euler. On question number 11 (http://projecteuler.net/index.php?section=problemsid=11), I was unable to come up with a solution, so I cheated and looked at some other people's answer's here: http://clojure-euler.wikispaces.com/Problem+011 Unfortunately, I am so dumb I cannot even understand the solutions very well...hahhaha. The first solution on that page defines the following function: (defn select-dir [array x y ncol span fnx fny] (when (not (zero? span)) (lazy-cons (array-get array x y ncol) (select-dir array (fnx x) (fny y) ncol (dec span) fnx fny Right off the bat, I am wondering what is lazy-cons? I could not find it in the api. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
filter sequence until false result
Hey all! I am trying to filter a sequence until a false value is returned. Is there a control-flow form to do this? ( I know I could write a loop statement to do it) Here are more details of what I am actually trying to do, in case above is not clear. input is the lazy sequence of primes: (use '[clojure.contrib.lazy-seqs :only (primes)]) I would like to filter the lazy sequence of primes for all of the primes less than 2,000,000 If I try: (filter #(while ( % 20)) primes) It gets hung up since filter keeps testing primes, despite the fact that they have grown too large. So, I would like filter to stop at the first false result. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: collections within collections
it seems kind of weird that map would work like that. i understood map as taking the first item of every collection and applying f to it. e.g (map + [2 4] [6 8]) - [8 12] In this case, since answer? takes a collection as argument I guess map just applies answer? to each collection? but don't all the collections have to be the same size or one will be exhausted? And then it seems that answer is acting independently on each collection. Is that because answer? only takes one argument, whereas a fcn like + takes 2 arguments. Sorry, I am a little bit confused. The other responses seemed very helpful too, but have not yet tried to figure them out. thx! On Mar 10, 12:18 pm, Wilson MacGyver wmacgy...@gmail.com wrote: you can define a function to filter the result like (defn answer? [x] (filter #(every? integer? %) x)) and then just call it by doing user= (map #(answer? %) (trips (range 1 7))) (() () ([3 4 5]) () ()) On Wed, Mar 10, 2010 at 1:20 PM, Glen Rubin rubing...@gmail.com wrote: I am working on the following problem: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000 My strategy is to produce a series of triplets of a^2 + b^2 and then filter out the ones where the c^2 is a perfect square, in order to determine Pythagorean triplets. I wrote a function to produce triplets that takes a range as input: (use '[clojure.contrib.math :only (sqrt)]) (defn trips [coll] (loop [a (first coll) b (rest coll) trip []] (cond (seq b) (recur (first b) (rest b) (conj trip (map #(vector a % (sqrt (+ (* a a) (* % % b))) true trip))) ,so if I want to see all triplets over the range of 1-7, I just do: (trips (range 1 7)), which yields the following; [([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219]) ([2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759]) ([3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369]) ([4 5 6.4031242374328485] [4 6 7.211102550927978]) ([5 6 7.810249675906654])] Obviously the only Pythagorean triplet burried in there is 3, 4, 5. Now, I can easily test a single vector for integers as follows: (map integer? [5 6 7]) However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. I guess I need to use some functions for merging collections? Any help apprectiated. thanks!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
collections within collections
I am working on the following problem: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000 My strategy is to produce a series of triplets of a^2 + b^2 and then filter out the ones where the c^2 is a perfect square, in order to determine Pythagorean triplets. I wrote a function to produce triplets that takes a range as input: (use '[clojure.contrib.math :only (sqrt)]) (defn trips [coll] (loop [a (first coll) b (rest coll) trip []] (cond (seq b) (recur (first b) (rest b) (conj trip (map #(vector a % (sqrt (+ (* a a) (* % % b))) true trip))) ,so if I want to see all triplets over the range of 1-7, I just do: (trips (range 1 7)), which yields the following; [([1 2 2.23606797749979] [1 3 3.1622776601683795] [1 4 4.123105625617661] [1 5 5.0990195135927845] [1 6 6.082762530298219]) ([2 3 3.605551275463989] [2 4 4.47213595499958] [2 5 5.385164807134504] [2 6 6.324555320336759]) ([3 4 5] [3 5 5.830951894845301] [3 6 6.708203932499369]) ([4 5 6.4031242374328485] [4 6 7.211102550927978]) ([5 6 7.810249675906654])] Obviously the only Pythagorean triplet burried in there is 3, 4, 5. Now, I can easily test a single vector for integers as follows: (map integer? [5 6 7]) However, the output of my trips function yields multiple collections of vectors inside of a larger vector. I am completely befuddled as to how to process this behemoth. I guess I need to use some functions for merging collections? Any help apprectiated. thanks!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
map not working in loop
The following code does not work, when using (range 1 5) as coll input: (defn pyt [coll] (loop [b (rest (coll))] (map #(* % %) b))) The real code was more complicated, but I refined it to its simplest form while still producing the error. (map f coll) looks correct to me?? :( -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: map not working in loop
The problem was that coll was being called as a fcn as others pointed out. You say the function being supplied as my second parameter does not modify my third parameter? (defn pyt [coll] (loop [b (rest coll)] (map #(* % %) b))) I am taking the third parameter and squaring it. Isn't that a modification? thx everybody for the help! On Mar 5, 7:15 am, Richard Lyman richard.ly...@gmail.com wrote: On Fri, Mar 5, 2010 at 7:05 AM, Glen Rubin rubing...@gmail.com wrote: The following code does not work, when using (range 1 5) as coll input: (defn pyt [coll] (loop [b (rest (coll))] (map #(* % %) b))) The real code was more complicated, but I refined it to its simplest form while still producing the error. (map f coll) looks correct to me?? :( I'm not sure what effect you're looking for, but... Don't forget, map is lazy and the function you've supplied as the second parameter doesn't modify b. Depending on what outcome you're looking for, you might want to wrap the call to map in a call to doall, or modify b and your second parameter so that b is changed. -Rich -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
no source file
Hi, I wrote some code, put it in a file, and now want to load that file. Here is the code I wrote, sqrs.clj: (use '[clojure.contrib.generic.math-functions :only (sqr)]) (defn square-of-sum [coll] adds up collection of numbers and then squares it (sqr (reduce + coll))) whenever I try (load-file sqrs.clj) i get a no source file exception. I have tried placing this file on my desktop, c:\, and clojure directory, but always get a no source file exception. Where should I put it? thx! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
Thank you so much This is really wonderful advice...saved me months of learning. I have rewritten my code as follows: ;definition of a palindrome (defn palindrome? [s] (= s (apply str (reverse s ;list of palindromes for range of numbers (defn palindromes [start end] (def startmod (- start 1)) (filter #(palindrome? (str %)) (range (* end end) (* startmod startmod) -1))) ;yields a lazy sequence of all that are divisible by a 3 digit number and yield a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) ( 99 (unchecked-divide pal %) 1000)) (range 999 99 -1))) (defn p1 [] (def palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999 (def root1 (first (divis-by-3dig palindromic-number))) (def root2 (unchecked-divide palindromic-number root1)) (def message (str the palindromic number is palindromic-number its roots are root1 root2)) message) On Feb 14, 11:17 pm, ataggart alex.tagg...@gmail.com wrote: On Feb 14, 5:49 pm, Glen Rubin rubing...@gmail.com wrote: Thank you for the advice! Just for reference I am working on project euler question #4 (Find the largest palindrome made from the product of two 3-digit numbers.) I have a solution, but am hoping somebody can clarify some things for me: First, I define a panlindrome tester: (defn palindrome? [s] (= s (apply str (reverse s Next, I define a list of palindromes for the two 3-digit number range: (def palindromes (filter #(palindrome? (str %)) (reverse (range (* 100 100) (+ 1 (* 999 999)) My next function takes a palindromic number as an argument and returns a sequence of all 3 digit divisors with a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) (= 3 (len (str (/ pal %) (reverse (range 100 1000 This function works, but only with an integer, which means I have to use it with another filter function in order to test a collection. And then it will return the palindromic number in my collection which has two 3 digit divisors instead of the factors, which is what I am looking for. I solve this as follows in my main function: (defn e1 [] (def palindromic-number (take 1 (filter #(not (empty? (divis-by-3dig %))) palindromes))) (def root (take 1 (map divis-by-3dig palindromic-number))) root) unfortunately there is still a problem with this, in that i cannot get access to a single root, instead am returned all of the roots from applying my divis-by-3dig function to the single element in my collection palindromic-number (e1) On Feb 14, 8:52 am, Steven E. Harris s...@panix.com wrote: Glen Rubin rubing...@gmail.com writes: How do I take an element from one collection and test for no remainder (e.g. (zero? (mod x y)), when dividing by every element of the second collection, before processing the next item in the first collection? This form checks if every element of the second range is a factor of every element in the first range: , | (let [r2 (range 100 150)] | (every? | #(every? (partial (comp zero? mod) %) r2) | (range 1000 2000))) ` Note that the walk over (range 1000 2000) is the outer one, and the walk over (range 100 150) (r2) is the inner one. -- Steven E. Harris So you're scanning all possible products, then back-tracking to figure out which 3-digit factors can result in that value? Interesting, though outside the scope of the actual PE question. A few comments: - There is no len function. Use count or .length for strings. - Don't def really long sequences; instead defn a function that returns the sequence (which can then be garbage collected). Plus it sucks when pasting into the repl and it tries to realize and print the entire sequence. - Don't reverse ranges since doing so requires first generating the entire (otherwise lazy) sequence; instead make the step negative, e.g., (range 999 99 -1) - Clojure's numeric inequality functions can take more than 2 args, thus you can call ( 99 % 1000) rather than testing the length of the stringified number. - If you want integer dividing, cast to int or use unchecked-divide (I prefer the latter which avoids the intermediate Ratio): user= (/ 3 4) 3/4 user= (int (/ 3 4)) 0 user= (unchecked-divide 3 4) 0 - Per the documentation of empty?, use the idiom (seq x) rather than (not (empty? x)) - See if you can avoid banging everything to/from strings. Maybe turn an int to/from some collection of digits. - (take 1 foo) returns you a one-element (or empty) sequence. (first foo) returns the first value (or nil). Use the latter when you really just want the value. This, by the way, is why your answer to (e1) is ((913 993)). -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure
Re: processing two collections
I tried using your alternate definition for palindromes? , but an exception was thrown: java.lang.NullPointerException [Thrown class java.lang.RuntimeException] On Feb 15, 7:02 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Feb 15, 2:50 pm, Glen Rubin rubing...@gmail.com wrote: ;definition of a palindrome (defn palindrome? [s] (= s (apply str (reverse s You might want to call vec on the string and then rseq instead of reverse. reverse walks the string twice, while rseq just walks the string once. The vector will use the underlying string as storage. (defn palindrome? [s] (= s (rseq (vec s ;list of palindromes for range of numbers (defn palindromes [start end] (def startmod (- start 1)) ^^^ No. No. No. Use (let [startmod (dec start)] )! def is toplevel only! (filter #(palindrome? (str %)) (range (* end end) (* startmod startmod) -1))) ;yields a lazy sequence of all that are divisible by a 3 digit number and yield a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) ( 99 (unchecked-divide pal %) 1000)) (range 999 99 -1))) (defn p1 [] (def palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999 (def root1 (first (divis-by-3dig palindromic-number))) (def root2 (unchecked-divide palindromic-number root1)) (def message (str the palindromic number is palindromic-number its roots are root1 root2)) message) Again: no nested def's, defn's, or anything else starting with def. Use let! def is always global so this will not do, what you think it does (ie. define a local). (defn p1 [] (let [palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999))) root1 (first (divis-by-3dig palindromic-number)) root2 (unchecked-divide palindromic-number root1)] (str the palindromic number is palindromic-number its roots are root1 root2))) Hope this helps. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
processing two collections
howdy clojure folks! I am a noob and trying to do the following: Suppose I have 2 collections of numbers: (range 1000 2000) (range 100 150) How do I take an element from one collection and test for no remainder (e.g. (zero? (mod x y)), when dividing by every element of the second collection, before processing the next item in the first collection? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
Thank you for the advice! Just for reference I am working on project euler question #4 (Find the largest palindrome made from the product of two 3-digit numbers.) I have a solution, but am hoping somebody can clarify some things for me: First, I define a panlindrome tester: (defn palindrome? [s] (= s (apply str (reverse s Next, I define a list of palindromes for the two 3-digit number range: (def palindromes (filter #(palindrome? (str %)) (reverse (range (* 100 100) (+ 1 (* 999 999)) My next function takes a palindromic number as an argument and returns a sequence of all 3 digit divisors with a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) (= 3 (len (str (/ pal %) (reverse (range 100 1000 This function works, but only with an integer, which means I have to use it with another filter function in order to test a collection. And then it will return the palindromic number in my collection which has two 3 digit divisors instead of the factors, which is what I am looking for. I solve this as follows in my main function: (defn e1 [] (def palindromic-number (take 1 (filter #(not (empty? (divis-by-3dig %))) palindromes))) (def root (take 1 (map divis-by-3dig palindromic-number))) root) unfortunately there is still a problem with this, in that i cannot get access to a single root, instead am returned all of the roots from applying my divis-by-3dig function to the single element in my collection palindromic-number (e1) On Feb 14, 8:52 am, Steven E. Harris s...@panix.com wrote: Glen Rubin rubing...@gmail.com writes: How do I take an element from one collection and test for no remainder (e.g. (zero? (mod x y)), when dividing by every element of the second collection, before processing the next item in the first collection? This form checks if every element of the second range is a factor of every element in the first range: , | (let [r2 (range 100 150)] | (every? | #(every? (partial (comp zero? mod) %) r2) | (range 1000 2000))) ` Note that the walk over (range 1000 2000) is the outer one, and the walk over (range 100 150) (r2) is the inner one. -- Steven E. Harris -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
defn
I am trying to learn clojure by learning the programing by example open wiki book. For an excercise demonstrating iteration they give the following example: (defn factorial ([n] (factorial n 1)) ([n acc] (if (= n 0) acc (recur (dec n) (* acc n) first I don't understand how acc ever gets an initial value? also the arguments to the function are a list and not a vector? why is the vector [n acc] on a line by itself? This function is very confusing to me!! thanks for any help!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: defn
wow! So if it is called with 1 argument, then the body of the function is: (factorial n 1) But if it is called with 2 arguments then the body of the function is: (if (= n 0) acc (recur (dec n) (* acc n))) Is this a standard feature of lisp? Sorry I am very noobish. thx! On Jan 25, 9:29 am, Mike DeLaurentis delauren...@gmail.com wrote: That's defining a function factorial that can be called with either one or two arguments. When called with one argument, it immediately calls itself with two arguments. So the (factorial n 1) call provides acc with an initial value of 1. The ([n] and ([n acc] lines are the declarations of the parameter lists for the function. Does that make sense? On Sun, Jan 24, 2010 at 7:23 PM, Glen Rubin rubing...@gmail.com wrote: I am trying to learn clojure by learning the programing by example open wiki book. For an excercise demonstrating iteration they give the following example: (defn factorial ([n] (factorial n 1)) ([n acc] (if (= n 0) acc (recur (dec n) (* acc n) first I don't understand how acc ever gets an initial value? also the arguments to the function are a list and not a vector? why is the vector [n acc] on a line by itself? This function is very confusing to me!! thanks for any help!! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email tocloj...@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email toclojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en