This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: CTAX revisited


Ian Bicking <ianb@colorstudy.com> writes:

> Okay, well not quite CTAX.  But, in an effort to revitalize (or maybe
> just vitalize) translation, I'm writing a translator from a C-like
> syntax to Scheme (no semantic translation at all).  tcl->scheme is a
> bit large and burdened with all sorts of complicated issues, and right
> now I'd like to deal with the fundamental issues of getting
> translators integrated into Guile -- how to load code destined for
> translations, how to package a translation, etc.  So, a C-like (or
> maybe more JavaScript-like) syntax would be useful, but also simple
> enough that the translation itself shouldn't be distracting.

Thank you for working on these problems.  (BTW, since Java and Scheme
are semantically similar and since we now have GOOPS, it's possible to
emulate Java efficiently.  So a Java->Scheme translator is probably
also a very rewarding project.)

> I'm almost finished with the translator.  There's one semantic issue
> that I need some help with: return, break, and continue.
> 
> call-with-current-continuation can, of course, implement these.  But
> call/cc is really heavy if every loop and function would have to be
> wrapped in one.  So, if there's any way to avoid this I'd really like
> to.  return is a very common construct, so most language translations
> will face this issue.
> 
> Ideas or advice on this issue would be most appreciated.

A primitive way to solve it is by using `catch' which is more
light-weight than continuations:

(define (return x)
  (throw 'return x))

(define (foo)
  (catch 'return
    (lambda ()
      (begin
        (return 'foo)
        'bar))
    (lambda (tag val)
      val)))

Similar constructions can be written for break and continue.

An approach which might lead to more efficient code is to transform
the code into continuation passing style.  Then return, break and
continue can be given simple definitions.

I'd be happy to clarify if you'd like more information.

Best regards,
/mdj

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]