Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding to the end of list in LISP [duplicate]

Tags:

People also ask

How does append work in Lisp?

Lisp. Append originates in the Lisp programming language. The append procedure takes zero or more (linked) lists as arguments, and returns the concatenation of these lists.

What is the Lisp function for concatenating 2 lists?

let ab = [a, b]. concat(); Scala.

What does cons mean in Lisp?

In computer programming, cons (/ˈkɒnz/ or /ˈkɒns/) is a fundamental function in most dialects of the Lisp programming language. cons constructs memory objects which hold two values or pointers to two values. These objects are referred to as (cons) cells, conses, non-atomic s-expressions ("NATSes"), or (cons) pairs.

How do you define a list in Lisp?

The list function is rather used for creating lists in LISP. The list function can take any number of arguments and as it is a function, it evaluates its arguments. The first and rest functions give the first element and the rest part of a list.


Possible Duplicate:
what is the ‘cons’ to add an item to the end of the list?

After watching many tutorials on lisp and searching high and low on google for answers, I still cannot figure out how to add to the end of a list in LISP.

I want my function to add 'a at the end of the list '(b c d) but I only know how to add it in front. Can someone help me use cons correctly to add 'a at the end of the list? Here is my code. Thanks in advance.

(defun AddRt (a list)
  (cond
    ((null list)
      0)
    (t
      (princ (cons a (cons (car list) (cdr list))))
    )))


(AddRt 'a '(b c d))