help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning value from function


From: Jean Louis
Subject: Re: Returning value from function
Date: Thu, 3 Nov 2022 09:59:09 +0300
User-agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02)

* Heime <heimeborgia@protonmail.com> [2022-11-02 08:08]:
> 
> I want the following function to return an indicator (Green or
> Amber).  How can this be done?

Sure, but me personally, I prefer using `cond' but would not mix it with `if' 
in the same time:

Instead of:

(defun txcomplt-light (featr)
  "DOCSTRING."
  (cond
   ((eq 'company featr)
    (if (equal 2 (aref recorder 0))
        (message "Light | Green")
      (message "Light | Amber")))
   ((eq 'corfu featr)
    (if (equal 2 (aref recorder 1))
        (message "Light | Green")
      (message "Light | Amber")))) )

(defun txcomplt-light (featr)
  "DOCSTRING."
  (cond ((and (eq 'company featr) (equal 2 (aref recorder 0))) (message "Light 
| Green"))
        ((and (eq 'corfu featr) (equal 2 (aref recorder 1))) (message "Light | 
Amber"))))

However, I did not maybe make your logic right. I hope you see that `if' is not 
necessary. 

To make function return anything, just make the value that you wish returned 
the last one:

(defun txcomplt-light (featr)
  "DOCSTRING."
  (cond ((and (eq 'company featr) (equal 2 (aref recorder 0))) 
         (message "Light | Green")
         "Green") ;; this is what is returned
        ((and (eq 'corfu featr) (equal 2 (aref recorder 1))) 
         (message "Light | Amber")
         "Amber"))) ;; this is what is returned

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]