* Returning value from function
@ 2022-11-02 5:06 Heime
2022-11-02 5:42 ` Heime
2022-11-03 6:59 ` Jean Louis
0 siblings, 2 replies; 5+ messages in thread
From: Heime @ 2022-11-02 5:06 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
I want the following function to return an indicator (Green or Amber). How can this be done?
(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")))) )
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Returning value from function
2022-11-02 5:06 Returning value from function Heime
@ 2022-11-02 5:42 ` Heime
2022-11-02 16:42 ` Emanuel Berg
2022-11-03 6:59 ` Jean Louis
1 sibling, 1 reply; 5+ messages in thread
From: Heime @ 2022-11-02 5:42 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
------- Original Message -------
On Wednesday, November 2nd, 2022 at 5:06 AM, Heime <heimeborgia@protonmail.com> wrote:
> I want the following function to return an indicator (Green or Amber). How can this be done?
>
> (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")))) )
I would like tow functions, one to return a string ("Green" "Amber") or a symbol ('green 'amber).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Returning value from function
2022-11-02 5:06 Returning value from function Heime
2022-11-02 5:42 ` Heime
@ 2022-11-03 6:59 ` Jean Louis
2022-11-03 9:19 ` Emanuel Berg
1 sibling, 1 reply; 5+ messages in thread
From: Jean Louis @ 2022-11-03 6:59 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
* 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-03 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-02 5:06 Returning value from function Heime
2022-11-02 5:42 ` Heime
2022-11-02 16:42 ` Emanuel Berg
2022-11-03 6:59 ` Jean Louis
2022-11-03 9:19 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.