Deepak
Deepak

Reputation: 1545

how to use functions as arguments and apply to sublist in lisp?

The question is pretty short.

Suppose F is any function, in this case I am using F = length, and L is any list that contains sublists, e.g. L in this case is ((3 3 3) (2 2) (1)). What should I do to have function F be applied to car of list L?

(defun try (F L)
    ('F (car L)))

When I call this function like

(try 'length '((3 3 3) (2 2) (1) (1) ))

I should get 3 as the result since the length of first Ssblist of L, (3 3 3), is 3.

Upvotes: 1

Views: 180

Answers (1)

C. K. Young
C. K. Young

Reputation: 223023

Use funcall:

(funcall f (car l))

Upvotes: 5

Related Questions