Regarding item-from-end *at first* I don't see the motivation for making it
a primitive. But when I used the profiler to compare the following code's
performance with 'item' I found item to be over 7 times faster.

to-report item-from-end [number list-or-string]
  report item (length list-or-string - number)  list-or-string
end

Though just using item (length ...) ... [open coding the reporter] was only
half the speed of just running item.

In addition to Seth's argument for not extending 'item' as suggested, think
about the added complexity for beginners of the documentation of 'item'.

Alan -- are there any occasions where a single instance of 'item' in some
code will have positive and negative index arguments?

Ideally some day the NetLogo compiler will be able to generate code as good
as that of 'primitives'. Otherwise one needs to consider the costs (more
code to maintain and test, longer programming manuals, more work to learn
the language) and benefits of adding this new primitive.

Best,

-ken


On 25 August 2014 19:57, Alan Isaac <[email protected]> wrote:

> Just to clarify, my wish was not for someone to write a helper function
> (which is not hard), it is for negative indexes to be supported by the core
> language.
>
> Seth's opposition makes it pretty clear that this will not happen.  But I
> want to point out that the reason offered for this opposition is lack of
> faith in the user.  After many years of using Python, I cannot recall one
> time when my use of negative indexes has created a problem.  And although
> James suggests that being able to reverse order by appropriate choice of
> index limits will produce head scratching, I have found it a wonderful and
> often used feature.  In fact I would love for NetLogo to add a primitive
> `slice` reporter that fully supports Python-style slicing of lists and
> strings.  (This could be done without making any other changes, although it
> would make `sublist` and `substring` somewhat redundant.  If the developers
> oppose supporting negative indexing elsewhere, perhaps they can
> still consider such a new primitive.)
>
> Thanks for considering,
> Alan
>
> --
> You received this message because you are subscribed to the Google Groups
> "netlogo-devel" 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/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"netlogo-devel" 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/d/optout.

Reply via email to