[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] eval-when 'defaults'

From: Camm Maguire
Subject: Re: [Gcl-devel] eval-when 'defaults'
Date: 07 Jul 2004 22:51:50 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings, and thanks!

Then it would appear the following lisp code is broken, and that a
conforming compiler is not obliged to compile set-up-cursor to code
that reflects the macro expansion of f-.  Right?

(defvar *acursor*  nil)
(import 'sloop:sloop)

(defmacro def-op (name type op &optional return-type)
            `(setf (macro-function ',name) (make-operation ',type ',op
;;make very sure .type .op and .return are not special!!
(defun make-operation (.type .op .return)
  (or .return (setf .return .type))
  #'(lambda (bod env) env
      (sloop for v in (cdr bod)
             when (eq t .type) collect v into body
             collect `(the , .type ,v) into body
             finally (setq body `(, .op ,@ body))
             (if (eq t .return) body
               `(the , .return ,body))))))

(def-op f+ fixnum +)
(def-op f- fixnum -)

(defun set-up-cursor (ar)
  (or *acursor* (setf *acursor* (make-array 11 :element-type 'fixnum
                                            :initial-element 0)))
  (let ((lis (array-dimensions ar))
        (*acursor* *acursor*))
    (declare ((vector fixnum) *acursor*))
    (setf (aref *acursor* 0) (length lis))
    (sloop for v in lis for i from 6 do (setf (aref *acursor* i) (f- v 1)))
    (sloop for i from 1 to (length lis) do (setf (aref *acursor* i) 0))))


Odd thing is that this appears to work as expected in cmucl, but the
spec seems to leave some of the behavior unspecified/implementation

Take care,

"Paul F. Dietz" <address@hidden> writes:

> Camm Maguire wrote:
> > Greetings!  Paul, from my brief reading of the spec, it would appear
> > that the default behavior for top level forms in a file being
> > compiled would be as if they were surrounded by an (eval-when
> > (:compile-toplevel :load-toplevel :execute)...).  Is this right?
> No.  Ordinary forms at the top level of a file being compiled
> aren't evaled at compile time, but rather are just minimally compiled,
> saved away, and evaled when the object file is loaded.
> See 3.2.3, paragraph 2, first sentence, and also case 6 in
> What *does* happen is that if the form is a macro form, the macro
> is expanded at compile time.  'DEF' macros typically expand into
> something with the necessary eval-when to force things to be computed
> at compile time.  See for more details of processing top level
> forms.
>       Paul
> _______________________________________________
> Gcl-devel mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gcl-devel

Camm Maguire                                            address@hidden
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]