help-octave
[Top][All Lists]
Advanced

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

Re: Behavior of octave and ans


From: Mike Miller
Subject: Re: Behavior of octave and ans
Date: Mon, 7 Jul 2014 10:07:51 -0400

On Mon, Jul 7, 2014 at 11:59:48 +0200, François Poulain wrote:
> Hi,
>
> [Note for answers, I am not subscriber of the present list.]
>
> I am a TeXmacs developer, working on this bug:
> https://savannah.gnu.org/bugs/index.php?20312
>
> In our Octave plugin, we make an read-eval loop in the octave session,
> for translating some datatype into TeXmacs types. For this we use the
> "eval" function and looks for the result in "ans".
>
> I suppose that this worked well before octave-2.9 (I didn't tested it).
>
> However, it seems that currently, the 'ans' variable is not set when
> e.g. affectation are done. Then, If I write
>> a=1
> or
>> a
> 'ans' is not set, despite the fact that the given instruction produce an
> answer (which is reassignable, e.g. via "b=a=1").

Yes, this is the correct behavior. The special ans variable is only
updated when there is no lvalue being assigned to in the outermost
expression.

> So, is there a way to get somewhere the values returned by those
> instructions, without parsing octave's output ?

Since you are using eval, you could rewrite the user-input expression
to assign it to a particular named variable of your own choosing, and
get the result from its value. So for example

  texmacs_result = a=1
  texmacs_result = b=a=1
  texmacs_result = a+1

all update the variable texmacs_result. This should be equivalent to
what you were expecting the ans variable to be.

Does that do what you need?

-- 
mike



reply via email to

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