Date: Wed, 5 Nov 2008 12:03:19 +0100 From: "Christoph Bauer" christoph.bauer@lmsintl.com
- is there a way to copy a record (define-structure) or to convert it to a list, like table-copy and table->list? for tables
Records are generally used to implement abstract data types that satisfy no other properties than the ones you endow them. Unlike tables or lists, they are not treated as general associations or sequences of objects; instead they are treated however you designate them to be treated. Copying, thus, is a highly application-dependent notion of which no general implementation can be prescribed. For instance, consider the following record type (defined with SRFI 9, but this detail is irrelevant):
(define-record-type <pare> (kons kar kdr) pare? (kar kar set-kar!) (kdr kdr set-kdr!))
The names were meant to be suggestive of a linked list structure derived from this record type -- but no machine would infer that a LYST-COPY routine on these structures would be analogous to SRFI 1's LIST-COPY. But then in some cases you will want to copy not just the structure of a list but the elements of the list to some degree. Again the machine cannot infer this; you the programmer must supply this information.
For elaboration on the subject, see Kent Pitman's essay `The Best of Intentions' at http://www.nhplace.com/kent/PS/EQUAL.html.