This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

scm_smob_print with name


Hello,

I'd like to print object names with my smobs like this:

  guile> (make-my-obj "foo")
  #<my-obj foo 123456>

I know there was a discussion about giving a name to any object
by setting an object-property `name', so how about this change?

2000-06-25  Keisuke Nishida  <kxn30@po.cwru.edu>

	* smob.c (scm_smob_print): Print the object name if the object
         property `name' is set.

Index: smob.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/smob.c,v
retrieving revision 1.26
diff -u -r1.26 smob.c
--- smob.c	2000/06/12 11:59:42	1.26
+++ smob.c	2000/06/25 04:55:02
@@ -48,6 +48,7 @@
 #include "libguile/_scm.h"
 
 #include "libguile/objects.h"
+#include "libguile/objprop.h"
 #include "libguile/ports.h"
 
 #ifdef HAVE_MALLOC_H
@@ -110,13 +111,21 @@
 /* {Print}
  */
 
+extern SCM scm_sym_name;
+
 int
 scm_smob_print (SCM exp, SCM port, scm_print_state *pstate)
 {
   int n = SCM_SMOBNUM (exp);
+  SCM name = scm_object_property (exp, scm_sym_name);
   scm_puts ("#<", port);
   scm_puts (SCM_SMOBNAME (n) ? SCM_SMOBNAME (n) : "smob", port);
   scm_putc (' ', port);
+  if (SCM_NFALSEP (name))
+    {
+      scm_display (name, port);
+      scm_putc (' ', port);
+    }
   scm_intprint (SCM_UNPACK (scm_smobs[n].size ? SCM_CDR (exp) : exp), 16, port);
   scm_putc ('>', port);
   return 1;

Thanks,
Keisuke Nishida

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]