2 Replies - 1431 Views - Last Post: 19 June 2016 - 05:09 AM

#1 bperkins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-March 15

Common Lisp: List of Lists

Posted 18 June 2016 - 04:46 PM

I am trying to write a function in LISP that accepts a list of lists as the argument, then returns the second element of the second list. This is what I have for the function definition. When I call the "second-of-second" function, I get this error. Thanks for the help.

CG-USER(1): (defun second-of-second((x)(y)(z)) (car(cdr y)))

CG-USER(2): (second-of-second '((a b c)(1 x)(e f)))

Error: Non-symbol used as a lambda argument name in function SECOND-OF-SECOND.
[condition type: PROGRAM-ERROR]

This post has been edited by sepp2k: 19 June 2016 - 05:01 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Common Lisp: List of Lists

#2 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon

Reputation: 10726
  • View blog
  • Posts: 18,357
  • Joined: 19-March 11

Re: Common Lisp: List of Lists

Posted 18 June 2016 - 06:49 PM

(defun second-of-second((x)(y)(z)) (car(cdr y)))

I would start by defining this function to take a list as its argument :)
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2517
  • View blog
  • Posts: 4,001
  • Joined: 21-June 11

Re: Common Lisp: List of Lists

Posted 19 June 2016 - 05:09 AM

The parameter list of a function consists of the names of its parameters - one per parameter (ignoring for the moment things like rest, keyword or optional arguments). Anything else (like in your case parentheses) is not allowed, which is what the error message is telling you.

If you want your function to take exactly one argument, the parameter list should contain exactly one name, which should not be surrounded in further parentheses.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1