I have one list of floating numbers like below:
A= (0.0 0.36 1.44 1.8 2.16 2.52 3.6 3.96 4.32 4.68 5.76 6.12 6.48 6.84 7.92 8.28 8.64 9.0 )
i have another floating number which comes from Xcoordinate of centerBox of a pin object which is 8.887.
I want to execute the following function:
for(k 0 length(A)
if(lessp(nth(k A) y) then printf("%.2f" nth(k A))
this is giving an error message as follows
Error lessp:cant handle(nil <8.887)
can someone help me how to solve this?
Before I get to the fact that that the approach you're using is wrong and rather inefficient, the reason it is failing is that your loop is going off the end of the list. There's two reasons for that - one is the fact that your loop goes to length(A) rather than length(A)-1 - and the other is the k=k+1 which also passes the end of the list. If the length of the list is L then nth(L A) will return nil - because it is zero-index.
Using nth() to access a list is inefficient for anything other than very small lists, because lists are sequential. It's not clear to me precisely what you're trying to do with the k=k+1 bit, but doing this would be better:
foreach(elem A if(lessp(elem y) then printf("%.2f " elem)))