lisp - how to set a bunch of variables depending on one condition in elisp? -
suppose want set values of bar
, baz
depending on 1 condition, same in both cases, value of foo
. using let
special form, this
(let ((bar (if foo 1 2)) (baz (if foo 3 4))) ... )
while above program correct, seems little strange checks value of foo
twice. there idiomatic expression 1 can use in such cases avoid double-check?
you needn't set values in let form itself. let form creates local bindings, after can set values wish.
(let (bar baz) (if foo (setq bar 1 baz 2) (setq bar 3 baz 4)) ...)
Comments
Post a Comment