[Coldstuff] evaluate method

Jeremy Weatherford coldstuff@cold.org
Tue, 15 Jan 2002 08:46:15 -0600 (CST)


Actually, it's simpler than the other change mentioned... if you have the
statement:

return 1 + 1

in a method, what do you get?  A parse error, of course, because there's
no trailing semicolon.  :)

Try: resp = .eval(["return 1 + 1;"]);

Jeremy Weatherford
xidus@xidus.net
http://xidus.net

On Tue, 15 Jan 2002, Adam Cormany wrote:

> I just tried $root.eval on my cold and also on
> ice.cold with this:
> @program $user_soth.atc() +access=pub
>   var resp;
>
>   resp = .eval(["return 1 + 1"]);
>   .tell("resp=" + resp);
>
>   // $#Edited: 15 Jan 02 06:42 $user_soth
>
> When I run this as ;.atc(); I get this result:
> resp=['errors, ["Line 2: parse error"], 0, 0]
>
> It looks like add_method doesn't like what I'm doing?
> Any other suggestions or am I misunderstand
> $root.eval?
>
> --- Brandon Gillespie <brandon@roguetrader.com> wrote:
> > On Mon, Jan 14, 2002 at 11:04:57PM -0500, Adam
> > Cormany wrote:
> > > I've been trying and can't figure out how to do
> > this on my own so hopefully the cold gods will smile
> > on me tonight:)
> > >
> > > I'm parsing some text and by the time it's all
> > finished, I have a string of an equation of numbers.
> > Is there a way to process this string to get the
> > answer? For example, I have a string "1+1", is there
> > a way to process this to get 2?  I know about @eval
> > or ; and I want to do exactly that but inside some
> > code as a method. I've been looking at
> > $programmer.eval_cmd and $programmer.evaluate but
> > I'm lost. Am I missing something or is there a
> > simple way to do <variable> = .<method>("1+1") ?
> > >
> >
> > @eval and ; on coldcore use .evaluate(), but there
> > is a distilled
> > version as .eval which you can use.  The only gotcha
> > is it expects a
> > full method, so include complete statements with
> > 'return'.  For your
> > case, do:
> >
> >     variable = .eval(["return 1+1"])[2];
> >
> > Or you can do what .eval is doing, and do your own
> > .add_method, exec,
> > del_method.
> >
> > -Brandon
> > _______________________________________________
> > Cold-Coldstuff mailing list
> > Cold-Coldstuff@cold.org
> > http://web.cold.org/mailman/listinfo/cold-coldstuff
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/
> _______________________________________________
> Cold-Coldstuff mailing list
> Cold-Coldstuff@cold.org
> http://web.cold.org/mailman/listinfo/cold-coldstuff
>