[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shrinking the C core
From: |
Emanuel Berg |
Subject: |
Re: Shrinking the C core |
Date: |
Fri, 15 Sep 2023 23:59:55 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Arthur Miller wrote:
> We can certainly speak about "old ways", let us take the
> or-idiom or how should I call it: initialization of the
> default value for optional arguments:
>
> (defun foo (&optional who-am-I)
> (let ((who-am-I (or who-am-I "foo")))
> (message "I am %s." who-am-I)))
>
> Is that really better than typing:
>
> (cl-defun foo (&optional (who-am-I "foo"))
> (message "I am %s." who-am-I))
>
> The user has to learn the idiom, which uses operator "or" to
> perform something that visually has nothing to do with the
> intention of the code, and also has to type the additional
> let-form each and every time. Than the users who are not
> familiar with the idiom will perhaps come up with their own
> version, using setq or some other thing, and you will really
> have to think what the user wanted to say with their code if
> you had to debug it. Is it better than seing an initialiser
> and knowing directly what is the default value and everyone
> using uniform syntax?
This is a very good example where the CL way is simply
superior. I don't know how many ways I've seen people,
including myself, setting the default value: `or', 'unless',
`setq', `let' - or forgetting about it, for that matter.
But we do have `cl-defun' - in Elisp - so it isn't like we
don't have it for anyone to use if and when desired. I learned
about `cl-defun' much later than I did &optional but if I want
optional arguments now `cl-defun' is a much better choise than
`defun', because of the much more clear syntax to provide the
default value.
--
underground experts united
https://dataswamp.org/~incal
- Re: [External] : Re: Shrinking the C core, (continued)
- Re: [External] : Re: Shrinking the C core, Arthur Miller, 2023/09/12
- Re: [External] : Re: Shrinking the C core, Emanuel Berg, 2023/09/12
- Re: [External] : Re: Shrinking the C core, Emanuel Berg, 2023/09/12
- Re: [External] : Re: Shrinking the C core, Tomas Hlavaty, 2023/09/12
- Re: [External] : Re: Shrinking the C core, Richard Stallman, 2023/09/12
- Re: Shrinking the C core, Bob Rogers, 2023/09/08
- Re: Shrinking the C core,
Emanuel Berg <=
- Re: Shrinking the C core, Richard Stallman, 2023/09/17
- Re: Shrinking the C core, Richard Stallman, 2023/09/08
- Re: Shrinking the C core, Arthur Miller, 2023/09/09
- Re: Shrinking the C core, Richard Stallman, 2023/09/11
Re: Shrinking the C core, Arthur Miller, 2023/09/12
Re: Shrinking the C core, Arthur Miller, 2023/09/12