Hello Experts,
my favorite feature of gambit is its portability. It compiles so easily on SunOS, IRIX, AIX, HP-UX and Linux. (Try to find such a common lisp implementation!) So now my questions:
- 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 - there is a function to create symbolic links. Is there also one for readlink(2)? - feature wish: copy-file could be extended to overwrite an existing file. copy-file src dest #!optional force - this code, which is written by Olin Shivers, doesn't work:
(define-syntax let-string-start+end
(syntax-rules () ((let-string-start+end (start end) proc s-exp args-exp body ...) (receive (start end) (string-parse-final-start+end proc s-exp args-exp) body ...)) ((let-string-start+end (start end rest) proc s-exp args-exp body ...) (receive (rest start end) (string-parse-start+end proc s-exp args-exp) body ...)))) *** ERROR IN (console)@4.17 -- Ill-formed expression
Christoph Bauer
Afficher les réponses par date
Christoph Bauer wrote:
Hello Experts,
my favorite feature of gambit is its portability. It compiles so easily on SunOS, IRIX, AIX, HP-UX and Linux. (Try to find such a common lisp implementation!) So now my questions:
- 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
- there is a function to create symbolic links. Is there also one for readlink(2)?
I don't know about these... You can always use the object->u8vector (and its counter part (u8vector->object) to make a copy, but there must be an easier way. Here is an example:
Gambit v4.2.8
(define-type t a b) (define t1 (make-t 1 2)) t1
#<t #3 a: 1 b: 2>
(define t2 (with-input-from-string (with-output-to-string "" (lambda () (write
(object->u8vector (make-t 1 2))))) (lambda () (u8vector->object (read)))))
t2
#<t #4 a: 1 b: 2>
(eq? t1 t2)
#f
- this code, which is written by Olin Shivers, doesn't work:
(define-syntax let-string-start+end
(syntax-rules () ((let-string-start+end (start end) proc s-exp args-exp body ...) (receive (start end) (string-parse-final-start+end proc s-exp args-exp) body ...)) ((let-string-start+end (start end rest) proc s-exp args-exp body ...) (receive (rest start end) (string-parse-start+end proc s-exp args-exp) body ...)))) *** ERROR IN (console)@4.17 -- Ill-formed expression
The syntax-case form is not supported by default by gambit-c, it is rather the "lower level" define-macro form which is used. If you want to use syntax-case macros, you have to include it with:
(include "~~/syntax-case.scm")
Then, you'll have access to it.
Have fun ^_^
David
David St-Hilaire wrote:
Christoph Bauer wrote:
- 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
For copying, there happens to be a function in the Gambit _io part which does what you want:
(define-prim (##readtable-copy rt) (let ((copy (##vector-copy rt))) (##subtype-set! copy (macro-subtype-structure)) copy))
so you could just use that one.
For turning into a list, you can mis-use |##vector->list|.
Note that those don't do type checking so be sure you actually pass them a structure (check with |##structure?|).
The syntax-case form is not supported by default by gambit-c, it is rather the "lower level" define-macro form which is used. If you want to use syntax-case macros, you have to include it with:
(include "~~/syntax-case.scm")
This should probably be:
(load "~~/syntax-case")
without the suffix, so it can be compiled (like with '(compile-file (path-expand "~~/syntax-case")) ) and the compiled object is loaded.
Christian.
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.