Re: Using map to produce side effects, not working

2019-02-08 Thread Alan Thompson
Also remember that `mapv` is not lazy and will force the map to run right away, which helps if side-effecty things like `println` are a part of the function. On Thu, Feb 7, 2019 at 10:54 AM Justin Smith wrote: > also do note that clojure.core/run! is designed for two-arg map when > it's only run

Re: Using map to produce side effects, not working

2019-02-07 Thread Justin Smith
also do note that clojure.core/run! is designed for two-arg map when it's only run for side effects, and clojure.core/doseq is designed for nested side-effecting iteration On Thu, Feb 7, 2019 at 3:33 AM Pierpaolo Tofani wrote: > > Thanks ! Your diagnosis is correct. With two dorun works fine. > >

Re: Using map to produce side effects, not working

2019-02-07 Thread Erik Assum
Just as a note, you should probably use `doseq` when you want to produce side effects. Erik. > On 7 Feb 2019, at 12:04, Pierpaolo Tofani wrote: > > Hi > i am new in clojure sorry. > In the snippet of code i used two map functions only to produce side effects > on two ref. > Even using doall

Re: Using map to produce side effects, not working

2019-02-07 Thread Pierpaolo Tofani
Thanks ! Your diagnosis is correct. With two dorun works fine. Il giorno giovedì 7 febbraio 2019 12:19:40 UTC+1, Orestis Markou ha scritto: > > Without having ran your code, it seems that the inner map is not wrapped > in a doall, so while the outer lazy-seq is forced, the inner is not. > > This

Re: Using map to produce side effects, not working

2019-02-07 Thread Orestis Markou
Without having ran your code, it seems that the inner map is not wrapped in a doall, so while the outer lazy-seq is forced, the inner is not. This might be of interest to you: http://clojure-doc.org/articles/language/laziness.html If you

Using map to produce side effects, not working

2019-02-07 Thread Pierpaolo Tofani
Hi i am new in clojure sorry. In the snippet of code i used two map functions only to produce side effects on two ref. Even using doall no affect is produced on ref aaa and zzz, seems that the sequence is still lazy. But if i remove the final :done , and the repl show me the sequence produced

Re: Using map inc fails on windows

2016-01-11 Thread Igwe Ogba
Hi everyone, Just tested it in another command prompt. It works perfectly now Also running (doc map) returns nil in the console which outputs the wrong answer The program clojure-noob (core.clj) only prints out one line so it is hard to see how it could change the definition of map. *

Re: Using map inc fails on windows

2016-01-11 Thread David Powell
this doesn't happen for me, it looks like you have something weird going on with your environment. how are you starting your repl? what does (clojure-version) return? has map somehow been redefined? is your namespace importing something that clobbers map? does (doc map) print the standard docs

Re: Using map inc fails on windows

2016-01-11 Thread gildraug
I'm not really expert in Windows, but it looks like some output problem, because REPL prints not the real result, but last element of the previously entered form: map should return sequence (e. g., (1 2 3 4)) and not vector ([0 1 2 4]). Also, REPL stores result of the last evaluated expression

Re: Using map inc fails on windows

2016-01-11 Thread Jason Felice
I would expect what you expect. Are you sure there's nothing in the clojure-noob.core namespace which redefines map? If not, try restarting the REPL in case map got clobbered somehow. On Mon, Jan 11, 2016 at 12:08 PM, Igwe Ogba wrote: > > >

Using map inc fails on windows

2016-01-11 Thread Igwe Ogba
Hello. I'm still a Clojure newbie and had a bit of code return what seems to be the wrong value.

Re: StackOverflowError while using map inside a reduce

2010-11-03 Thread John Szakmeister
On Wed, Nov 3, 2010 at 2:35 AM, Meikel Brandmeyer wrote: > Hi, > > On 3 Nov., 00:40, Rasmus Svensson wrote: > >> I think the problem is that this reduction will build an expression like >> this: >> >>     (map + ... (map + ... (map + ... (map + ... > levels> >> >> When clojure tries to reali

Re: StackOverflowError while using map inside a reduce

2010-11-02 Thread Meikel Brandmeyer
Hi, On 3 Nov., 00:40, Rasmus Svensson wrote: > I think the problem is that this reduction will build an expression like this: > >     (map + ... (map + ... (map + ... (map + ... levels> > > When clojure tries to realize an element of the resulting lazy seq, > every level will result in a ne

Re: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Rasmus Svensson
2010/11/3 John Szakmeister : > I'm sorry... I don't quite understand this explanation.  Do you mean > that reduce is realizing the entire list all at once?  I would think > it would grab an element one at a time.  Sorry for the stupid > question, but there's something subtle here that I'm not > und

Re: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread John Szakmeister
On Tue, Nov 2, 2010 at 4:49 PM, Meikel Brandmeyer wrote: > Hi, > > Am 02.11.2010 um 12:58 schrieb Pepijn de Vos: > >> The one-liner: >> http://gist.github.com/659491 > > I would expect this is because you pile lazy seq on lazy seq, which then get > realised, unfolding the whole thing resulting in

Re: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Meikel Brandmeyer
Hi, Am 02.11.2010 um 12:58 schrieb Pepijn de Vos: > The one-liner: > http://gist.github.com/659491 I would expect this is because you pile lazy seq on lazy seq, which then get realised, unfolding the whole thing resulting in the stack overflow. Try this: user=> (reduce #(doall (map + %1 %2)) (

[Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Pepijn de Vos
Hi all, Usually my 'bugs' are in my own code, but this time I talked to three of four people on IRC and came up with a one-liner that suffers the same problem my project has. I was optimizing some code to not retain the head of the sequence, but when I put a map inside a reduce over a gigantic

Re: Using map on multiple collections.

2009-12-29 Thread Nicolas Buduroi
Big thanks to everyone, the suggestions given are all very welcome, even if I didn't really needed a better version as my use of mappad is really simple for now. It was just curiosity on my part. The lazy version by Heinz could be quite useful in other situations, I've added it to my toolbox. Usin

Re: Using map on multiple collections.

2009-12-28 Thread Heinz N. Gies
On Dec 27, 2009, at 22:33 , Meikel Brandmeyer wrote: > Checking for nil here is independent on the contents of the lists. The `(map > seq lists)` first turns everything in lists into a seq. If a collection is > empty it will be turned into nil. This nil is independent of any contained > nil of

Re: Using map on multiple collections.

2009-12-27 Thread Meikel Brandmeyer
Hi, Am 27.12.2009 um 12:22 schrieb Heinz N. Gies: >> (defn extend-tupel >> [default & lists] >> (lazy-seq >> (let [seqs (map seq lists)] >> (when (some identity seqs) >> (cons (map (fnil first [default]) seqs) ; < Note previously >> missing brackets. >> (apply extend-

Re: Using map on multiple collections.

2009-12-27 Thread Heinz N. Gies
On Dec 26, 2009, at 21:09 , Meikel Brandmeyer wrote: > Here is a more idiomatic (and fully lazy) version using the fnil function > proposed by Rich here: > http://groups.google.com/group/clojure/msg/f251cfd9baab440a > > (defn extend-tupel > [default & lists] > (lazy-seq >(let [seqs (map se

Re: Using map on multiple collections.

2009-12-26 Thread Meikel Brandmeyer
Hi, Am 26.12.2009 um 14:45 schrieb Heinz N. Gies: > > On Dec 26, 2009, at 2:37 , Nicolas Buduroi wrote: > >> >> I'll have a look at this, it would certainly make this function more >> idiomatic to Clojurians. >> >> Thanks for the suggestion. > > I've another one I like even better, it get's

Re: Using map on multiple collections.

2009-12-26 Thread Daniel Werner
On Dec 23, 6:04 am, Nicolas Buduroi wrote: > Hi, today I needed to use the map function on multiple collections > which didn't had all the same length. In this case, it returns a > sequence of the size of smallest one. But the problem I was facing was > required to map until the end of the longest

Re: Using map on multiple collections.

2009-12-26 Thread Heinz N. Gies
On Dec 26, 2009, at 2:37 , Nicolas Buduroi wrote: > > I'll have a look at this, it would certainly make this function more > idiomatic to Clojurians. > > Thanks for the suggestion. I've another one I like even better, it get's a bit away from mapping over n list but it could achiev the same:

Re: Using map on multiple collections.

2009-12-25 Thread Nicolas Buduroi
On Dec 25, 9:08 am, "Heinz N. Gies" wrote: > On Dec 23, 2009, at 6:04 , Nicolas Buduroi wrote: > > > Hi, today I needed to use the map function on multiple collections > > which didn't had all the same length. In this case, it returns a > > sequence of the size of smallest one. But the problem I

Re: Using map on multiple collections.

2009-12-25 Thread Nicolas Buduroi
On Dec 25, 1:52 am, Tom Hicks wrote: > A slight modification, which I think avoids counting each collection > twice: > > (defn append-val [val & colls] >   (let [lengths (map count colls) >         maxlen (apply max lengths)] >     (map #(concat %1 (repeat (- maxlen %2) val)) colls lengths) >   )

Re: Using map on multiple collections.

2009-12-25 Thread Heinz N. Gies
On Dec 23, 2009, at 6:04 , Nicolas Buduroi wrote: > Hi, today I needed to use the map function on multiple collections > which didn't had all the same length. In this case, it returns a > sequence of the size of smallest one. But the problem I was facing was > required to map until the end of the

Re: Using map on multiple collections.

2009-12-24 Thread Tom Hicks
A slight modification, which I think avoids counting each collection twice: (defn append-val [val & colls] (let [lengths (map count colls) maxlen (apply max lengths)] (map #(concat %1 (repeat (- maxlen %2) val)) colls lengths) ) ) On Dec 23, 10:30 am, kyle smith wrote: > It's a

Re: Using map on multiple collections.

2009-12-23 Thread Nicolas Buduroi
On Dec 23, 12:30 pm, kyle smith wrote: > It's a little shorter if you unconditionally concat & repeat. > > (defn append-val [val & colls] >   (let [maxlen (apply max (map count colls))] >     (map #(concat % (repeat (- maxlen (count %)) val)) colls))) > > user> (apply map + (append-val 0 [1] [2 3]

Re: Using map on multiple collections.

2009-12-23 Thread kyle smith
It's a little shorter if you unconditionally concat & repeat. (defn append-val [val & colls] (let [maxlen (apply max (map count colls))] (map #(concat % (repeat (- maxlen (count %)) val)) colls))) user> (apply map + (append-val 0 [1] [2 3] [4 5 6])) (7 8 6) -- You received this message be

Using map on multiple collections.

2009-12-22 Thread Nicolas Buduroi
Hi, today I needed to use the map function on multiple collections which didn't had all the same length. In this case, it returns a sequence of the size of smallest one. But the problem I was facing was required to map until the end of the longest, padding the smaller ones with a default value. I c

Re: Using Map

2009-05-09 Thread Emeka
> From what you say I imagine you have something like a matrix > or table, something with rows and columns that form cells. > And you want to be able to grab the contents of one cell and move > it around to another cell. Andre, that statement captures all I intend to achieve. This is what I wanted

Re: Using Map

2009-05-08 Thread André Thieme
On 4 Mai, 17:01, Emeka wrote: > Hello All, > I want to arrange objects in rows and also being able to manipulate them. By > manipulation I meant, I could move one object from one row and use it to > replace another object in another. Should I use Map or something else? I > need your opinions here

Re: Using Map

2009-05-08 Thread Stephen C. Gilardi
On May 8, 2009, at 6:40 PM, James Reeves wrote: Perhaps you could explain in more detail what you intend to do and why? As Luke says, a "row" suggests a vector, rather than a map, but it's difficult to say for sure without knowing what you are trying to achieve. I'm interested in Emeka's answ

Re: Using Map

2009-05-08 Thread James Reeves
On May 8, 8:40 pm, Emeka wrote: > Luke > I was referring to map the data structure. I later decided to use struct > which is a map. I intend to manipulate elements of each row. > > Emeka Perhaps you could explain in more detail what you intend to do and why? As Luke says, a "row" suggests a vect

Re: Using Map

2009-05-08 Thread Emeka
Luke I was referring to map the data structure. I later decided to use struct which is a map. I intend to manipulate elements of each row. Emeka On Fri, May 8, 2009 at 6:17 PM, Luke VanderHart wrote: > > Do you mean map the function or map the data structure? > > If the most natural form of your

Re: Using Map

2009-05-08 Thread Luke VanderHart
Do you mean map the function or map the data structure? If the most natural form of your data is truly "rows", you're probably best off using a vector data structure. As for which function you use, that depends whether you're doing something to every element or only to specific elements, and if y

Using Map

2009-05-04 Thread Emeka
Hello All, I want to arrange objects in rows and also being able to manipulate them. By manipulation I meant, I could move one object from one row and use it to replace another object in another. Should I use Map or something else? I need your opinions here Regards, Emeka --~--~-~--~