From: cirfu
Subject: macro-problem
Date: 
Message-ID: <edd7578f-6f3e-404a-ae66-5d7ffc7d16cb@f36g2000hsa.googlegroups.com>
why is the first one not working but the second is? ok dumb idea to
use == since it normally means test and not assignment, just
wondering).

CL-USER> (defmacro == (var val)
	   (setf var val))
==
CL-USER> (== d 7)
7
CL-USER> d
; Evaluation aborted
CL-USER>


and why is this working for a but not for k?

CL-USER> (defmacro := (var val)
	   (setf var val))
:=
CL-USER> (:= k 9)
9
CL-USER> k
; Evaluation aborted
CL-USER> (:= a 4)
4
CL-USER> a
4

From: danb
Subject: Re: macro-problem
Date: 
Message-ID: <a9b660e4-7d87-482b-ab80-99703ba3ad4a@e39g2000hsf.googlegroups.com>
On Jun 8, 4:29 pm, cirfu <············@yahoo.se> wrote:
> why is the first one not working but the second is?

Actually, neither one is working.

> CL-USER> (defmacro == (var val)
>            (setf var val))

Your macro should *return* the setf form, but
instead it's *evaluating* it.  To return the setf
form, you have to either quote it or construct it.
Quote:    `(setf ,var ,val)
Construct: (list 'setf var val)

Either way, your macro has to return the s-expression
unevaluated, except for var and val.

> ==
> CL-USER> (== d 7)
> 7

The setf form inside your macro binds the local variable
VAR to the value of VAL, which is 7.  Setf returns the
value assigned, and it's the last form in the macro, so
the new value of VAR is returned.  The macro ignored D.

> CL-USER> d
> ; Evaluation aborted

So, since the macro ignored D, D is still unbound.

> and why is this working for a but not for k?
> CL-USER> (:= a 4)
> 4
> CL-USER> a
> 4

This can't be right.  You must have bound A yourself
some other way.  Both of your macros are ignoring
their first argument.

--Dan

------------------------------------------------
http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
From: Ken Tilton
Subject: Re: macro-problem
Date: 
Message-ID: <484c7451$0$23563$607ed4bc@cv.net>
cirfu wrote:
> why is the first one not working but the second is? ok dumb idea to
> use == since it normally means test and not assignment, just
> wondering).
> 
> CL-USER> (defmacro == (var val)
> 	   (setf var val))
> ==
> CL-USER> (== d 7)
> 7
> CL-USER> d
> ; Evaluation aborted
> CL-USER>
> 
> 
> and why is this working for a but not for k?
> 
> CL-USER> (defmacro := (var val)
> 	   (setf var val))
> :=
> CL-USER> (:= k 9)
> 9

Never mind that crap, help us figure out how to get rid of the frickin 
parentheses, they are driving us nuts.

thx, kenny


-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant: 
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk: 
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en
From: Filipe Cabecinhas
Subject: Re: macro-problem
Date: 
Message-ID: <m263sjd2uu.fsf@farnsworth.albasani.net>
cirfu <············@yahoo.se> writes:

> why is the first one not working but the second is? ok dumb idea to
> use == since it normally means test and not assignment, just
> wondering).

You should read some texts to learn about what macros are and what
they do. The macro should return an S-Expression to substitute the
macro call. You're not doing that, you're doing a setf in the macro
body, which won't do what you want.

Try (macroexpand-1 '(setf var val)) to see what will be in your
macro's body.


-- 

  - Filipe Cabecinhas

(defvar real-email
  (apply #'concatenate 'string
         '("filcab" ·@" "gmail" "." "com"))
  "My real email address.")
From: cirfu
Subject: Re: macro-problem
Date: 
Message-ID: <a3b7e362-a73e-402b-9813-bbf484525c21@l42g2000hsc.googlegroups.com>
the whole thing doesnt make sense. i keep getting weird errors.
is setf not really menat for us ein macros?

i tried:
(macroexpand-1 '(setf var val))

CL-USER> (defmacro := (var val)
	   (list 'setf var val))
:=
CL-USER> (:= m 99)
99
CL-USER> m
99

which seems to work.
From: Ken Tilton
Subject: Re: macro-problem
Date: 
Message-ID: <484c74c2$0$23574$607ed4bc@cv.net>
cirfu wrote:
> the whole thing doesnt make sense. i keep getting weird errors.
> is setf not really menat for us ein macros?

If G*d had meant for us to write macros, would the backquote key have 
such a silly name and be way over there on the edge of the keyboard like 
the goddamn Aleution Islands? I don't think soooooooooooooo.....

hth,kenny

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant: 
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk: 
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en
From: Thomas F. Burdick
Subject: Re: macro-problem
Date: 
Message-ID: <06dd58e4-0545-4e5b-bab7-e99c678af8ed@z66g2000hsc.googlegroups.com>
On Jun 9, 2:09 am, Ken Tilton <···········@optonline.net> wrote:
> cirfu wrote:
> > the whole thing doesnt make sense. i keep getting weird errors.
> > is setf not really menat for us ein macros?
>
> If G*d had meant for us to write macros, would the backquote key have
> such a silly name and be way over there on the edge of the keyboard like
> the goddamn Aleution Islands? I don't think soooooooooooooo.....

Accent grave? Right by my right pinky? I think God only meant for
macros to be used by French Mac users. Mysterious ways and all that.
From: Ken Tilton
Subject: Re: macro-problem
Date: 
Message-ID: <484d1cae$0$11602$607ed4bc@cv.net>
Thomas F. Burdick wrote:
> On Jun 9, 2:09 am, Ken Tilton <···········@optonline.net> wrote:
> 
>>cirfu wrote:
>>
>>>the whole thing doesnt make sense. i keep getting weird errors.
>>>is setf not really menat for us ein macros?
>>
>>If G*d had meant for us to write macros, would the backquote key have
>>such a silly name and be way over there on the edge of the keyboard like
>>the goddamn Aleution Islands? I don't think soooooooooooooo.....
> 
> 
> Accent grave? Right by my right pinky? I think God only meant for
> macros to be used by French Mac users. Mysterious ways and all that.

Ca explique tout!

Mci,G

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant: 
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk: 
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en
From: Pascal J. Bourguignon
Subject: Re: macro-problem
Date: 
Message-ID: <8763sjblv4.fsf@hubble.informatimago.com>
cirfu <············@yahoo.se> writes:

> the whole thing doesnt make sense. i keep getting weird errors.
> is setf not really menat for us ein macros?
>
> i tried:
> (macroexpand-1 '(setf var val))

There is no point in that.

SETF is a complex macro, it's expansions are often implementation
dependant and won't help you in guessing how to implement SETF itself,
and therefore won't help you to implement a == macro after it.

If you want to know it, have a look at GET-SETF-EXPANSION (and DEFSETF
and (DEFUN (SETF x) ...)).


> CL-USER> (defmacro := (var val)
> 	   (list 'setf var val))
> :=
> CL-USER> (:= m 99)
> 99
> CL-USER> m
> 99
>
> which seems to work.

Yes, read my other answer to see why.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"This machine is a piece of GAGH!  I need dual Opteron 850
processors if I am to do battle with this code!"
From: Pascal J. Bourguignon
Subject: Re: macro-problem
Date: 
Message-ID: <87abhvbm3e.fsf@hubble.informatimago.com>
Filipe Cabecinhas <······@nospam.com> writes:

> cirfu <············@yahoo.se> writes:
>
>> why is the first one not working but the second is? ok dumb idea to
>> use == since it normally means test and not assignment, just
>> wondering).
>
> You should read some texts to learn about what macros are and what
> they do. The macro should return an S-Expression to substitute the
> macro call. You're not doing that, you're doing a setf in the macro
> body, which won't do what you want.

Yes.


Macros are functions that must _return_ code.  They mustn't _execute_
code.  Well, of course, to return anything they have to execute
something, but that something is executed at macroexpansion time
(usually included in compilation time), and you don't want to execute
then things that should be executed at run-time, that is, the form
that you should return.


> CL-USER> (defmacro == (var val)
> 	   (setf var val))
> ==
> CL-USER> (== d 7)
> 7
> CL-USER> d
> ; Evaluation aborted



 
> and why is this working for a but not for k?
> 
> CL-USER> (defmacro := (var val)
> 	   (setf var val))
> :=
> CL-USER> (:= k 9)
> 9
> CL-USER> k
> ; Evaluation aborted
> CL-USER> (:= a 4)
> 4
> CL-USER> a
> 4

Try (:= a 42) and then a.  I'd bet a will still be 4.
 



> Try (macroexpand-1 '(setf var val)) to see what will be in your
> macro's body.

No, not really.



So you  first start to write a function that takes a VAR and a VAL,
and returns a form that assigns VAL to VAR:

(defun gen-assign (var val)
  (list 'setf var val))

Try it:

(gen-assign 'a '7)

If it's ok, you can then hook it into the compiler:

(defmacro == (var val) (gen-assign var val))

Check it:

(macroexpand '(== a 7))

Is it ok?

So now you can run it:

(let (a)
  (== a 7)
  a)


Note that while it's not forbidden to bind functions or macros to
keywords, it's not advised to do so, since keywords are a global
resource that may be used by several systems.  You wouldn't like it if
just because you loaded some utility package your := macro was
replaced by some := function doing something entirely different.  So
don't do it yourself.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"This machine is a piece of GAGH!  I need dual Opteron 850
processors if I am to do battle with this code!"
From: Thomas A. Russ
Subject: Re: macro-problem
Date: 
Message-ID: <ymiy75ea0sj.fsf@blackcat.isi.edu>
cirfu <············@yahoo.se> writes:

> why is the first one not working but the second is? ok dumb idea to
> use == since it normally means test and not assignment, just
> wondering).
> 
> CL-USER> (defmacro == (var val)
> 	   (setf var val))
> ==
> CL-USER> (== d 7)
> 7
> CL-USER> d
> ; Evaluation aborted
> CL-USER>

What do you get from evaluating VAR?

> 
> 
> and why is this working for a but not for k?

Undoubtedly because you at some time previously executed
  (setf a 4)

For a better clue, what is the value of VAR after each of the macro
invocations. 

> CL-USER> (defmacro := (var val)
> 	   (setf var val))
> :=
> CL-USER> (:= k 9)
> 9
> CL-USER> k
> ; Evaluation aborted
> CL-USER> (:= a 4)
> 4
> CL-USER> a
> 4
> 

-- 
Thomas A. Russ,  USC/Information Sciences Institute