chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Creating new types and their representation in the R


From: Peter Bex
Subject: Re: [Chicken-users] Creating new types and their representation in the REPL
Date: Wed, 7 Jul 2010 20:58:51 +0200
User-agent: Mutt/1.4.2.3i

On Wed, Jul 07, 2010 at 01:45:39PM -0500, Jack Trades wrote:
> I'm sure this is a simple question but I can't quite figure it out.  Is
> there a way to get (define-record ...) to print out something other than the
> tag of the record?
> 
> Example of current behavior:
> 
> (define-record point x y)
> (define p (make-point 5 10))
> p
> ===> #<point>
> 

Use define-record-printer:
http://chicken.wiki.br/man/4/Non-standard%20macros%20and%20special%20forms#define-record-printer

> Example of desired behavior:
> 
> (define-record point x y)
> (define p (make-point 5 10))
> p
> ===> (5 10)

(define-record-printer (point p outport)
  (display (list (point-x p) (point-y p)) outport)

> -- or --
> ===> (point 5 10)

(define-record-printer (point p outport)
  (display (list 'point (point-x p) (point-y p)) outport)

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]