Hi guys, I was writing some code yesterday that had to programmatically set docstrings, and it seemed to me that it was entirely redundant to maintain a distinction between object properties and procedure properties.
Let's compare the API found at (info "(guile) Procedure Properties") and th one at (info "(guile) Object Properties"). * Procedure Properties -- Scheme Procedure: procedure-name proc -- C Function: scm_procedure_name (proc) -- Scheme Procedure: procedure-source proc -- C Function: scm_procedure_source (proc) -- Scheme Procedure: procedure-properties proc -- C Function: scm_procedure_properties (proc) -- Scheme Procedure: procedure-property proc key -- C Function: scm_procedure_property (proc, key) -- Scheme Procedure: set-procedure-properties! proc alist -- C Function: scm_set_procedure_properties_x (proc, alist) -- Scheme Procedure: set-procedure-property! proc key value -- C Function: scm_set_procedure_property_x (proc, key, value) -- Scheme Procedure: procedure-documentation proc -- C Function: scm_procedure_documentation (proc) * Object Properties -- Scheme Procedure: make-object-property -- Scheme Procedure: object-properties obj -- C Function: scm_object_properties (obj) -- Scheme Procedure: set-object-properties! obj alist -- C Function: scm_set_object_properties_x (obj, alist) -- Scheme Procedure: object-property obj key -- C Function: scm_object_property (obj, key) -- Scheme Procedure: set-object-property! obj key value -- C Function: scm_set_object_property_x (obj, key, value) You'll notice that they have 4 very similar procedures. In the first set, you also have a few predefined object properties, and in the latter, a schemier interface in (make-object-property)[0]. Since procedures _are_ objects, it makes no sense for them to have separate but equal procedures. scheme@(guile-user)> (define (foo x) "some docs" x) scheme@(guile-user)> (procedure-documentation foo) $1 = "some docs" scheme@(guile-user)> ,use (ice-9 documentation) scheme@(guile-user)> (object-documentation foo) $2 = "some docs" scheme@(guile-user)> (procedure-properties foo) $3 = ((name . foo) (documentation . "some docs")) scheme@(guile-user)> (object-properties foo) $4 = () What I would like for us to do is, make the old procedure-* variants into aliases (or wrappers, if we wish to preserve the argument checking) for the object-* versions, and mark them as deprecated. We could even go further and mark the alist style properties deprecated, since we already call it legacy in the object-properties section of manual in favour of (make-object-property), but unification is better than nothing, and this way provides no loss of functionality. There are two implementation concerns. One is that procedure meta data is in some sense special, since we embed the property alist of a procedure in the tree-il representation, and this may be cheaper (I haven't measured) than the cost of the weak hash table access for object properties. The other is that the semantics of weak hash tables for object properties might be undesirable. Mark Weaver gave the following example on IRC <mark_weaver> (define foo (make-object-property))n <mark_weaver> (set! (foo 'blahblah) 1) <mark_weaver> (foo 'blahblah) => 1 <mark_weaver> (gc) (foo 'blahblah) => #f I think if we want to treat procedure properties special _under the hood_, that's fine, but there's no reason to treat it special at the scheme level. WDYT? (I've also attached a quick patch documenting the behaviour of object properties when an object doesn't have a particular property) 0. For docstrings on general objects, we have object-documentation in (ice-9 documentation) too, but that's a separate module, so I'm not counting it. -- Ian Price -- shift-reset.com "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled"
>From 92e01ab352f158b59300b1ab68b6e0069b3667f1 Mon Sep 17 00:00:00 2001 From: Ian Price <ianpric...@googlemail.com> Date: Sun, 8 Sep 2013 09:02:46 +0100 Subject: [PATCH] doc: Object properties return #f when property missing. * doc/ref/api-utility.texi (Object Properties): Mention default value in `make-object-property' and 'object-property'. --- doc/ref/api-utility.texi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/ref/api-utility.texi b/doc/ref/api-utility.texi index 76c50b2..cf9654a 100644 --- a/doc/ref/api-utility.texi +++ b/doc/ref/api-utility.texi @@ -215,7 +215,8 @@ Create and return an object property. An object property is a procedure-with-setter that can be called in two ways. @code{(set! (@var{property} @var{obj}) @var{val})} sets @var{obj}'s @var{property} to @var{val}. @code{(@var{property} @var{obj})} returns the current -setting of @var{obj}'s @var{property}. +setting of @var{obj}'s @var{property}, defaulting to @code{#f} if none +has been set. @end deffn A single object property created by @code{make-object-property} can @@ -246,7 +247,8 @@ Set @var{obj}'s property list to @var{alist}. @deffn {Scheme Procedure} object-property obj key @deffnx {C Function} scm_object_property (obj, key) -Return the property of @var{obj} with name @var{key}. +Return the property of @var{obj} with name @var{key}, or @code{#f} if +@var{obj} does not have that property. @end deffn @deffn {Scheme Procedure} set-object-property! obj key value -- 1.7.11.7