K
K
Karina2015-10-17 23:01:07
Lisp
Karina, 2015-10-17 23:01:07

Can you explain lambda in lisp?

I'm starting to understand Lisp a little (I want to attach one thing to emacs). And I don't understand the tutorial:

...
(let* ( (...)
  (lines (...) ) 
   )
  (insert 
    (mapconcat '(lambda (s) (concat "<key>" s ) )
    lines ;; как передается переменная, которая ниже в параметр lambda?
    "\n"
  ) )

Actually, the question is in the comment itself - I don’t understand by what law lines was passed to the lambda parameter?
How does is called?
Thanks to all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-12-03
@iKapex

The mapconcat function calls the function passed in the first argument (lambda in your case) for each element of the sequence passed in the second argument, and the returned values ​​are glued into one line, separated by the third argument.

(mapconcat 
  '(lambda (s) (concat "<key>" s ))
  lines
  "\n")

That is, if linesit contains '("a" "b" "c"), then first the string "a" will be passed to the lambda, there it will be glued with the string "<key>", then the string "b", then "c", and after the received strings "<key>a", "<key>b" and "<key>c" will be concatenated into one string "<key>a\n<key>b\n<key>c".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question