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

Reply via email to