From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Import your CK macro into Guile? Date: Fri, 09 Nov 2012 13:35:49 -0500 Message-ID: <87625e7hfe.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1352486177 9814 80.91.229.3 (9 Nov 2012 18:36:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 9 Nov 2012 18:36:17 +0000 (UTC) Cc: guile-devel@gnu.org To: oleg@okmij.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Nov 09 19:36:27 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TWtRH-0002i1-IZ for guile-devel@m.gmane.org; Fri, 09 Nov 2012 19:36:23 +0100 Original-Received: from localhost ([::1]:60964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWtR8-0006IW-8z for guile-devel@m.gmane.org; Fri, 09 Nov 2012 13:36:14 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:40374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWtR2-0006Fv-LC for guile-devel@gnu.org; Fri, 09 Nov 2012 13:36:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TWtQy-0001u5-Bl for guile-devel@gnu.org; Fri, 09 Nov 2012 13:36:08 -0500 Original-Received: from world.peace.net ([96.39.62.75]:60314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWtQy-0001tp-7R for guile-devel@gnu.org; Fri, 09 Nov 2012 13:36:04 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TWtQq-0003xu-JW; Fri, 09 Nov 2012 13:35:56 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15132 Archived-At: --=-=-= Content-Type: text/plain Hi Oleg, I'd like to import your CK macro into Guile. Would you be willing to contribute it to Guile? If so, please respond to the list to say so. It's small enough (15 lines) that I guess we don't need papers. Here's what I was hoping to add. It's slightly modified to use an internal helper macro instead of using the "arg" trick. If not, I guess I can reinvent the wheel easily enough, but it seems silly to do so. What do you think? Mark --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=ck.scm Content-Description: ck.scm ;;; ck, an abstract machine to facilitate applicative-order macro ;;; programming ;;; Copyright (C) 2012 Free Software Foundation, Inc ;;; Copyright (C) 2009, 2011 Oleg Kiselyov ;;; ;;; This library is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU Lesser General Public ;;; License as published by the Free Software Foundation; either ;;; version 3 of the License, or (at your option) any later version. ;;; ;;; This library is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; Lesser General Public License for more details. ;;; ;;; You should have received a copy of the GNU Lesser General Public ;;; License along with this library; if not, write to the Free Software ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;;; ;;; ;;; Originally written by Oleg Kiselyov and later contributed to Guile. ;;; ;;; Based on the CK machine introduced in: ;;; ;;; Matthias Felleisen and Daniel P. Friedman: Control operators, the ;;; SECD machine, and the lambda-calculus. In Martin Wirsing, editor, ;;; Formal Description of Programming Concepts III, pages ;;; 193-217. Elsevier, Amsterdam, 1986. ;;; ;;; See http://okmij.org/ftp/Scheme/macros.html#ck-macros for details. ;;; (define-syntax ck (syntax-rules (quote) ((ck () 'v) v) ; yield the value on empty stack ((ck (((op ...) ea ...) . s) 'v) ; re-focus on the other argument, ea (ck-arg s (op ... 'v) ea ...)) ((ck s (op ea ...)) ; Focus: handling an application; (ck-arg s (op) ea ...)))) ; check if args are values (define-syntax ck-arg (syntax-rules (quote) ((ck-arg s (op va ...)) ; all arguments are evaluated, (op s va ...)) ; do the redex ((ck-arg s (op ...) 'v ea1 ...) ; optimization when the first ea (ck-arg s (op ... 'v) ea1 ...)) ; was already a value ((ck-arg s (op ...) ea ea1 ...) ; focus on ea, to evaluate it (ck (((op ...) ea1 ...) . s) ea)))) --=-=-=--