Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

syntax rewrite then print out?


hi

how to rewrite "advance" scheme syntax with "old" scheme syntax then
print out?
define-syntax can recognize new syntax, but how to print them out or
pp them out?
I need to rewrite in situation like: (cadr x) => (car (cdr x))
(define (f x) ...) => (define (lambda (x) ... etc.
I need to do this because my simple interpreter can't handle them
right now.
I have a lots of test code to rewrite. thanks.

On Apr 2, 9:22 pm, dillog@gmail.com wrote:

> hi

> how to rewrite "advance" scheme syntax with "old" scheme syntax then
> print out?
> define-syntax can recognize new syntax, but how to print them out or
> pp them out?
> I need to rewrite in situation like: (cadr x) => (car (cdr x))
> (define (f x) ...) => (define (lambda (x) ... etc.
> I need to do this because my simple interpreter can't handle them
> right now.
> I have a lots of test code to rewrite. thanks.

I've just figured it out, mit-scheme's pp would work.

dillog@gmail.com writes:
> hi

> how to rewrite "advance" scheme syntax with "old" scheme syntax then
> print out?
> define-syntax can recognize new syntax, but how to print them out or
> pp them out?
> I need to rewrite in situation like: (cadr x) => (car (cdr x))
> (define (f x) ...) => (define (lambda (x) ... etc.
> I need to do this because my simple interpreter can't handle them
> right now.
> I have a lots of test code to rewrite. thanks.

You could add a simple Q&D macro system to your interpreter.

--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org

On Apr 3, 3:49 pm, Pascal Bourguignon <p@informatimago.com> wrote:

> dillog@gmail.com writes:
> > hi

> > how to rewrite "advance" scheme syntax with "old" scheme syntax then
> > print out?
> > define-syntax can recognize new syntax, but how to print them out or
> > pp them out?
> > I need to rewrite in situation like: (cadr x) => (car (cdr x))
> > (define (f x) ...) => (define (lambda (x) ... etc.
> > I need to do this because my simple interpreter can't handle them
> > right now.
> > I have a lots of test code to rewrite. thanks.

> You could add a simple Q&D macro system to your interpreter.

What's Q&D macro?

Quick & Dirty.

(define macros '()) ; an a list of macro definitions.

(define (define-macro name expander) (set! macros (cons (cons name expander) macros)))
(define (find-macro name) (let ((a (assoc name macros)))
                             (if a (cdr a) #f)))

And add to your eval:

(define (eval form ...)
   (cond
      ...
     ((find-macro (car form)) (eval ((find-macro (car form)) form) ...))
     ...))

So now you can start to write macros such as:

(define-macro 'if (lambda (form)
                      (let ((test (second form))
                            (then (third form))
                            (else (fourth form)))
                        `(cond (,test ,then) (else ,else)))))

People here will cry, because there's no hygine, etc, that's why I
qualified it of quick and dirty.  But it can help.

Now, of course, for define expanding to define it might be difficult.
You'd need a primitive define, let's name it %define (change your
eval), and then you can write:

(define-macro define (lambda (form)
                       (if (list? (second form))
                           ; (define (f . args) . body)
                           `(%define ,(caadr form) (lambda ,(cdadr form) . ,(cddr form)))
                           `(%define . ,(cdr form)))))

and be happy.

--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc