Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add an element in a list

Status
Not open for further replies.

sarte

Programmer
Dec 5, 2008
2
DE
Hi,
I want to add an element in the head of a list, for instance:
add(a,[b,c],N). N= [a,b,c].
But I'm too stupid, I don't know how to start with the easy case, when the list is empty. I thought of add(A,[],[A]). I think it is wrong, because at the end of a recursive list A will stand at the end(N= [b,c,a]) , and I don't want this.
Can somebody help?
 
Remember that, you can acces, as in Lisp, at the first element of a list and the rest of this list by List = [Head | Tail].
 
Argh, I'm stupid^^ It was so easy. Just "add(A,B,[A|B]).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top