Jozef,

Thanks--good advice about names.

Well, I don't know whether useful is the right word.  domap (nee mapc) 
obviously wouldn't add any functionality.  (Neither does 'map', I suppose, 
since we have 'for'.)  

I seem to be unusual in my affection for this construct outside of purely 
functional contexts--otherwise Clojure would already have it.  

For years I've been using 'mapc' or 'mapcar' for side effects in Common 
Lisp, or 'map' in Perl, etc.  Maybe I do tend prefer to stay away from 
variadic functions, too, other things being equal.  

Anyway, no problem--I can define domap for myself if I want, even if it 
doesn't have enough support to be part of the language.

Here's a cleaned-up, simplified version of something I wrote the other day:

(defn unmask!
  "Given a core.matrix vector representing a node mask, and an index into 
that vector, set the indexed element of the mask to 1."
  [mask idx]
    (mx/mset! mask idx 1.0)) ; fyi: mset! modifies a vector element or 
matrix element

(defn add-nodes-to-network!
  [node-mask ...]
...
   (let [idxs-to-unmask (construct-seq-of-indexes-to-unmask  ...)
         unmask-node! (partial unmask! node-mask) ] 
     (domap unmask-node! idxs-to-unmask)))
     
There are lots of other ways to do this.  I'm sure many that are better 
relative to one goal or another.  To me the last line seems natural, and 
easy to understand.  Just my personal preference, though.



On Tuesday, January 28, 2014 9:27:13 AM UTC-6, Jozef Wagner wrote:
>
> Regarding names, I would not place a bang after it (!), as there is 
> nothing in that function itself that forbids its use inside transactions. 
> Functions which primary purpose is to produce side effects tend to begin 
> with 'do', so my suggestion is to name it 'domap'. 
>
> I am however still not convinced of its usefulness beyond very few 
> specific cases. If you often need to call some side-effecty function for 
> all items in the collection, consider extending that function so it accepts 
> a collection as an argument, or make it a variadic fn.
>
> JW
>
> On Tuesday, January 28, 2014 4:12:35 PM UTC+1, Mars0i wrote:
>>
>> On Tuesday, January 28, 2014 7:29:06 AM UTC-6, Stefan Kamphausen wrote:
>>>
>>> Does wrapping your map expression in a dorun do what you want?
>>>
>>
>> Yes, it does.  But that's more verbose, and as Jozef Wagner notes, it 
>> creates seqs unnecessarily.
>>
>> I like Jozef's solution.  However, I think a proper definition of mapc 
>> may have to be more complicated, in order to allow for multiple sequence 
>> arguments after the function argument.  Maybe as a macro that calls doseq 
>> in the end.
>>
>> If nothing like this exists, I'd call it "map!", since "mapc" is just an 
>> odd legacy name from Common Lisp.  The "!" doesn't mean that map! is 
>> guaranteed to have side-effects, but "!" doesn't usually guarantee that, 
>> anyway.   (I delight in CL's idiosyncrasies, but appreciate Clojure's more 
>> systematic elegance.)
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to