Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Recreational Common Lisp :)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Conrad  
View profile  
 More options May 7 2003, 7:12 pm
Newsgroups: comp.lang.lisp
From: Mark Conrad <nos...@iam.invalid>
Date: Wed, 07 May 2003 23:10:16 GMT
Local: Wed, May 7 2003 7:10 pm
Subject: Re: Recreational Common Lisp :)
In article <060520031307021934%nos...@iam.invalid>, Mark Conrad

<nos...@iam.invalid> wrote:
> ...some erroneous stuff...

Here is the  *CORRECTED*  version of Paul Graham's "six macros" code
from his 1994  "On Lisp" book

Joe Marshall kindly pointed out that some of my added code would break
Paul's macros, and suggested that I use the CL "eval-when" here.

After some brief tests, the addition of eval-when does indeed appear to
eliminate difficulties experienced by me when a continuation tries to
go to toplevel

Copy and paste  *everything*  from between the asterisk lines to your
own file.   This code is necessary to be loaded into Lisp  _before_
the examples in this thread will run.

;; CORRECTED VERSION - REPLACE YOUR OLDER VERSION
;****************************************

(defun group (source n)
   (if (endp source)
        nil
        (let ((rest (nthcdr n source)))
           (cons (if (consp rest)
                         (subseq source 0 n) source)
                         (group rest n)) )))

(defmacro abbrev (short long)
    `(defmacro ,short (&rest args)
         `(,',long ,@args)))

(defmacro abbrevs (&rest names)
   `(progn
       ,@(mapcar #'(lambda (pair)
                                `(abbrev ,@pair))
                         (group names 2) )))

(abbrevs
     =setq
     define-symbol-macro)

;; Below are Paul Graham's six macros.  About the only changes
;; that I made were to change his "*cont*" to "%cont%", in order
;; to emphasize that %cont% is not a dynamically-scoped
;; variable.
;;
;; Another change I made was to use "=setq" to ensure that %cont%
;; does not act like a dynamically-scoped variable.
;;
;; =setq is just a convenient shorter abbreviation for CL's built-in
;; macro named "define-symbol-macro"
;;
;; Regarding the "=setq" form immediately below, it might not be
;; necessary however I think it should be left in because a few CL
;; implementors might try to turn toplevel variables like  %cont%  into
;; special variables, which would break Paul Graham's six macros.

(=setq
    %cont%
    #'(lambda (&rest args)
            (if (cdr args)
                 args
                 (car args) )))

(eval-when (:load-toplevel :execute)
        (setf (symbol-value '%cont%)
            (lambda (&rest args)
                (if (cdr args)
                     args
                    (car args)) )))

(defmacro  =lambda (parms &body body)
  `#'(lambda (%cont% ,@parms) ,@body))

(defmacro  =defun (name parms &body body)
  (let ((f (gensym)))
    `(progn
      (defmacro ,name ,parms
        `(,',f %cont% ,,@parms))
      (defun ,f (%cont% ,@parms) ,@body) )))

(defmacro  =bind (parms expr &body body)
  `(let ((%cont%  #'(lambda ,parms ,@body))) ,expr))

(defmacro  =values (&rest retvals)
  `(funcall %cont% ,@retvals))

(defmacro  =funcall (fn &rest args)
  `(funcall ,fn %cont% ,@args))

(defmacro  =apply (fn &rest args)
  `(apply ,fn %cont% ,@args))

;*******************************************
;; End of Paul Graham's six macros from his "On Lisp" book.

Mark-


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.