Hi Herwig,

Thanks for the reply!  I think I had tried that before and I tried again 
just now but it gives a problem of arity:

CompilerException java.lang.RuntimeException: Can't have fixed arity 
function with more params than variadic function, 
compiling:(audio_seq/core.clj:42) 

which makes sense.  Using apply map though does simplify it a bit:

(defn amix
  ([] [])
  ([& a] 
     (let [len (count a)]
       (if (= len 1)
         (first a)
         (apply map + a)))))

and that is working rather nicely, thanks!  

I spent a couple hours today trying to work on performance of the code and 
it's unfortunately very poor at the moment.  Doing a lot of number 
crunching with lazy sequences, while elegant, seems to be not very 
performant. I think I need to learn a bit more about Clojure and perhaps 
rethink my design strategy for this work.

Thanks again!
steven




On Saturday, February 16, 2013 1:35:14 AM UTC, Herwig Hochleitner wrote:
>
> Sorry, hit the wrong key early. This version handles the one arg case 
> efficiently:
>
> (defn amix 
>   ([a] a)
>   ([& as]
>     (apply map + as)))
>
>
> 2013/2/16 Herwig Hochleitner <hhochl...@gmail.com <javascript:>>
>
>> To your first question: How about
>>
>> (defn amix 
>> [& a]
>>   (apply map + a))
>>
>>
>>
>> 2013/2/16 Steven Yi <stev...@gmail.com <javascript:>>
>>
>>> Hi All,
>>>
>>> I'm fairly new to Clojure (enjoying it very much!) and had a couple 
>>> questions regarding lazy sequences.  
>>>
>>> 1. With a sequence of sequences, I want to reduce the sequences down 
>>> into a single sequence.  So, the heads of all the sequences gets reduced, 
>>> then the next items, etc.  The end result would also be a lazy sequence. 
>>>  Right now I have this code that is working, but I wasn't sure if there's 
>>> some other way that might be clearer:
>>>
>>> (defn amix
>>>   ([] [])
>>>   ([& a]
>>>      (let [len (count a)]
>>>        (if (= len 1)
>>>          (first a)
>>>          (map #(reduce + %) (partition len (apply interleave a)))))))
>>>
>>>
>>> 2. I'm planning to have a number of sequence transforming functions. 
>>>  Most will probably have this shape:
>>>
>>> (defn some-func [arg1 arg2 xs]
>>>   (map #(some code...) xs))
>>>
>>> This would be so I could consume a lazy sequence xs, operate on it, then 
>>> output a lazy sequence.  I thought I might write a macro to simplify this 
>>> and have the function do its own lazy-seq and recursive call to itself, 
>>> rather than go through map (figured it might save some call overhead, and 
>>> simplify the macro writing, but am still a bit new with this).  I imagine 
>>> this should work fine, but is this kind of thing already encapsulated 
>>> somewhere?
>>>
>>> Thanks!
>>> steven
>>>
>>>  -- 
>>> -- 
>>> 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/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>

-- 
-- 
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/groups/opt_out.


Reply via email to