Hi Lior, I wouldn't worry about it. I just profiled running each of nthelem(2 lst) nth(1 lst) and cadr(lst) 100 million times, and from two experiments of each I saw: cadr: 12.12 12.12 nthelem: 13.11 13.28 nth: 13.00 13.21 So if it's only taking 12 or 13 seconds for 100 million operations, that's something that I'd class as over-optimising your code! I'd go for style over (minor) performance benefits here - so whatever makes most sense to you. In practice I rarely use nth or nthelem because it's unusual for me to want to get a fixed element from a list unless it's short, otherwise I'd iterate over the list - odd occasions when you have a short list with more than 4 items I might, but otherwise I tend to use car, cadr, caddr or cadddr - it's a matter of typing a little less (not much though). So pick whichever works for you. Regards, Andrew.
↧