[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: as_ly_scm_list
From: |
Dan Eble |
Subject: |
Re: as_ly_scm_list |
Date: |
Tue, 26 Jul 2022 18:46:12 -0400 |
On Jul 25, 2022, at 16:09, Jean Abou Samra <jean@abou-samra.fr> wrote:
>
> Now, the next question. Suppose I just want to iterate over the list, nothing
> else. (This is actually the only case I have found myself in.) Suppose I get
> this list from an lvalue. The compiler won’t let me use ly_scm_list (lvalue).
> Is there a way to use ly_scm_list nevertheless and not as_ly_scm_list in
> order not to put the reader in a mode where they look for in-place
> modifications of the SCM lvalue?
Readers will know that you are just iterating if you use a range-based for loop.
If the variable declaration is a reference, assignment modifies the current
list element (and readers will be expecting it).
// set! all elements of the_list to #f
if (SCM &s : as_ly_scm_list (the_list))
s = SCM_BOOL_F;
If the variable declaration is a value, then it is a copy of the current list
element, which can't be used to change the element.
if (SCM s : as_ly_scm_list (the_list))
{
// s is read, but probably not assigned to.
// If s is assigned to, it doesn't change the_list.
}
However, if s above refers to a smob, the smob can still be modified via s even
though the_list cannot. For a homogeneous list of smobs, we can hamper that;
for example,
if (const auto *col : as_ly_smob_list<Paper_column> (the_list))
...
> Is there a way to use ly_scm_list ...
I am aware that I haven't actually answered this question.
—
Dan