unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Custom printers for SRFI-9 records
@ 2010-05-25  0:26 No Itisnt
  2010-05-25 19:23 ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: No Itisnt @ 2010-05-25  0:26 UTC (permalink / raw)
  To: guile-devel

One thing I'm missing, and maybe I just didn't see it, is a way to
define custom printers for SRFI-9 records.

(define-syntax define-record-printer
  (syntax-rules ()
    ((_ name thunk)
     (struct-set! name vtable-index-printer thunk))))

Does something like that already exist? If not, 1) do yall think it's
a good idea? 2) where should it go?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-25  0:26 Custom printers for SRFI-9 records No Itisnt
@ 2010-05-25 19:23 ` Ludovic Courtès
       [not found]   ` <AANLkTilzb959cEaRDcpFUntPK_r0q_9RsIE5pByG4QPm@mail.gmail.com>
  0 siblings, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2010-05-25 19:23 UTC (permalink / raw)
  To: guile-devel

Hello!

No Itisnt <theseaisinhere@gmail.com> writes:

> One thing I'm missing, and maybe I just didn't see it, is a way to
> define custom printers for SRFI-9 records.

I agree that it’s generally useful, but I think SRFI modules should not
diverge from the spec, or when they do, make it separate, as was done
with (srfi srfi-4 gnu).

What do you think?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
       [not found]   ` <AANLkTilzb959cEaRDcpFUntPK_r0q_9RsIE5pByG4QPm@mail.gmail.com>
@ 2010-05-26  4:18     ` No Itisnt
  2010-05-26 21:09       ` No Itisnt
  2010-05-26 22:34       ` Ludovic Courtès
  0 siblings, 2 replies; 9+ messages in thread
From: No Itisnt @ 2010-05-26  4:18 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

On Tue, May 25, 2010 at 3:56 PM, No Itisnt <theseaisinhere@gmail.com> wrote:
> I agree. Here's a patch that adds (srfi srfi-9 gnu) with
> set-record-printer! and adds a subsection to the SRFI-9 part of the
> manual for it.
> I can go ahead and commit it, if that's OK.
>
> On Tue, May 25, 2010 at 2:23 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>> Hello!
>>
>> No Itisnt <theseaisinhere@gmail.com> writes:
>>
>>> One thing I'm missing, and maybe I just didn't see it, is a way to
>>> define custom printers for SRFI-9 records.
>>
>> I agree that it’s generally useful, but I think SRFI modules should not
>> diverge from the spec, or when they do, make it separate, as was done
>> with (srfi srfi-4 gnu).
>>
>> What do you think?
>>
>> Thanks,
>> Ludo’.
>>
>>
>>
>

[-- Attachment #2: define-record-printer.patch --]
[-- Type: application/octet-stream, Size: 2631 bytes --]

diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 0d192fa..b3f9946 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -1922,6 +1922,35 @@ The functions created by @code{define-record-type} are ordinary
 top-level @code{define}s.  They can be redefined or @code{set!} as
 desired, exported from a module, etc.
 
+@menu
+* SRFI-9 Custom printers::      Customizing print behavior.
+@end menu
+
+@node SRFI-9 Custom printers
+@subsubsection Custom printers
+@cindex record printer
+
+You may use @code{set-record-printer!} to customize the default printing
+behavior of records. This is a GUILE extension and is not part of SRFI-9. It is
+located in the @nicode{(srfi srfi-9 gnu)} module.
+
+@deffn {library syntax} set-record-printer! name thunk
+Where @var{type} corresponds to the first argument of @code{define-record-type},
+and @var{thunk} is a procedure accepting two arguments, the record to print, and
+an output port.
+
+@end deffn
+
+@noindent
+This example prints the employee's name in brackets, for instance ``@code{[Fred]}''.
+
+@example
+(set-record-printer! employee-type
+  (lambda (record port)
+    (write-char #\[ port)
+    (display (get-employee-name record) port)
+    (write-char #\] port)))
+@end example
 
 @node SRFI-10
 @subsection SRFI-10 - Hash-Comma Reader Extension
diff --git a/module/srfi/srfi-9/gnu.scm b/module/srfi/srfi-9/gnu.scm
new file mode 100644
index 0000000..3a37471
--- /dev/null
+++ b/module/srfi/srfi-9/gnu.scm
@@ -0,0 +1,29 @@
+;;; Extensions to SRFI-9
+
+;; 	Copyright (C) 2010 Free Software Foundation, Inc.
+;;
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 3 of the License, or (at your option) any later version.
+;; 
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; Lesser General Public License for more details.
+;; 
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+;;; Commentary:
+
+;; Extensions to SRFI-9. Fully documented in the Guile Reference Manual.
+
+;;; Code:
+
+(define-module (srfi srfi-9 gnu)
+  #:export (set-record-printer!))
+
+(define (set-record-printer! type thunk)
+  (struct-set! type vtable-index-printer thunk))

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-26  4:18     ` No Itisnt
@ 2010-05-26 21:09       ` No Itisnt
  2010-05-26 22:04         ` Ludovic Courtès
  2010-05-26 22:42         ` Ludovic Courtès
  2010-05-26 22:34       ` Ludovic Courtès
  1 sibling, 2 replies; 9+ messages in thread
From: No Itisnt @ 2010-05-26 21:09 UTC (permalink / raw)
  To: guile-devel

Whoops ! Due to my misunderstanding of 'git push' I committed this to
master. I had already committed it to master locally so after I merge
it, I guess it pushed my master changes as well when I was trying to
push my lua branch.  Hopefully I didn't mess up anything else. I read
the docs now so it won't happen again.

On Tue, May 25, 2010 at 11:18 PM, No Itisnt <theseaisinhere@gmail.com> wrote:
> On Tue, May 25, 2010 at 3:56 PM, No Itisnt <theseaisinhere@gmail.com> wrote:
>> I agree. Here's a patch that adds (srfi srfi-9 gnu) with
>> set-record-printer! and adds a subsection to the SRFI-9 part of the
>> manual for it.
>> I can go ahead and commit it, if that's OK.
>>
>> On Tue, May 25, 2010 at 2:23 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>>> Hello!
>>>
>>> No Itisnt <theseaisinhere@gmail.com> writes:
>>>
>>>> One thing I'm missing, and maybe I just didn't see it, is a way to
>>>> define custom printers for SRFI-9 records.
>>>
>>> I agree that it’s generally useful, but I think SRFI modules should not
>>> diverge from the spec, or when they do, make it separate, as was done
>>> with (srfi srfi-4 gnu).
>>>
>>> What do you think?
>>>
>>> Thanks,
>>> Ludo’.
>>>
>>>
>>>
>>
>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-26 21:09       ` No Itisnt
@ 2010-05-26 22:04         ` Ludovic Courtès
  2010-05-26 22:42         ` Ludovic Courtès
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2010-05-26 22:04 UTC (permalink / raw)
  To: guile-devel

Hi!

No Itisnt <theseaisinhere@gmail.com> writes:

> Whoops ! Due to my misunderstanding of 'git push' I committed this to
> master. I had already committed it to master locally so after I merge
> it, I guess it pushed my master changes as well when I was trying to
> push my lua branch.

I pushed changes after you pushed your merge commit, so we’ll leave it
here and commit changes depending on the outcome of our discussions.

Git can sometimes be confusing.  There are commands like this for which
I’ve always checked the man page before hitting RET.  ;-)

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-26  4:18     ` No Itisnt
  2010-05-26 21:09       ` No Itisnt
@ 2010-05-26 22:34       ` Ludovic Courtès
  2010-05-27  2:41         ` No Itisnt
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2010-05-26 22:34 UTC (permalink / raw)
  To: guile-devel

Hi,

No Itisnt <theseaisinhere@gmail.com> writes:

> On Tue, May 25, 2010 at 3:56 PM, No Itisnt <theseaisinhere@gmail.com> wrote:
>> I agree. Here's a patch that adds (srfi srfi-9 gnu) with
>> set-record-printer! and adds a subsection to the SRFI-9 part of the
>> manual for it.
>> I can go ahead and commit it, if that's OK.

This looks good to me.

> diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
> index 0d192fa..b3f9946 100644
> --- a/doc/ref/srfi-modules.texi
> +++ b/doc/ref/srfi-modules.texi
> @@ -1922,6 +1922,35 @@ The functions created by @code{define-record-type} are ordinary
>  top-level @code{define}s.  They can be redefined or @code{set!} as
>  desired, exported from a module, etc.
>  
> +@menu
> +* SRFI-9 Custom printers::      Customizing print behavior.
> +@end menu
> +
> +@node SRFI-9 Custom printers
> +@subsubsection Custom printers

Use @unnumberedsubsubsec instead and no menu.  Capitalize like this:
“SRFI-9 Custom Printers”.

> +You may use @code{set-record-printer!} to customize the default printing
> +behavior of records. This is a GUILE extension and is not part of SRFI-9. It is

s/GUILE/Guile/ and two spaces after and end-of-sentence period.

> +located in the @nicode{(srfi srfi-9 gnu)} module.
> +
> +@deffn {library syntax} set-record-printer! name thunk

Rather use @deffn{Scheme Syntax}, which seems to be the most commonly
used form in the manual.

> +This example prints the employee's name in brackets, for instance ``@code{[Fred]}''.

No need for ``quotes'' here.

> +(define (set-record-printer! type thunk)
> +  (struct-set! type vtable-index-printer thunk))

I’d rather call it ‘set-record-type-printer!’ (it prints records, but
it’s the printer of the record type).  What do you think?

You could add a docstring here.

And don’t forget to add srfi-9/gnu.scm to ‘SRFI_SOURCES’ in
modules/Makefile.am.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-26 21:09       ` No Itisnt
  2010-05-26 22:04         ` Ludovic Courtès
@ 2010-05-26 22:42         ` Ludovic Courtès
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2010-05-26 22:42 UTC (permalink / raw)
  To: guile-devel

BTW, you should always create a local branch when working on something,
even if it may eventually be committed to ‘master’.  The reason is that
something else may be pushed before your commit, and if you just run
‘git push’ after that, we’ll end up with a merge commit, which we’d
rather avoid.

So the workflow would be:

  $ git branch wip-foo
  $ git checkout wip-foo
  # hack...
  $ git commit ...

  # Check whether something was pushed.
  $ git checkout master
  $ git pull

  # if “already up-to-date”:
  $ git merge wip-foo && git push
  # else
  $ git checkout wip-foo
  $ git rebase master
  # and try again
  # endif

Also I recommend using Magit: <http://zagadka.vm.bytemark.co.uk/magit/>
or <http://github.com/philjackson/magit>.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-26 22:34       ` Ludovic Courtès
@ 2010-05-27  2:41         ` No Itisnt
  2010-05-27  8:20           ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: No Itisnt @ 2010-05-27  2:41 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

OK.

> s/GUILE/Guile/ and two spaces after and end-of-sentence period.

How so? Two trailing spaces after the period or two newlines?
Is there a style guide somewhere? I was mainly copying and pasting
from srfi-modules.texi.

> I’d rather call it ‘set-record-type-printer!’ (it prints records, but
> it’s the printer of the record type).  What do you think?
>
> You could add a docstring here.
>
> And don’t forget to add srfi-9/gnu.scm to ‘SRFI_SOURCES’ in
> modules/Makefile.am.

Done.

[-- Attachment #2: printers.patch --]
[-- Type: application/octet-stream, Size: 2425 bytes --]

diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index b3f9946..08b11e0 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -1922,30 +1922,23 @@ The functions created by @code{define-record-type} are ordinary
 top-level @code{define}s.  They can be redefined or @code{set!} as
 desired, exported from a module, etc.
 
-@menu
-* SRFI-9 Custom printers::      Customizing print behavior.
-@end menu
+@unnumberedsubsubsec Custom Printers
 
-@node SRFI-9 Custom printers
-@subsubsection Custom printers
-@cindex record printer
-
-You may use @code{set-record-printer!} to customize the default printing
-behavior of records. This is a GUILE extension and is not part of SRFI-9. It is
+You may use @code{set-record-type-printer!} to customize the default printing
+behavior of records. This is a Guile extension and is not part of SRFI-9. It is
 located in the @nicode{(srfi srfi-9 gnu)} module.
 
-@deffn {library syntax} set-record-printer! name thunk
+@deffn {Scheme Syntax} set-record-type-printer! name thunk
 Where @var{type} corresponds to the first argument of @code{define-record-type},
 and @var{thunk} is a procedure accepting two arguments, the record to print, and
 an output port.
-
 @end deffn
 
 @noindent
-This example prints the employee's name in brackets, for instance ``@code{[Fred]}''.
+This example prints the employee's name in brackets, for instance @code{[Fred]}.
 
 @example
-(set-record-printer! employee-type
+(set-record-type-printer! employee-type
   (lambda (record port)
     (write-char #\[ port)
     (display (get-employee-name record) port)
diff --git a/module/Makefile.am b/module/Makefile.am
index 4ea8997..80376c9 100644
--- a/module/Makefile.am
+++ b/module/Makefile.am
@@ -236,6 +236,7 @@ SRFI_SOURCES = \
   srfi/srfi-6.scm \
   srfi/srfi-8.scm \
   srfi/srfi-9.scm \
+  srfi/srfi-9/gnu.scm \
   srfi/srfi-10.scm \
   srfi/srfi-11.scm \
   srfi/srfi-13.scm \
diff --git a/module/srfi/srfi-9/gnu.scm b/module/srfi/srfi-9/gnu.scm
index 3a37471..30c101b 100644
--- a/module/srfi/srfi-9/gnu.scm
+++ b/module/srfi/srfi-9/gnu.scm
@@ -23,7 +23,8 @@
 ;;; Code:
 
 (define-module (srfi srfi-9 gnu)
-  #:export (set-record-printer!))
+  #:export (set-record-type-printer!))
 
-(define (set-record-printer! type thunk)
+(define (set-record-type-printer! type thunk)
+  "Set a custom printer THUNK for TYPE."
   (struct-set! type vtable-index-printer thunk))

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: Custom printers for SRFI-9 records
  2010-05-27  2:41         ` No Itisnt
@ 2010-05-27  8:20           ` Ludovic Courtès
  0 siblings, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2010-05-27  8:20 UTC (permalink / raw)
  To: No Itisnt; +Cc: guile-devel

Hi,

No Itisnt <theseaisinhere@gmail.com> writes:

>> s/GUILE/Guile/ and two spaces after and end-of-sentence period.
>
> How so? Two trailing spaces after the period or two newlines?

Two spaces.  It’s visually the closest thing to English typography rules
as mentioned in the Texinfo manual (info "(texinfo) Ending a Sentence").
The GCS also recommends it (info "(standards) Comments"), so it’s better
if we keep following it.

Other than that the patch looks good to me so feel free to commit to
‘master’ without any merge commit, or Andy or myself can apply it, as
you prefer.

Thanks!

Ludo’.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-05-27  8:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-25  0:26 Custom printers for SRFI-9 records No Itisnt
2010-05-25 19:23 ` Ludovic Courtès
     [not found]   ` <AANLkTilzb959cEaRDcpFUntPK_r0q_9RsIE5pByG4QPm@mail.gmail.com>
2010-05-26  4:18     ` No Itisnt
2010-05-26 21:09       ` No Itisnt
2010-05-26 22:04         ` Ludovic Courtès
2010-05-26 22:42         ` Ludovic Courtès
2010-05-26 22:34       ` Ludovic Courtès
2010-05-27  2:41         ` No Itisnt
2010-05-27  8:20           ` Ludovic Courtès

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).