How about $idx for map?

Started by Kazimir Majorinc, July 26, 2008, 05:50:51 AM

Previous topic - Next topic

Kazimir Majorinc

If it is realistic, it can be cute small improvement.



(map (lambda()(print $idx)) '(1 2 7)) ; 127
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Jeff

#1
It would be more idiomatic for $idx to be the position of the current item in the list.


(map (fn (x) (list $idx x)) '(1 2 3)) => '((0 1) (1 2) (2 3))

Anyway, it isn't necessary.  Use dolist for that.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Kazimir Majorinc

#2
Quote from: "Jeff"It would be more idiomatic for $idx to be the position of the current item in the list.


(map (fn (x) (list $idx x)) '(1 2 3)) => '((0 1) (1 2) (2 3))

Anyway, it isn't necessary.  Use dolist for that.


Yes, you are right about $idx as position on the list. I was not focused. True, it is not necessary, but it is still small improvement which could provide similar advantage to $idx in other loops, isn't it - if its implementation is equally (time, space, implementation effort) cheap.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Jeff

#3
I don't think so.  It breaks convention.  A function, even an anonymous function, takes arguments.  What is it if there are multiple parameters, such as (map 'list '(1 2 3) '(4 5 6))?  You could always write your own macro that did the same thing, but accepted an expression instead of a function.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code