chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Egg svn request: caketext


From: felix winkelmann
Subject: Re: [Chicken-users] Egg svn request: caketext
Date: Tue, 18 Mar 2008 08:42:44 +0100

Hi!

Attached is a patch against the chicken trunk that adds
a rewrite hook for literals in program code. It's used like this:

% cat fix.scm
(set! ##compiler#literal-rewrite-hook
  (lambda (x w)
    `(,(w 'fix-strings) ',x)))
% cat ftest.scm
(use srfi-13)

(define (fix-strings x)
  (let walk ((x x))
    (cond ((pair? x) (cons (walk (car x)) (walk (cdr x))))
          ((vector? x)
           (list->vector (map walk (vector->list x))))
          ((string? x) (string-reverse x))
          (else x) ) ) )

(print "this is a test.")

(pp '(abc #(def "foobar" 99) #\_))
% csc -X fix.scm ftest.scm

It rewrites literals appearing in program text into
a function call (the hook function should probably
also check whether strings are contained in the
literal at all, to avoid adding a call for every literal).

The exact semantics of the hook are somewhat
subtle, but the above example should be sufficient
for this particular use (string translation).


cheers,
felix

Attachment: lrh.diff
Description: Text Data


reply via email to

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