* A question about cycle-spacing--context
@ 2015-01-25 23:28 Marcin Borkowski
2015-01-26 0:38 ` Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-01-25 23:28 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hello Emacsers,
as I mentioned elsewhere, I'm studying simple.el (whose name I consider
a bit, hm, ironic;-)). Here's what I found in the definition of
cycle-spacing:
(cons n (cons orig-pos (buffer-substring start (point))))
Is there any particular reason for using this instead of just
(list n orig-pos (buffer-substring start (point)))?
(Of course, the results are formally different, but functionally the
same, and in the current implementation, thus defined
cycle-spacing--context is not even a "proper", nil-terminated list!)
I understand that the current implementation saves memory (but taking
into account that there is one instance of cycle-spacing--context per
Emacs instance (!), this is negligible). I guess it *might* improve
performance - but again, this is an interactive command clearly not
intended for non-interactive use, so saving a microsecond or two (and
I guess much less in reality) is not really a gain. OTOH, we pay for
this with less readable code.
So, my question is: (1) why is that so and (2) would it be a good
practice to employ such an idea in my own code? (I suppose the answers
are (1) why not? and (2) no, but I'd like to ask anyway.)
Also, this is yet another time I see a symbol with two consecutive
dashes. This might be a naive question, but is there any convention
used here that I do not know of?
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: A question about cycle-spacing--context
2015-01-25 23:28 A question about cycle-spacing--context Marcin Borkowski
@ 2015-01-26 0:38 ` Drew Adams
2015-01-26 1:48 ` Artur Malabarba
0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2015-01-26 0:38 UTC (permalink / raw)
To: Marcin Borkowski, Help Gnu Emacs mailing list
> Here's what I found in the definition of cycle-spacing:
> (cons n (cons orig-pos (buffer-substring start (point))))
> Is there any particular reason for using this instead of just
> (list n orig-pos (buffer-substring start (point)))?
No, not that I can see.
> (Of course, the results are formally different, but functionally
> the same, and in the current implementation, thus defined
> cycle-spacing--context is not even a "proper", nil-terminated
> list!) I understand that the current implementation saves memory
> So, my question is: (1) why is that so and (2) would it be a good
> practice to employ such an idea in my own code? (I suppose the
> answers are (1) why not? and (2) no, but I'd like to ask anyway.)
I think you are asking whether and when it makes sense to use
dotted lists in your own code. If so, the answer lies in what you
use the possibly dotted list for.
If you expect to be able to use list operations (e.g. `mapcar')
on it then the answer is generally no. If you are using it as
a simple, large (many conses) alist, especially one that is
created anew often, then the answer might be "Why not?"
The answer is to look at how it is being used in your code and
judge whether it is convenient or inconvenient etc.
FWIW, I probably would not have bothered to use a dotted list
in this case. But there is nothing really wrong with doing so.
For clarity, I'd say start by using proper lists, and change
to a dotted list here or there if you find a good reason to
do so.
> Also, this is yet another time I see a symbol with two consecutive
> dashes. This might be a naive question, but is there any convention
> used here that I do not know of?
Some of the Emacs developers like to use `--' to indicate an
"internal" function, variable or whatever, by which is meant only
that its implementation is not guaranteed not to change (which is
anyway true of any function, var or whatever!). You can take it
as a hint that if you write code that uses such an "internal"
thingy then you are on your own if and when an Emacs release
changes its use or behavior.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: A question about cycle-spacing--context
2015-01-26 0:38 ` Drew Adams
@ 2015-01-26 1:48 ` Artur Malabarba
2015-01-26 3:10 ` Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Artur Malabarba @ 2015-01-26 1:48 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs, Marcin Borkowski
> Some of the Emacs developers like to use `--' to indicate an
As of 24.4, this is also the official recommended style. At least, (I
think) that's what it said in the news file.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: A question about cycle-spacing--context
2015-01-26 1:48 ` Artur Malabarba
@ 2015-01-26 3:10 ` Drew Adams
0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2015-01-26 3:10 UTC (permalink / raw)
To: Artur Malabarba; +Cc: help-gnu-emacs, Marcin Borkowski
> > Some of the Emacs developers like to use `--' to indicate an
>
> As of 24.4, this is also the official recommended style.
> At least, (I think) that's what it said in the news file.
Same difference. ;-) See what I wrote about what "internal" means
for something like Emacs:
its implementation is not guaranteed not to change
(which is anyway true of any function, var or whatever!).
IOW, much ado about little or nothing. Just one opinion, of course.
(BTW, I see nothing in NEWS about this, by searching for "--"
or "[Ii]nternal". The only thing mentioned is that for `cl-lib'
the "internal definitions use the 'cl--' prefix" - and that is
mentioned for Emacs 24.3, not 24.4.)
Personally, I do use the same convention occasionally, but
usually to remind *myself* that the thing in question is
something whose implementation I probably do *not* want to
change lightly. IOW, in my case it is for the code developer,
not for someone using the code, and it just reminds me that
this stuff is essentially "plumbing".
(BTW2: In a `simple.el' name such as
`repeat-complex-command--called-interactively-skip' (gotta
love that one), added for Emacs 24.4 and removed since, one
wonders whether the `--' might have been introduced less
because the thing was considered internal and more just to
visually separate the `repeat-complex-command' prefix from
the rest of the name, IOW, as a kind of compensation.)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-26 3:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-25 23:28 A question about cycle-spacing--context Marcin Borkowski
2015-01-26 0:38 ` Drew Adams
2015-01-26 1:48 ` Artur Malabarba
2015-01-26 3:10 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).