2
 (repeat-transformation #'(lambda (x) (* 2 x)) 4 1)

This is a LISP lambda function , i don't understand what is the last "1" ? Thanks.

3 Answers 3

5

Definition: repeat-transformation (F N X)

Repeat applying function F on object X for N times.

You're defining your lambda function to be called by repeat-transformation 4 times on the integer 1.

Hope that explains it.

Sign up to request clarification or add additional context in comments.

Comments

2

Google comes back with a recursive definition for repeat-transformation:

(defun repeat-transformation (F N X)
  "Repeat applying function F on object X for N times."
  (if (zerop N)
      X
    (repeat-transformation F (1- N) (funcall F X))))

Which indicates the 1 is the value on which the function operates. The next 3 Google links confirm it.

Comments

0

The lambda function is the first argument to repeat-transformation. 4 and 1 are the second and third arguments respectively.

The Lisp Tutorial Advanced Functional Programming in LISP defines a repeat-transformation function that repeats applying function F on object X for N times. If yours is equivalent, then the 1 is the number of times to apply the lambda function on the value 4.

2 Comments

Yes, it repeats applying F on X for N times, but the order of the arguments is F N X.
Good catch. It's a reminder to double-check the function signature rather than assume that the order of the arguments is the same as in the documentation string. It also demonstrates that it might be helpful to maintain the order of the arguments when documenting a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.