A good point, Björn -

 Since the number of elements is known beforehand in mdutil & mdls, an
immutable array
would suffice (& use less words). I carried the vector format over from a
previous incarnation
of <md-command>, where I didn't know how many elems would be needed in the
array.

I'm not religious about mutating data structures, but your suggestion makes
the code more succinct.

Thanks,
~cw


On Wed, Nov 13, 2013 at 5:04 AM, Björn Lindqvist <[email protected]> wrote:

> Here are some random tips from me. I'm also a Factor newbie so take it
> with a grain of salt:
>
>  * Don't use vectors because normal sequences works just as well.
>  * Be functional! Avoid words that mutate data structures because they
> make the code harder to reason about.
>
> F.e. this piece of code in mdls:
>
>     "mdls" 1vector swap suffix!
>
> can be written as just:
>
>     "mdls" swap 2array
>
> Another example is your mdutil word:
>
>     :: (mdutil) ( flags on|off volume root/owner -- seq )
>         root/owner 1vector "-" flags append suffix!
>         "-i" suffix! on|off suffix! volume suffix!
>
> It's a great showcase for local variables but can be better written
> without array mutations:
>
>     :: mdutil ( flags on|off volume root/owner -- seq )
>         root/owner flags "-" prepend "-i" on|off volume 5 narray
>
>
> 2013/11/13 CW Alston <[email protected]>:
> >  I've posted a new gist for spotlight.factor w/ filename & Factor
> > formatting.
> > I think I dealt with most of Alex's red-lines, & I shed the string
> > constants.
> > The whole thing is much shorter. The included examples work on my
> machine.
> >
> >  The file can be USE:d from the listener if you give it a folder in your
> > 'work'.
> >
> >  After a long divagation, looks like I've wound up back where John & Alex
> > suggested I start, 3 weeks ago. Well, like I was warned in the Boy
> Scouts,
> > when you wander lost in the woods, you tend to go 'round in circles.
> > Just couldn't see how to get on from there without a compass (or native
> > guides),
> > & I did learn a lot along the way. Still needs some improvement (maybe
> bug
> > fixes, too).
> >
> >  In particular, I'd like to memoize an API call to
> > MDSchemaCopyAllAttributes(),
> > but I'm better at Chinese than C. Pointers on alien-invoke, or what else
> to
> > use?
>
>
>
> --
> mvh/best regards Björn Lindqvist
>



-- 
*~ Memento Amori*
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to