since I’m using mapcar with posn-match in lambda mode (see screenshot) to handle lists, I would like to know what should I use, instead of posn-match, in order to process lists with floats. In fact, if the list is not rounded to integers is not accepted (the message is Error while evaluating the box MAPCAR : Function nthcdr expected a non-negative integer, got 0.0.). So, what is the most appropriate function to handle lists with floats? Thanks for your attention.
Francesco Vitale screenshot.pdf (58.8 KB)
you cannot use floats for positions. It has nothing to do with mapcar.
posn-match second input takes positions. And these should be integers not floats.
You cannot have an 1.333 nth elemt in a list.
Maybe you should clarify what you want to do, before usinf these. i.e mabe you have some data (i am guessing), which gives floats, and you want to use them as positions in a list. If it is so, you chouls consider your algorithm.
Hi Francesco, (whoops Karim was faster as always !
This seems normal, the nthcdr is somewhere inside posn-match, whose arguments are :
- a list to pick up elements from
- a list of indexes or positions in the first list (starting with 0 as first position, 1 as second etc.)
Posn-match is nothing but a glorified nth, that can take a list of positions instead of only one position.
So it’s normal that it doesn’t accept floats, there are no such things as float positions.
what is the 2.3th element in (5 2 6 432 12)?
You need to round it either below — (floor 2.3) => 2th gives 6 —
or above — (ceiling 2.3) => 3th gives 432 — again counting from 0
If you actually want to get something “in between” two elements in the first list — if they are numbers of course and not arbitrary symbols — you need a very different function, with some kind of interpolation inside.
Hope it makes sense !
thanks for having clarified for me the posn-match role once for all: I obviously didn’t recall that it was an enhanced nth. I erroneously assumed that the position in “posn” was coordinate-wise! Since I’m working with two lists of y coordinates, as Julien has remarked, I’d need to use a very different function as lambda: something that works as posn-match but where the position is a real number coordinate. Do you have in mind something that could do this job? Thanks again.