Reputation: 107
I have got a function in Scheme that I want to accept a list of lists. I then want to be able to send each list in this list to another function, but I haven't been able to figure out how to get the function to accept a list of lists. What I've got now looks like this:
(define (myFunction lst)
(car(lst)))
I want to be able to call the function like this:
(myFunction '((1 2 3 4) (5 6 7 8) (9 10 11 12))
But when I try to do that, I get the following error:
function call: expected a function after the open parenthesis, but
received (list (list 1 2 3 4) (list (5 6 7 8) (list 9 10 11 12))
Can anyone see what I'm doing wrong? It's as if it thinks the list of lists is a string. I just want to be able to split the lists (using car and cdr) and work with them or combine all the elements into one list. Sorry if this sounds way too obvious, but I've been reading my book on Scheme and searching Google for an answer for hours.
Upvotes: 0
Views: 117
Reputation: 206717
You have a simple error. Remove the (
before lst
.
(define (myFunction lst)
(car lst))
Upvotes: 2
Reputation: 70225
In: (define (myFunction lst) (car(lst))
the form (lst)
is a function call - hence the reported error. If you want the first element of a list, use (car lst)
and if you want the rest of the stuff use (cdr lst)
.
Also, your provided definition of myFunction
has unbalance parens; not sure how it worked to produce the error. Perhaps your cut-and-paste into StackOverflow was wrong.
Upvotes: 1