[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [External] : Closures - do you understand them well?
From: |
Drew Adams |
Subject: |
RE: [External] : Closures - do you understand them well? |
Date: |
Thu, 8 Dec 2022 17:56:00 +0000 |
> But yes, like explicitly specifying a nil binding (X nil) instead of (X)
> this is bout readability and personal preferences. (X '()) is my
> hint to the reader that X will be used as a list type accumulator in the
> BODY. I prefer that over (X ()), (X nil) and (X). It's a stylistic
> habit.
>
> Why? Because I want to make clear that the variable is initialized with
> an empty list, compared to what the evaluation of an empty list aka nil
> returns (which accidentally happens to be the same again in Lisp).
I have _exactly_ the same concern as you:
human-reader readability (and in most cases
that's me).
I use (let ((xs ())
(foop nil)
(bar nil)
(yy))
to tell me that:
1. xs and foop are bound initially.
yy gets its meaningful value only from
the `let' body - its initial nil value
is (should be) meaningless/ignored.
2. xs has a list value (at least initially).
IOW, I use () for the same reason you use
'().
3. foop and bar have non-(non-nil) values
(at least initially).
4. foop is used as a Boolean (true/false).
bar is likely not used just as a Boolean.
(bar might have several possible values,
where nil might mean some base case,
which could, but need not, mean false.
Wrt #4: I use the suffix code convention
"p"/"-p" for variable names, as well as for
function names. I find this _very_ helpful.
Throughout the body, I'm reminded that foop
is Boolean.
___
You say, "which accidentally happens to be
the same again in Lisp". To me it's not an
accident; it's by design. It's arguable,
and it's been argued, but to me this design
is (1) clever/elegant and (2) _very_ handy.
Is #1 important? Maybe not, but to me it's
lovely.
Re: Closures - do you understand them well?, Tassilo Horn, 2022/12/08