help with funcion

Discussion of Common Lisp
Post Reply
bbeni
Posts: 1
Joined: Sun Oct 23, 2011 4:58 am

help with funcion

Post by bbeni » Sun Oct 23, 2011 5:13 am

I want make function in lisp, because I have it in java

void index()
{ for(int j=0;j<zoznamP.length;j++){
if (zoznamP[j].equals("2")) indexM=j;}, where String [] zoznamP={"2","3","4"} ;

so i call function (funcion 3) and it returns 2, List I want declared:(defparameter *list* '(3 5 6 8 4 2 1 9))

Paul
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: help with funcion

Post by Paul » Mon Oct 24, 2011 8:29 pm

If I understand the question correctly, the function POSITION does what you want.

virex
Posts: 17
Joined: Fri Oct 28, 2011 3:41 pm

Re: help with funcion

Post by virex » Fri Oct 28, 2011 3:49 pm

Do you want a function that does that, or do you want to write one yourself?

In the first case, you're looking for the index of the element that is equal to the provided value, and the function that does this is position.

If you want to write one yourself, the most succinct and easy way for you would probably be to use the loop macro.

Post Reply