help with macro / packages 
Author Message
 help with macro / packages

hi all,
this is my first attemt at macros,
i tried to create the rotatef macro which i needed for use with xlisp
i created a file called rotatef.lsp
whith the following contents
--------------------------------
; Rotatef 4 xlisp as defined in CL

;
(in-package "USER")
(export '(rotatef))
(defmacro rotatef (item-1 &rest items &aux tmp)
  (cond  ((null `(cdr ,items))
              `(progn                      ; a swap
                   (setf tmp ,item-1)

item

               )
         )
         (t
              `(progn
                   (setf tmp ,item-1)

;left shift f
(defmacro lsf (item-1 item-2 &rest items)
   (cond ((null items)
           `(setf ,item-1 ,item-2))
         (t
           (eval `(setf ,item-1 ,item-2))

   )
)
--------------------------------

then i when i run xlisp int the init.lsp file i added

--------------------------------
(load "common.lsp")
(load "common2.lsp")
(load "rotatef.lsp")
--------------------------------

in in my code file i have among some other functions these ones:

--------------------------------

(defun L (state)
  (if *debug* (format t "~%applying L"))
  (let (tempstate )
     (setq tempstate
         (mapcar #'change-face
                state '(vertical vertical nochange vertical radial
vertical)))
     (rotatef (second (first tempstate)) (second (fourth tempstate))
              (second (sixth tempstate)) (second (second tempstate)))
     (setf (third (fifth tempstate)) (rotate2 (third (fifth
tempstate))))
  (if *debug* (format t "~%   results with: ~a" (heuristic-fn
tempstate (gg))  ))
  tempstate
  )
)

(defun generate-face(color)
     (list   'horizontal
                (list color color color)
                (list color color color)
                (list color color color) )
)

(defun generate-goal(n)
   (declare (ignore n))
   (list (generate-face 'Y)      ;TOP
           (generate-face 'R)    ;Front
           (generate-face 'G)    ;RIGHT
           (generate-face 'O)    ;BACK
           (generate-face 'B)    ;Left
           (generate-face 'W))   ;Down
)

--------------------------------

it is ment to handle a data structure for rubic's cube.

when i load it and try the following line

(L (generate-goal 3))

i get in response:

error: unbound variable -tempstate
if continued ...

i think the problem has to do with the macro expantion not recognizing
this
variable but i have no clue as to how to slove it (may be pacakge
problems ?).

any help will be most welcome.

thanks,
eyal peleg



Fri, 09 Aug 1996 06:50:16 GMT  
 help with macro / packages

Can't tell for sure what is going on, but I would be suspicious of the
evals in your macro. eval uses the global bindings, and thus would not
see the local binding of tempstate. It would have been helpful if you
used baktrace so we could see where the error occured.

--
Tom Almy

Standard Disclaimers Apply



Sat, 10 Aug 1996 02:44:49 GMT  
 help with macro / packages

Quote:

>(defmacro rotatef (item-1 &rest items &aux tmp)
>  (cond  ((null `(cdr ,items))

This shouldn't be backquoted -- it passes the list (CDR ...) to NULL, which
will always return false.  However, since the other case works when ITEMS
only contains one element, this shouldn't cause the macro to fail.

Quote:
>              `(progn                      ; a swap
>                   (setf tmp ,item-1)

This TMP variable is not the same as the one in the &AUX specification,
because it's inside the backquote.  Since you don't have a local TMP
variable, you'll access the global one.

Outside the backquote, you should set TMP to (GENSYM), and then use ",tmp"
inside the backquote.

Quote:

>item

>               )
>         )
>         (t
>              `(progn
>                   (setf tmp ,item-1)

>;left shift f
>(defmacro lsf (item-1 item-2 &rest items)
>   (cond ((null items)
>           `(setf ,item-1 ,item-2))
>         (t
>           (eval `(setf ,item-1 ,item-2))


This is your problem.  EVAL uses the global environment.  If you reference
any local variables in the arguments to ROTATEF, it will fail.  The above
two lines should be:

        `(progn
            (setf ,item-1 ,item-2)

Unless you know what you're doing, if you think you need to use EVAL you're
almost always wrong.

By the way, I hope you're aware that your definition of ROTATEF will not
work correctly if you pass it subforms that have side effects or depend on
left-to-right argument evaluation, since it evaluates the subforms multiple
times.

--
Barry Margolin
System Manager, Thinking Machines Corp.




Sat, 10 Aug 1996 16:53:53 GMT  
 help with macro / packages
Quote:

>Can't tell for sure what is going on, but I would be suspicious of the
>evals in your macro. eval uses the global bindings, and thus would not
>see the local binding of tempstate. It would have been helpful if you
>used baktrace so we could see where the error occured.

>--
>Tom Almy

>Standard Disclaimers Apply

 i would write directly to you but our machine does not recognize
 wu.labs.tek.com, (do you know your IP addr ?),
 any way, to the problem:
 what kind of information should i get you ?
 what sould i write when i get the error ???
 assuming the problem is as you said it is : what should i do about it ?
 make tempstate global ?? use something else insteed of eval ??

thanks,
eyal peleg



Fri, 16 Aug 1996 05:00:50 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with macros writing macros in Bigloo

2. help sought for macro defining macro

3. A macro involving two sub-macros - where the 2nd macro needs results from the first

4. CMACROS assembly language macro package

5. CMACROS assembly language macro package

6. calling Word Macros through tcom package for tcl

7. TCL Macro Package (Needs a Maintainer)

8. Anaphoric macros and packages

9. Why is in-package a macro?

10. slots, get, packages, macro

11. Packages and macros are driving me slowly insane...

12. Macro packages

 

 
Powered by phpBB® Forum Software