AnimusComplex
AnimusComplex

Reputation: 31

LISP Append Method

I have to create a procedure called (list-push-front lst new-list) that adds the elements from new-list to the front of lst. For example, the output for : (list-push-front '(4 3 7 1 2 9) '( 1 2)) should give
'(1 2 4 3 7 1 2 9)

This what I have so far but I receive an arity error message for the expected number of arguments(2) not matching the given number expected (1)

 (define(list-push-front lst new-list)   
  (if(null? lst) 
  '()
  (append(list-push-front(car new-list))(lst(car lst)))))

Upvotes: 1

Views: 328

Answers (1)

Óscar López
Óscar López

Reputation: 236170

Just call the append procedure, it does exactly what you need - when using a new procedure you should always refer to the documentation. In this case we don't have to write an explicit recursion, using the built-in function is enough:

(define (list-push-front lst new-list)
  (append new-list lst))

For example:

(list-push-front '(4 3 7 1 2 9) '(1 2))
=> '(1 2 4 3 7 1 2 9)

Upvotes: 3

Related Questions