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))))
Dilna
  • 1
  • 3
  • 11
  • 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'. – dalanicolai Jul 15 '22 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 '22 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 '22 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. – dalanicolai Jul 15 '22 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 – dalanicolai Jul 15 '22 at 12:35
  • Emacs source files using list are quite basic, just list of expressions with perhaps if statements. – Dilna Jul 15 '22 at 12:49
  • https://www.quora.com/What-does-it-mean-to-format-your-code, it is more or less those extra spaces in the let that make your code look strange to me. And additionally, I think I mostly see those local variables definitions getting placed on separate lines like in this example (although that is probably a matter of preference) – dalanicolai Jul 15 '22 at 12:58

1 Answers1

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.

Dilna
  • 1
  • 3
  • 11