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

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

Re: operations on path lists


From: Jean Louis
Subject: Re: operations on path lists
Date: Tue, 7 Feb 2023 11:33:08 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Emanuel Berg <incal@dataswamp.org> [2023-02-05 16:15]:
> Jean Louis wrote:
> 
> >>> (cond ((file-directory-p file) (expand-file-name file))
> >>>       (t nil))
> >> 
> >> (when (file-directory-p file)
> >>   (expand-file-name file) )
> >
> > I am aware of it, I prefer using `cond' as I get
> > more clarity.
> 
> The (t nil) part is of no use, even if you stick to `cond'.
> 
>   "If no clause succeeds, cond returns nil."
> 
> And: one COND, one branch or BODY - in idiomatic Lisp, that's
> `when'.

I use it to see the `nil'. 

To help person how you think is better, then write it in your way for
that person. 

`cond' in my world has special place, it is not really replacement for
`if' or other conditionals. It is used in period of programming as it
helps with thinking during the function ripening.

In general I will first want to define what the function should return
without other conditions. The ripening process begins.

(defun my-function (arg)
  (cond (t (user-error "Verify me"))))

Then I start adding conditions:

(defun my-function (arg)
  (cond ((zerop arg) (message "Worked"))
        (t nil)))

And more to it:

(defun my-function (arg)
  (cond ((stringp arg) (message "I got `%s'" arg))
        ((zerop arg) (message "Worked"))
        (t nil)))

and then I add more:

(defun my-function (arg)
  (cond ((numberp arg) (message "I got number `%s'" arg))
        ((stringp arg) (message "I got string `%s'" arg))
        ((zerop arg) (message "Worked"))
        (t nil)))

I hope you can see how conditions are developed during time. In the
process of ripening it is good to see `nil' visually in the last
condition from beginning. 

The return can be `nil' but also something else.

Once function is "stable", then I may remove what is not any more
necessary for some readers.

Got that one?

-- 
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]