From: tutilus
Subject: Eval and macro
Date: 
Message-ID: <a94lsi$ncn$1@wanadoo.fr>
Hi!
I have a problem to use the local variables to a function in macro.
I explain me.

I have a method

(defmethod parcours-arbre ((arbre tree))
   ( ....
      (setf (tree-information arbre) (eval (tree-attribute arbre)))))

and a macro
(defmacro attribute (numero)
   (if (= 0 numero) `(tree-attribute (car (tree-sons arbre))))
   ... )

A example of the slot attribute in class 'tree' : "(print   (attribute)
... )"
In execution, the variable 'arbre' is ubound. I would used the occurence of
method.
I found a only solution : Used a global variable *arbre* initialized in
method and used in macro-function.

Have you a other(s) solution(s) ??

--
 Aur�lien

I'm so sorry about my english, i'm french.

From: Barry Margolin
Subject: Re: Eval and macro
Date: 
Message-ID: <Jelt8.12$zU.745@paloalto-snr1.gtei.net>
In article <············@wanadoo.fr>, tutilus <·······@wanadoo.fr> wrote:
>I have a problem to use the local variables to a function in macro.
>I explain me.

You can't.  Macros may be expanded before the function is called (for
instance, they must be expanded when you compile the function), and the
local variables are not avaiable at that time.

>
>I have a method
>
>(defmethod parcours-arbre ((arbre tree))
>   ( ....
>      (setf (tree-information arbre) (eval (tree-attribute arbre)))))
>
>and a macro
>(defmacro attribute (numero)
>   (if (= 0 numero) `(tree-attribute (car (tree-sons arbre))))
>   ... )
>
>A example of the slot attribute in class 'tree' : "(print   (attribute)
>... )"
>In execution, the variable 'arbre' is ubound. I would used the occurence of
>method.
>I found a only solution : Used a global variable *arbre* initialized in
>method and used in macro-function.
>
>Have you a other(s) solution(s) ??

Put a function in the slot, and use funcall, passing arbre to it:

(defmethod parcours-arbre ((arbre tree))
  ...
  (setf (tree-information arbre) (funcall (tree-attribute arbre) arbre)))

(defun attribute (arbre numero)
  (if (= 0 numero) (tree-attribute (car (tree-sons arbre))))
  ...)

An example of the slot attribute in class tree:
      #'(lambda (arbre) (attribute 0 arbre))

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Malauss�ne
Subject: Re: Eval and macro
Date: 
Message-ID: <a94qqn$rch$1@wanadoo.fr>
"Barry Margolin" <······@genuity.net> a �crit dans le message de news:
···············@paloalto-snr1.gtei.net...
> In article <············@wanadoo.fr>, tutilus <·······@wanadoo.fr> wrote:
[...]
> >In execution, the variable 'arbre' is ubound. I would used the occurence
of
> >method.
> >I found a only solution : Used a global variable *arbre* initialized in
> >method and used in macro-function
> >Have you a other(s) solution(s) ??
>
> Put a function in the slot, and use funcall, passing arbre to it:
>
> (defmethod parcours-arbre ((arbre tree))
>   ...
>   (setf (tree-information arbre) (funcall (tree-attribute arbre) arbre)))
>
> (defun attribute (arbre numero)
>   (if (= 0 numero) (tree-attribute (car (tree-sons arbre))))
>   ...)
>
> An example of the slot attribute in class tree:
>       #'(lambda (arbre) (attribute 0 arbre))

I can't use the function (or i didn't understand really) but it's my fault!
I more explain the problem.

I have a file that contains lines such as :
--- begin of file --------
A B C D  (setf (attribute 0) (format t "~S" (attribute 1)))  ;;Or a code
more complex.
 ....
--- end of file ----------

A course of file put information in slot 'attribute' for each "trees" (root
and leaves of tree).
In each slot attribute, the function (or macro-function) attribute is only a
reference of the other attribute.
The program should evaluate each attribute (and used the other attribute).
['attribute' is a simple call accessor function of slot 'attribute' in class
'tree'.]

Exemple i have a tree with a root and two leaves.
        <root>
<leaf1>   <leaf2>

I evaluate a leaf1 attribute  => (print "abc")
I evaluate a leaf2 attribute => (print "def")
(The leaves contain respectively "abc" and "def")
And evaluate root attribute => (concatenate 'string (attribute 1) (attribute
2))
The root attribute contain "abcdef".

The macro-function is here of replace the code (tree-attribute (nth numero
(tree-sons arbre)).

Thank for your answer (and to have answer, yet)

--
 Malauss�ne
From: Kent M Pitman
Subject: Re: Eval and macro
Date: 
Message-ID: <sfw7kneorqq.fsf@shell01.TheWorld.com>
"Malauss�ne" <·······@wanadoo.fr> writes:

> I have a file that contains lines such as :


Is this homework?
From: Malauss�ne
Subject: Re: Eval and macro
Date: 
Message-ID: <a96kq5$bbk$1@wanadoo.fr>
"Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
···············@shell01.TheWorld.com...
> "Malauss�ne" <·······@wanadoo.fr> writes:
>
> > I have a file that contains lines such as :
>
> Is this homework?

It's a problem i have met on my parser's project.
The files which contains the information lines are those have got to analyse
by the parser.
The method i am dealing with is not the better one and i'm looking for a
better one (less ugly that the one i am dealing with).

Thanks for answering.

--
 Malauss�ne
From: Coby Beck
Subject: Re: Eval and macro
Date: 
Message-ID: <W3Dt8.18810$ir6.881081@news1.calgary.shaw.ca>
"Malauss�ne" <·······@wanadoo.fr> wrote in message
·················@wanadoo.fr...
> "Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
> ···············@shell01.TheWorld.com...
> > "Malauss�ne" <·······@wanadoo.fr> writes:
> >
> > > I have a file that contains lines such as :
> >
> > Is this homework?
>
> It's a problem i have met on my parser's project.

Ok...  Is the parser project homework?  Nobody minds giving homework help,
we just like to know so we don't impede the learning process while aiding
the coding process.

Good luck, either way!

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Barry Margolin
Subject: Re: Eval and macro
Date: 
Message-ID: <MHDt8.3$NA3.244@paloalto-snr2.gtei.net>
In article <······················@news1.calgary.shaw.ca>,
Coby Beck <·····@mercury.bc.ca> wrote:
>
>"Malauss�ne" <·······@wanadoo.fr> wrote in message
>·················@wanadoo.fr...
>> "Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
>> ···············@shell01.TheWorld.com...
>> > "Malauss�ne" <·······@wanadoo.fr> writes:
>> >
>> > > I have a file that contains lines such as :
>> >
>> > Is this homework?
>>
>> It's a problem i have met on my parser's project.
>
>Ok...  Is the parser project homework?  Nobody minds giving homework help,
>we just like to know so we don't impede the learning process while aiding
>the coding process.

But he posted what he tried.  The usual complaint about posting homework is
when you just post the problem set and expect others to do it for you.  In
this thread he's clearly asking for more specific help and clarification,
not for people to do it all for him.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Coby Beck
Subject: Re: Eval and macro
Date: 
Message-ID: <PAEt8.18894$de1.943928@news3.calgary.shaw.ca>
Barry Margolin <······@genuity.net> wrote in message
····················@paloalto-snr2.gtei.net...
> In article <······················@news1.calgary.shaw.ca>,
> Coby Beck <·····@mercury.bc.ca> wrote:
> >
> >"Malauss�ne" <·······@wanadoo.fr> wrote in message
> >·················@wanadoo.fr...
> >> "Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
> >> ···············@shell01.TheWorld.com...
> >> > "Malauss�ne" <·······@wanadoo.fr> writes:
> >> >
> >> > > I have a file that contains lines such as :
> >> >
> >> > Is this homework?
> >>
> >> It's a problem i have met on my parser's project.
> >
> >Ok...  Is the parser project homework?  Nobody minds giving homework
help,
> >we just like to know so we don't impede the learning process while aiding
> >the coding process.
>
> But he posted what he tried.  The usual complaint about posting homework
is
> when you just post the problem set and expect others to do it for you.

What's wrong with being unusual?  But I think the "usual complaint" you cite
above covers all coding questions, not just the homework ones.

> In
> this thread he's clearly asking for more specific help and clarification,
> not for people to do it all for him.

He also gave an ambiguous answer to the direct question "Is this homework?"
Anyway, I meant no ill will.  Sometimes people wonder why no one (or few
people) respond to their post.

Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Kent M Pitman
Subject: Re: Eval and macro
Date: 
Message-ID: <sfwzo08ubhm.fsf@shell01.TheWorld.com>
"Coby Beck" <·····@mercury.bc.ca> writes:

> "Malauss�ne" <·······@wanadoo.fr> wrote in message
> ·················@wanadoo.fr...
> > "Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
> > ···············@shell01.TheWorld.com...
> > > "Malauss�ne" <·······@wanadoo.fr> writes:
> > >
> > > > I have a file that contains lines such as :
> > >
> > > Is this homework?
> >
> > It's a problem i have met on my parser's project.
> 
> Ok...  Is the parser project homework?  Nobody minds giving homework help,
> we just like to know so we don't impede the learning process while aiding
> the coding process.

In addition, it's surprising to come across "externally defined data" that
just happens to be in Common Lisp syntax.  In general, it never happens that
someone calls me up and says "the IT department of my company chose to write
data files that spontaneouisly and without the help of a common lisp 
programmer turned out to be valid common lisp code" much less also code that
makes apparent assumptions about the variables bound in some surrounding 
environment.  There is something very odd about this. 

Either there is another Common Lisp programmer secretly at work elsewhere
in your company (in which case you shoould seek them out) or else someone
(such as a teacher) has fixed the nature of this very arbitrary problem
in order to make it hard for you (in which case you should be doing the
homework, not us) or else the nature of the data file is probably within
your control and you might want to consider other formats for the data.
The fact that you take the data file format as fixed seems very peculiar,
which is why I'm not jumping to help.
From: Malauss�ne
Subject: Re: Eval and macro
Date: 
Message-ID: <a9a1nj$h6b$1@wanadoo.fr>
"Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
···············@shell01.TheWorld.com...
> "Coby Beck" <·····@mercury.bc.ca> writes:
>
[...]
> Either there is another Common Lisp programmer secretly at work elsewhere
> in your company (in which case you shoould seek them out) or else someone
> (such as a teacher) has fixed the nature of this very arbitrary problem
> in order to make it hard for you (in which case you should be doing the
> homework, not us) or else the nature of the data file is probably within
> your control and you might want to consider other formats for the data.
> The fact that you take the data file format as fixed seems very peculiar,
> which is why I'm not jumping to help.

I don't agree about this.
It's quite right  that the data files were fixed. When i need to create a
program, it often happened to  have a data files fixed by the problem (the
subject). The  program which has to be realized is often made to process a
specific data
files (fixed either by the others programs -whose generate its- or by a
specification). The last case was what my project was based on the point is
that i fixed
it myself. For speaking about my project, i prefered used "Yacc parser data
files like" to allow a simplier adaptation. So, i  showed you a data file's
example as i meant it.
 In my way of thinking, it's preferable to work with  preleminarie
informations (the
data files and out files) in order to built a program which corresponds to
this
"black-box".

 All these things to say that it was legitimate for me to indicate the data
in (or
out) as my problem affected the "in-module" (it was the situation).

Everything you 've said seems illegitimate to my in that case as in
orthers!!

--
 Malauss�ne
From: Kent M Pitman
Subject: Re: Eval and macro
Date: 
Message-ID: <sfwpu13kxpm.fsf@shell01.TheWorld.com>
"Malauss�ne" <·······@wanadoo.fr> writes:

> "Kent M Pitman" <······@world.std.com> a �crit dans le message de news:
> ···············@shell01.TheWorld.com...
> > "Coby Beck" <·····@mercury.bc.ca> writes:
> >
> [...]
> > Either there is another Common Lisp programmer secretly at work elsewhere
> > in your company (in which case you shoould seek them out) or else ...
> 
> I don't agree about this. [...]
> Everything you 've said seems illegitimate to my in that case as in
> orthers!!

I wasn't trying to convince you of a certain truth.  I was trying to
offer a plausible analysis as to why we would reasonably withhold 
information.

My words were not meant to convince or convict you.  They were meant to
help you understand that there was something legitimately odd which was
causing us to be cautious.

You might show up at my door with a cup in your hand and blood
dripping conspicuously from your arm, asking cheerfully to just borrow
a cup of sugar and either forgetting to mention that you were injured
or perhaps even thinking it too unimportant to mention.  I might, in
turn, still ask you questions before fulfilling your request.  I might
even give you a list of reasons for my concern.  Even if you have a
completely reasonable excuse for the odd-looking situation, your
attempt to argue point by point against my reasons for being nervous,
telling me I had no reason to be nervous, will not obtain the sugar
for you any faster.  Even if nothing is in fact wrong, that's not the
same statement as saying there was no reason to worry that something
might be wrong.

As an instructor once said to me in a probabilities class--there's
really no such thing as probabilities; things either happen or they do
not.  You can't argue from the fact that a certain horse wins a
certain race that there was not a 40% probability of the win; not
without throwing out the entire purpose of probabilities, which is to
reason usefully with insufficient information, At the point you know
the horse will win, the conditional probability of its winning becomes
100%, but that doesn't address the issue of the original probability
given the original information.

I'm sorry you think we've been unreasonable with you, but the various
of us who did so did it in the context of our experience.  In my case,
I think I would likely react the same again given the same degree of
information because I think your case is very unusual.  I'm glad you
seem to be getting help from some people here, but please don't think
the rest of us has been mean-spirited with you for simply being
cautious, nor for taking the trouble to explain in detail the reason
for our caution.

This is really all I have to say on the matter.  It doesn't really
require a reply, but if you do feel compelled to reply, don't expect
me to follow up further.  I'd like to spare the newsgroup a protracted,
irrelevant discussion.
From: Malauss�ne
Subject: Re: Eval and macro
Date: 
Message-ID: <a97bb5$on7$1@wanadoo.fr>
"Coby Beck" <·····@mercury.bc.ca> a �crit dans le message de news:
······················@news1.calgary.shaw.ca...
> "Malauss�ne" <·······@wanadoo.fr> wrote in message

> > > Is this homework?
> >
> > It's a problem i have met on my parser's project.
>
> Ok...  Is the parser project homework?  Nobody minds giving homework help,
> we just like to know so we don't impede the learning process while aiding
> the coding process.

I am not asking you to do my homework (a project four month ago). I have
found a solution about my "problem" (a very tiny part of my project) but i
think that isn't the better solution. To use a global variable is rarely the
better solution. (I'm -only- looking for a more elegant solution).

 I thought that evaluate a macro (with 'eval') in function used a this
function local variable (I explained that in my beginning post on this
thread).

 If i would that you do my project, i could write in a thread since three
month :
 "I search a source of a parser which use the Earley parse algorithm and
written in Lisp".
 did i do that ???

I thought that english or american developper were more nice!
I'm so sorry to disturb you.
I thanks Barry Morgolin for his answer (Interesting but i don't think that
apply for my problem) and his understanding (it's difficult to show his
problems in an other natural language).

--
 Malauss�ne
A french computer science student  disappointed by the reaction of the lisp
programmer.
[Sorry about my spelling mistake]
From: Coby Beck
Subject: Re: Eval and macro
Date: 
Message-ID: <ayGt8.19921$de1.967830@news3.calgary.shaw.ca>
Malauss�ne <·······@wanadoo.fr> wrote in message
·················@wanadoo.fr...
>
> "Coby Beck" <·····@mercury.bc.ca> a �crit dans le message de news:
> ······················@news1.calgary.shaw.ca...
> > "Malauss�ne" <·······@wanadoo.fr> wrote in message
>
> > > > Is this homework?
> > >
> > > It's a problem i have met on my parser's project.
> >
> > Ok...  Is the parser project homework?  Nobody minds giving homework
help,
> > we just like to know so we don't impede the learning process while
aiding
> > the coding process.
>
> I am not asking you to do my homework (a project four month ago). I have
> found a solution about my "problem" (a very tiny part of my project) but i
> think that isn't the better solution. To use a global variable is rarely
the
> better solution. (I'm -only- looking for a more elegant solution).

No problem, that is an admirable motivation.  So many of us settle for
whatever solution we find first and learn so much less because of that.

BTW - I think global variables fill a valuable role and are often a part of
an elegant solution.

> I thought that english or american developper were more nice!

Oh...better remove that misconception!  ;-)

> I'm so sorry to disturb you.
> I thanks Barry Morgolin for his answer (Interesting but i don't think that
> apply for my problem) and his understanding (it's difficult to show his
> problems in an other natural language).
>
> --
>  Malauss�ne
> A french computer science student  disappointed by the reaction of the
lisp
> programmer.

You should not be disappointed or insulted, I don't think anyone was mean to
you.  You have to understand that many other students come here for only
answers and not understanding, we can not always know for sure who has
integrity and who does not!

Please feel welcome to post on any other topic you wish!

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Barry Margolin
Subject: Re: Eval and macro
Date: 
Message-ID: <OQGt8.17$NE4.365@paloalto-snr1.gtei.net>
In article <············@wanadoo.fr>, Malauss�ne <·······@wanadoo.fr> wrote:
>I am not asking you to do my homework (a project four month ago). I have
>found a solution about my "problem" (a very tiny part of my project) but i
>think that isn't the better solution. To use a global variable is rarely the
>better solution. (I'm -only- looking for a more elegant solution).
>
> I thought that evaluate a macro (with 'eval') in function used a this
>function local variable (I explained that in my beginning post on this
>thread).

No, EVAL always evaluates in the top-level lexical environment.  It can
access local dynamic bindings (bindings of special variables), but not
lexical variables.

So you could do something like:

(let ((arbre ...))
  (declare (special arbre))
  (eval ...))

and when the expression refers to ARBRE, it will get this local binding.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Malauss�ne
Subject: Re: Eval and macro
Date: 
Message-ID: <a97f9h$4i8$1@wanadoo.fr>
> No, EVAL always evaluates in the top-level lexical environment.  It can
> access local dynamic bindings (bindings of special variables), but not
> lexical variables.
>
> So you could do something like:
>
> (let ((arbre ...))
>   (declare (special arbre))
>   (eval ...))
>
> and when the expression refers to ARBRE, it will get this local binding.

Thank you for this answer (yet)
I think that is the solution about my problem. That is the same principe
that my solution but it's more elegant ;o))

And for Coby Beck, i remove that misconception ;o)

If i have a other problems i will create new topics!

--
 Malauss�ne
Always french but no more disappointed