* Property list key names
@ 2008-08-09 13:56 Lennart Borgman (gmail)
2008-08-09 14:52 ` Juanma Barranquero
0 siblings, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 13:56 UTC (permalink / raw)
To: Emacs Devel
I guess there is something like this function in Emacs:
(defun property-list-keys (plist)
"Return list of key names in property list PLIST."
(let ((keys)
(plist (copy-list plist)))
(while plist
(setq keys (cons (car plist) keys))
(setq plist (cddr plist)))
keys))
What is the name of it?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 13:56 Property list key names Lennart Borgman (gmail)
@ 2008-08-09 14:52 ` Juanma Barranquero
2008-08-09 15:02 ` Lennart Borgman (gmail)
2008-08-09 15:08 ` Johan Bockgård
0 siblings, 2 replies; 16+ messages in thread
From: Juanma Barranquero @ 2008-08-09 14:52 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Emacs Devel
On Sat, Aug 9, 2008 at 15:56, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> I guess there is something like this function in Emacs:
I don't think there's one...
> (defun property-list-keys (plist)
> "Return list of key names in property list PLIST."
> (let ((keys)
> (plist (copy-list plist)))
Why do you copy plist?
> (while plist
> (setq keys (cons (car plist) keys))
> (setq plist (cddr plist)))
> keys))
> What is the name of it?
It's easy enough to implement, and not much needed (apparently).
If you're using CL, you can get fancy
(defun property-list-keys (plist)
(let ((c 0))
(remove-if #'(lambda (ignore) (zerop (mod (incf c) 2))) plist)))
(not that it is better or clearer than your version, of course ;-)
Juanma
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 14:52 ` Juanma Barranquero
@ 2008-08-09 15:02 ` Lennart Borgman (gmail)
2008-08-09 15:07 ` Juanma Barranquero
2008-08-09 15:08 ` Johan Bockgård
1 sibling, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 15:02 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Emacs Devel
Juanma Barranquero wrote:
> On Sat, Aug 9, 2008 at 15:56, Lennart Borgman (gmail)
> <lennart.borgman@gmail.com> wrote:
>
>> I guess there is something like this function in Emacs:
>
> I don't think there's one...
>
>> (defun property-list-keys (plist)
>> "Return list of key names in property list PLIST."
>> (let ((keys)
>> (plist (copy-list plist)))
>
> Why do you copy plist?
Just a mistake.
>> (while plist
>> (setq keys (cons (car plist) keys))
>> (setq plist (cddr plist)))
>> keys))
>
>> What is the name of it?
>
> It's easy enough to implement, and not much needed (apparently).
Ok, thanks.
> If you're using CL, you can get fancy
>
> (defun property-list-keys (plist)
> (let ((c 0))
> (remove-if #'(lambda (ignore) (zerop (mod (incf c) 2))) plist)))
>
> (not that it is better or clearer than your version, of course ;-)
But I learned something ;-)
> Juanma
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 15:02 ` Lennart Borgman (gmail)
@ 2008-08-09 15:07 ` Juanma Barranquero
2008-08-09 15:11 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 16+ messages in thread
From: Juanma Barranquero @ 2008-08-09 15:07 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Emacs Devel
On Sat, Aug 9, 2008 at 17:02, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> But I learned something ;-)
Yes. That I am an idiot...
(defun property-list-keys (plist)
(let ((c 0))
(remove-if #'(lambda (ignore) (evenp (incf c))) plist)))
Much simpler.
BTW, the only "advantage" of my version is that the keys are returned in order.
Juanma
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 14:52 ` Juanma Barranquero
2008-08-09 15:02 ` Lennart Borgman (gmail)
@ 2008-08-09 15:08 ` Johan Bockgård
2008-08-09 15:15 ` Juanma Barranquero
1 sibling, 1 reply; 16+ messages in thread
From: Johan Bockgård @ 2008-08-09 15:08 UTC (permalink / raw)
To: emacs-devel
"Juanma Barranquero" <lekktu@gmail.com> writes:
> If you're using CL, you can get fancy
(loop for x in plist by 'cddr
collect x)
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 15:07 ` Juanma Barranquero
@ 2008-08-09 15:11 ` Lennart Borgman (gmail)
2008-08-09 15:16 ` Juanma Barranquero
0 siblings, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 15:11 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Emacs Devel
Juanma Barranquero wrote:
> On Sat, Aug 9, 2008 at 17:02, Lennart Borgman (gmail)
> <lennart.borgman@gmail.com> wrote:
>
>> But I learned something ;-)
>
> Yes. That I am an idiot...
Oh, sorry, I missed that ;-)
> (defun property-list-keys (plist)
> (let ((c 0))
> (remove-if #'(lambda (ignore) (evenp (incf c))) plist)))
>
> Much simpler.
>
> BTW, the only "advantage" of my version is that the keys are returned in order.
What I am trying to do is finding different CL symbol definitions. I do
not know CL at all and it is quite frustrating trying to find the
definition sources. (Though I am beginning to understand defstruct etc now.)
Is there already some library for that?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 15:08 ` Johan Bockgård
@ 2008-08-09 15:15 ` Juanma Barranquero
0 siblings, 0 replies; 16+ messages in thread
From: Juanma Barranquero @ 2008-08-09 15:15 UTC (permalink / raw)
To: emacs-devel
On Sat, Aug 9, 2008 at 17:08, Johan Bockgård
<bojohan+news@dd.chalmers.se> wrote:
> (loop for x in plist by 'cddr
> collect x)
Yes, of course. I tend not to use `loop' because of code formatting
issues, but certainly you can do everything with it :-)
Juanma
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 15:11 ` Lennart Borgman (gmail)
@ 2008-08-09 15:16 ` Juanma Barranquero
2008-08-09 16:17 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 16+ messages in thread
From: Juanma Barranquero @ 2008-08-09 15:16 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Emacs Devel
On Sat, Aug 9, 2008 at 17:11, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> What I am trying to do is finding different CL symbol definitions. I do not
> know CL at all and it is quite frustrating trying to find the definition
> sources. (Though I am beginning to understand defstruct etc now.)
I do not understand.
Juanma
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 15:16 ` Juanma Barranquero
@ 2008-08-09 16:17 ` Lennart Borgman (gmail)
2008-08-09 16:58 ` Johan Bockgård
0 siblings, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 16:17 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Emacs Devel
Juanma Barranquero wrote:
> On Sat, Aug 9, 2008 at 17:11, Lennart Borgman (gmail)
> <lennart.borgman@gmail.com> wrote:
>
>> What I am trying to do is finding different CL symbol definitions. I do not
>> know CL at all and it is quite frustrating trying to find the definition
>> sources. (Though I am beginning to understand defstruct etc now.)
>
> I do not understand.
If there for example is something like this
(defstruct ert-stats
(selector (assert nil)))
then a defstruct selector function `ert-stats-selector' is defined. It
would be nice to go to that function directly from the link in
`describe-function', but currently the position in the file is not found.
And there is no information at all provided by describe-function that it
is made by defstruct. Wouldn't it be nice if the CL library added that
information? I am not very fond of that CL black box game.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 16:17 ` Lennart Borgman (gmail)
@ 2008-08-09 16:58 ` Johan Bockgård
2008-08-09 17:18 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 16+ messages in thread
From: Johan Bockgård @ 2008-08-09 16:58 UTC (permalink / raw)
To: emacs-devel
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> If there for example is something like this
>
> (defstruct ert-stats
> (selector (assert nil)))
>
> then a defstruct selector function `ert-stats-selector' is defined. It
> would be nice to go to that function directly from the link in
> describe-function', but currently the position in the file is not
> found.
Indeed, defstruct should put a `definition-name' property on the names
it constructs. Like
(put 'ert-stats-selector 'definition-name 'ert-stats)
--
Johan Bockgård
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 16:58 ` Johan Bockgård
@ 2008-08-09 17:18 ` Lennart Borgman (gmail)
2008-08-09 17:20 ` Lennart Borgman (gmail)
2008-08-09 17:33 ` Johan Bockgård
0 siblings, 2 replies; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 17:18 UTC (permalink / raw)
To: emacs-devel
Johan Bockgård wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> If there for example is something like this
>>
>> (defstruct ert-stats
>> (selector (assert nil)))
>>
>> then a defstruct selector function `ert-stats-selector' is defined. It
>> would be nice to go to that function directly from the link in
>> describe-function', but currently the position in the file is not
>> found.
>
> Indeed, defstruct should put a `definition-name' property on the names
> it constructs. Like
>
> (put 'ert-stats-selector 'definition-name 'ert-stats)
Yes, something like that. Is 'definition-name special in some way or
could/should it be something else?
Beside that `ert-stats' does not get any information about where it is
defined. Is there any reason not to add that information, either to
load-history (preffered) or to the symbol itself?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 17:18 ` Lennart Borgman (gmail)
@ 2008-08-09 17:20 ` Lennart Borgman (gmail)
2008-08-09 17:33 ` Johan Bockgård
1 sibling, 0 replies; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 17:20 UTC (permalink / raw)
To: emacs-devel
Lennart Borgman (gmail) wrote:
> Beside that `ert-stats' does not get any information about where it is
> defined. Is there any reason not to add that information, either to
> load-history (preffered) or to the symbol itself?
And should not `defmacro' be responsible for this?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 17:18 ` Lennart Borgman (gmail)
2008-08-09 17:20 ` Lennart Borgman (gmail)
@ 2008-08-09 17:33 ` Johan Bockgård
2008-08-09 18:18 ` Lennart Borgman (gmail)
1 sibling, 1 reply; 16+ messages in thread
From: Johan Bockgård @ 2008-08-09 17:33 UTC (permalink / raw)
To: emacs-devel
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> Johan Bockgård wrote:
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>
>>> If there for example is something like this
>>>
>>> (defstruct ert-stats
>>> (selector (assert nil)))
>>>
>>> then a defstruct selector function `ert-stats-selector' is defined. It
>>> would be nice to go to that function directly from the link in
>>> describe-function', but currently the position in the file is not
>>> found.
>>
>> Indeed, defstruct should put a `definition-name' property on the names
>> it constructs. Like
>>
>> (put 'ert-stats-selector 'definition-name 'ert-stats)
>
> Yes, something like that. Is 'definition-name special in some way or
> could/should it be something else?
Try C-h f again after adding the property above.
--
Johan Bockgård
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 17:33 ` Johan Bockgård
@ 2008-08-09 18:18 ` Lennart Borgman (gmail)
2008-08-09 18:52 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 18:18 UTC (permalink / raw)
To: emacs-devel
Johan Bockgård wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> Johan Bockgård wrote:
>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>
>>>> If there for example is something like this
>>>>
>>>> (defstruct ert-stats
>>>> (selector (assert nil)))
>>>>
>>>> then a defstruct selector function `ert-stats-selector' is defined. It
>>>> would be nice to go to that function directly from the link in
>>>> describe-function', but currently the position in the file is not
>>>> found.
>>> Indeed, defstruct should put a `definition-name' property on the names
>>> it constructs. Like
>>>
>>> (put 'ert-stats-selector 'definition-name 'ert-stats)
>> Yes, something like that. Is 'definition-name special in some way or
>> could/should it be something else?
>
> Try C-h f again after adding the property above.
Hey, that is the black box game again ... ;-)
Yes, you are right, but I do not understand how it works. I guess C-h f
searches the buffer for the "definition-name".
So this looks like more or less a bug.
I tried to look at defstruct to see where to add 'definition-name. There
seems to be 4 uses of `defun' and `defsubst*'. Should not all this 4 be
adding 'definition-name?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 18:18 ` Lennart Borgman (gmail)
@ 2008-08-09 18:52 ` Lennart Borgman (gmail)
2008-08-09 18:54 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 18:52 UTC (permalink / raw)
To: emacs-devel
Lennart Borgman (gmail) wrote:
> Johan Bockgård wrote:
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>
>>> Johan Bockgård wrote:
>>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>>
>>>>> If there for example is something like this
>>>>>
>>>>> (defstruct ert-stats
>>>>> (selector (assert nil)))
>>>>>
>>>>> then a defstruct selector function `ert-stats-selector' is defined. It
>>>>> would be nice to go to that function directly from the link in
>>>>> describe-function', but currently the position in the file is not
>>>>> found.
>>>> Indeed, defstruct should put a `definition-name' property on the names
>>>> it constructs. Like
>>>>
>>>> (put 'ert-stats-selector 'definition-name 'ert-stats)
>>> Yes, something like that. Is 'definition-name special in some way or
>>> could/should it be something else?
>>
>> Try C-h f again after adding the property above.
>
> Hey, that is the black box game again ... ;-)
>
> Yes, you are right, but I do not understand how it works. I guess C-h f
> searches the buffer for the "definition-name".
>
> So this looks like more or less a bug.
>
> I tried to look at defstruct to see where to add 'definition-name. There
> seems to be 4 uses of `defun' and `defsubst*'. Should not all this 4 be
> adding 'definition-name?
Here is a patch for that. Should be wrapped a bit, but it is easier
seeing what I have done if it is like this. Should the (put ...
'definition-name ...) be before or after the defmacro* and defun in the
code?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Property list key names
2008-08-09 18:52 ` Lennart Borgman (gmail)
@ 2008-08-09 18:54 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 16+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-09 18:54 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]
Lennart Borgman (gmail) wrote:
> Lennart Borgman (gmail) wrote:
>> Johan Bockgård wrote:
>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>
>>>> Johan Bockgård wrote:
>>>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>>>
>>>>>> If there for example is something like this
>>>>>>
>>>>>> (defstruct ert-stats
>>>>>> (selector (assert nil)))
>>>>>>
>>>>>> then a defstruct selector function `ert-stats-selector' is
>>>>>> defined. It
>>>>>> would be nice to go to that function directly from the link in
>>>>>> describe-function', but currently the position in the file is not
>>>>>> found.
>>>>> Indeed, defstruct should put a `definition-name' property on the names
>>>>> it constructs. Like
>>>>>
>>>>> (put 'ert-stats-selector 'definition-name 'ert-stats)
>>>> Yes, something like that. Is 'definition-name special in some way or
>>>> could/should it be something else?
>>>
>>> Try C-h f again after adding the property above.
>>
>> Hey, that is the black box game again ... ;-)
>>
>> Yes, you are right, but I do not understand how it works. I guess C-h
>> f searches the buffer for the "definition-name".
>>
>> So this looks like more or less a bug.
>>
>> I tried to look at defstruct to see where to add 'definition-name.
>> There seems to be 4 uses of `defun' and `defsubst*'. Should not all
>> this 4 be adding 'definition-name?
>
>
> Here is a patch for that. Should be wrapped a bit, but it is easier
> seeing what I have done if it is like this. Should the (put ...
> 'definition-name ...) be before or after the defmacro* and defun in the
> code?
Sorry, attached the patch.
[-- Attachment #2: cl-macs-definition-name.diff --]
[-- Type: text/plain, Size: 1745 bytes --]
Index: cl-macs.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/cl-macs.el,v
retrieving revision 1.76
diff -u -r1.76 cl-macs.el
--- cl-macs.el 16 Jul 2008 02:50:00 -0000 1.76
+++ cl-macs.el 9 Aug 2008 18:44:42 -0000
@@ -2328,6 +2328,7 @@
(list (if (eq type 'vector) (list 'aref 'cl-x pos)
(if (= pos 0) '(car cl-x)
(list 'nth pos 'cl-x)))))) forms)
+ (push (list 'put (list 'quote accessor) (list 'quote 'definition-name) (list 'quote struct)) forms)
(push (cons accessor t) side-eff)
(push (list 'define-setf-method accessor '(cl-x)
(if (cadr (memq :read-only (cddr desc)))
@@ -2355,9 +2356,11 @@
(if (eq (car pred-form) 'and)
(append pred-form '(t))
(list 'and pred-form t))) forms)
+ (push (list 'put (list 'quote predicate) (list 'quote 'definition-name) (list 'quote struct)) forms)
(push (cons predicate 'error-free) side-eff)))
(and copier
(progn (push (list 'defun copier '(x) '(copy-sequence x)) forms)
+ (push (list 'put (list 'quote copier) (list 'quote 'definition-name) (list 'quote struct)) forms)
(push (cons copier t) side-eff)))
(if constructor
(push (list constructor
@@ -2372,6 +2375,7 @@
(push (list 'defsubst* name
(list* '&cl-defs (list 'quote (cons nil descs)) args)
(cons type make)) forms)
+ (push (list 'put (list 'quote name) (list 'quote 'definition-name) (list 'quote struct)) forms)
(if (cl-safe-expr-p (cons 'progn (mapcar 'second descs)))
(push (cons name t) side-eff))))
(if print-auto (nconc print-func (list '(princ ")" cl-s) t)))
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2008-08-09 18:54 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-09 13:56 Property list key names Lennart Borgman (gmail)
2008-08-09 14:52 ` Juanma Barranquero
2008-08-09 15:02 ` Lennart Borgman (gmail)
2008-08-09 15:07 ` Juanma Barranquero
2008-08-09 15:11 ` Lennart Borgman (gmail)
2008-08-09 15:16 ` Juanma Barranquero
2008-08-09 16:17 ` Lennart Borgman (gmail)
2008-08-09 16:58 ` Johan Bockgård
2008-08-09 17:18 ` Lennart Borgman (gmail)
2008-08-09 17:20 ` Lennart Borgman (gmail)
2008-08-09 17:33 ` Johan Bockgård
2008-08-09 18:18 ` Lennart Borgman (gmail)
2008-08-09 18:52 ` Lennart Borgman (gmail)
2008-08-09 18:54 ` Lennart Borgman (gmail)
2008-08-09 15:08 ` Johan Bockgård
2008-08-09 15:15 ` Juanma Barranquero
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.