emacs - Elisp function return value -


i'm having (probably) dumb problem elisp. want function return t or nil depending on when condition. code:

(defun tmr-active-timer-p   "returns t or nil depending of if there's active timer"   (progn     (if (not (file-exists-p tmr-file))         nil       ; (... more code)       )     ) ) 

but i'm having error. i'm not sure how make function return value... i've read function return last expression result value in case, wan't make (php mess warning):

// code  if ($condition) {   return false; }  // more code... 

maybe i'm missing point , functional programming doesn't allow approach?

first, need argument list after tmr-active-timer-p; defun syntax is

(defun function-name (arg1 arg2 ...) code...) 

second, not need wrap body in progn.

third, return value last form evaluated. if case can write

(defun tmr-active-timer-p ()   "returns t or nil depending of if there's active timer."   (when (file-exists-p tmr-file)       ; (... more code)     )) 

then return nil if file not exist (because (when foo bar) same (if foo (progn bar) nil)).

finally, hanging parentheses considered poor code formatting style in lisp.

ps. emacs lisp not have return, have nonlocal exits. urge avoid them unless really know doing.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -