octave-maintainers
[Top][All Lists]
Advanced

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

Re: Matlab compatibility of assert


From: Rik
Subject: Re: Matlab compatibility of assert
Date: Tue, 24 Sep 2013 12:33:50 -0700

On 09/24/2013 10:45 AM, John W. Eaton wrote:
> On 09/24/2013 01:28 PM, Rik wrote:
>
>> How bothersome!  We have a perfectly good feature and then the syntax gets
>> changed underneath us.
>
> Yes, it's what we get for innovation.
>
>> I guess it's fine to change the function.  I would rather see oassert for
>> Octave assert rather than tassert.  This follows the pattern for ostrsplit
>> and strsplit where the same pre-existing function situation happened and we
>> had to change Octave to accommodate Matlab.
>
> OK, I don't have any particular attachment to the name, so oassert is
> fine with me, though when I see that, I think "old assert", not
> "octave assert".
>
> If we had packages, could that help here?  Then we could add something
> like
>
>   import octave.test.*
>
> in the test function and ensure that we get the version of assert that
> we want without having to change any of the existing test code.
>
> If that would help, then I think we could put this change off until
> later.  It hasn't really caused trouble for us so far, so maybe we
> should wait.
>
That would be nice, but it probably isn't strictly necessary.  test.m reads
in an entire block of code and then executes it as a function.  We could
simply put in a strrep or regexprep to replace assert with oassert before
it defines the function.  Alternatively, and getting a little fancy, we
could eval a new assert function into existence which is an alias for
oassert.  This would shadow the Matlab compatible assert until the end of
the function and then we could clear it.  I just tested this and it works

function assert (varargin)
  oassert (varargin{:});
endfunction

Although, now the warning message isn't accurate

assert (0,1)
error: ASSERT errors for:  assert (varargin {:})

so maybe the first way is better.

--Rik



reply via email to

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