0

I am making an interactive function and encountering a difficulty on the placing of the command list to set the function argument.

This code

  (interactive
   (list
    (let ( (rqmatch t)  (initpk "mixed")  (dflt "extended")
           (cseq '("expression" "mixed" "hlsexp"
                      "bracemk" "extended" "disable")) )

      (+ 2 2)
      (completing-read "Flare_type: " cseq nil rqmatch initpk
         'flare-hist dflt))))

versus the following

  (interactive
    (let ( (rqmatch t)  (initpk "mixed")  (dflt "extended")
       (cseq '("expression" "mixed" "hlsexp"
                     "bracemk" "extended" "disable")) )
      (+ 2 2)
      (list 
         (completing-read "Flare_type: " cseq nil rqmatch initpk
            'flare-hist dflt))))
7
  • That is up to you, although I guess for most people, your second version makes more sense. Personally, I don't see any reason here to use the let at all (but you might have a good argument for it). Also, I am not sure if the formatting that you use here is also the formatting that you use 'in production'. In that case, I would recommend having a look at some 'random' Emacs lisp source files to see the 'common way for formatting'. Jul 15, 2022 at 12:07
  • Using let was just a test for cases where they would be required. Emacs source files show a variety of implementations. So there is really no common way. Although we can agree on what makes it easier for working with other people's code.
    – Dilna
    Jul 15, 2022 at 12:28
  • A little question regarding the first implementation. Have read the introduction to emacs lisp, As I understand, the body of the let clause is the part that returns values from expressions, which are then collected in a list to set the argument values.
    – Dilna
    Jul 15, 2022 at 12:32
  • The comment about looking at source files was related to your formatting. To me, the formatting of Emacs source files generally looks quite consistent. Jul 15, 2022 at 12:33
  • Only the value of the last expression in the let clause its body is returned... this is a 'good argument' for using the second version Jul 15, 2022 at 12:35

1 Answer 1

0

The value of the special form function let should be the last evaluation inside it. The list will only contain completing-read value. list should be the last call inside let if one wants it to return a list.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.