From: Ian Price <ianprice90@googlemail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Guile Lua
Date: Mon, 14 Jan 2013 21:02:23 +0000 [thread overview]
Message-ID: <87ehhn5vhc.fsf@Kagami.home> (raw)
In-Reply-To: <CAGua6m04gbJPX26yX+scifCZap2k0OJg9tU+yYScuRj85nW53w@mail.gmail.com> (Stefan Israelsson Tampe's message of "Mon, 14 Jan 2013 21:51:59 +0100")
[-- Attachment #1: Type: text/plain, Size: 734 bytes --]
Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
> To note is that in order to implement common lisp one need to bypass tree-il
> and generate directly to glil, the reason is that tagbody is poorly
> represented
> by tree-il. If we intend to be multilingual it would be nice to be able to
> effectively
> represent those ideoms. Any thoughts on it?
At one point I implemented tagbody for a laugh using call/cc. I've
attached the code, but it's kinda lame. I was much less experienced with
continuations and macros then, and I could certainly write it better now.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
[-- Attachment #2: tagbody --]
[-- Type: text/plain, Size: 1327 bytes --]
(library (tagbody)
(export tagbody go)
(import (rnrs)
(for (tagbody utils) expand)
(for (srfi :8 receive) expand))
(define (go tag)
(tag #f))
(define-syntax tagbody
(lambda (stx)
(define (make-group tag statements next)
#`(call/cc
(lambda (escape)
(call/cc
(lambda (k)
(set! #,tag k)
(escape k)))
#,@statements
#,(if next
#`(go #,next)
#'#f))))
(define (exprs->groups first-tag list)
(unzip (plist->alist identifier?
(cons first-tag list))))
(syntax-case stx ()
[(tagbody tags-or-statements ...)
(let ((init #'init))
(receive (tags groups) (exprs->groups
init
(syntax->list #'(tags-or-statements ...)))
(with-syntax (((entry-point ...) (generate-temporaries tags))
((tag ...) tags)
((group ...)
(map make-group tags groups (shift-left tags #f))))
#`(let ((tag #f) ... (done #f))
(let ((entry-point group) ...)
(unless done
(set! done #t)
(go #,init)))))))])))
)
[-- Attachment #3: various utilities --]
[-- Type: text/plain, Size: 1434 bytes --]
(library (tagbody utils)
(export plist->alist
shift-left
unzip
syntax->list
)
(import (rnrs))
(define (syntax->list stxobj)
(define (inner stx)
(syntax-case stx ()
[() '()]
[(x . rest)
(cons #'x (inner #'rest))]))
(assert (list? (syntax->datum stxobj)))
(inner stxobj))
(define (plist->alist car? plist)
;; assumes head of (car? plist) is true
(define (rcons a b)
(cons (reverse a) b))
(if (null? plist)
'()
(let loop ((plist (cdr plist))
(current-field (list (car plist)))
(return-list '()))
(cond ((null? plist)
(reverse
(if (null? current-field)
return-list
(rcons current-field return-list))))
((car? (car plist))
(loop (cdr plist)
(list (car plist))
(rcons current-field return-list)))
(else
(loop (cdr plist)
(cons (car plist) current-field)
return-list))))))
(define (unzip list-of-pairs)
(let loop ((pairs list-of-pairs) (cars '()) (cdrs '()))
(if (null? pairs)
(values (reverse cars) (reverse cdrs))
(loop (cdr pairs) (cons (caar pairs) cars)
(cons (cdar pairs) cdrs)))))
(define (shift-left old-list end)
(append (cdr old-list) (list end)))
)
next prev parent reply other threads:[~2013-01-14 21:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-17 16:30 Guile Lua Ian Price
2012-11-19 2:30 ` nalaginrut
2012-11-19 21:07 ` Ludovic Courtès
2012-11-20 4:50 ` nalaginrut
2012-11-20 11:25 ` Ian Price
2012-11-20 17:04 ` Ludovic Courtès
2012-11-21 2:40 ` nalaginrut
2012-11-21 3:20 ` nalaginrut
2012-11-21 13:25 ` Ludovic Courtès
2012-11-21 15:51 ` Stefan Israelsson Tampe
2013-01-12 8:43 ` Nala Ginrut
2013-01-12 14:37 ` Noah Lavine
2013-01-12 15:25 ` Nala Ginrut
2013-01-13 15:13 ` Ian Price
2013-01-14 20:51 ` Stefan Israelsson Tampe
2013-01-14 21:02 ` Ian Price [this message]
2012-11-23 3:45 ` nalaginrut
2012-11-20 0:24 ` Ian Price
2012-11-20 6:12 ` Daniel Hartwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ehhn5vhc.fsf@Kagami.home \
--to=ianprice90@googlemail.com \
--cc=guile-devel@gnu.org \
--cc=stefan.itampe@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).