octave-maintainers
[Top][All Lists]
Advanced

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

Re: Error with pkg.m (== isspace does work with cell arrays anymore)


From: Daniel J Sebald
Subject: Re: Error with pkg.m (== isspace does work with cell arrays anymore)
Date: Mon, 25 Feb 2008 18:42:19 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

John W. Eaton wrote:
On 25-Feb-2008, Søren Hauberg wrote:

| | man, 25 02 2008 kl. 16:17 -0500, skrev John W. Eaton:
| > On 24-Feb-2008, Michael Goffioul wrote:
| > | > | I have an error with recent mercurial code, in pkg.m. It reduces to
| > | the fact that isspace does not work anymore on cell array of
| > | strings. The error occurs around line 1299:
| > | | > | if (! all (isspace (filenames))) | > | | > | where filenames is a cell array of strings. I'm not sure what's
| > | the correct way to fix this.
| > | > I could probably help if I knew what isspace should do for a cell
| > array.  Matlab appears to do this:
| > | > >> isspace ({' ', ' ', ' '}) | > | > ans = | > | > 0 0 0 | > | > | > Which makes no sense to me. Is this behavior useful in some way that
| > I'm not seeing?
| It seems to be that matlab is doing something like
| | function output = isspace(input)
|   if (ischar(input))
|     ...
|   else
|     output = zeros(size(input), "logical");
|   endif
| endfunction
| | As an example:
|   isspace(@sin)
| returns 0. Does that make sense? Not in my mind. I think the logic is:
| | "A space is part of a string, hence if the input is not a string, it
| is not a space."

Yes, probably an error is better.

| I don't think we should copy this. If people depend on this behaviour,
| then there's a pretty good chance of a bug in their code.

OK, isspace appears to be unique.  Matlab doesn't seem to have the
other is* predicates, but it does have isstrprop, which lumps them all
in one function.  I propose the following change.  The added functions in
{Cell,ov-cell}.{h,cc} make writing the isstrprop function fairly
simple.

I would guess this still doesn't solve the isspace problem in pkg.m.
We need to know what the intent of the isspace call there is.

I would think that conditional test could be rewritten.  filenames is a cell of 
strings.  It wouldn't be difficult to write a short bit of code to test every 
member of the cell.  One wonders if there were a way to do that with a simple 
change of syntax.  This makes sense:

octave:25> x = [1 2; 3 4]
x =

  1   2
  3   4

octave:26> x(:)
ans =

  1
  3
  2
  4

and this makes sense:

octave:27> filenames = {'this' 'is' 'a' 'test'}
filenames =

{
 [1,1] = this
 [1,2] = is
 [1,3] = a
 [1,4] = test
}

octave:28> filenames{:}
ans =

(,
 [1] = this
 [2] = is
 [3] = a
 [4] = test
,)

And the following makes sense:

octave:30> filenames{1}(:)
ans =

t
h
i
s

so why couldn't we do:

octave:34> filenames{:}(:)
error: can't perform indexing operations for cs-list type
octave:34>

in the instance where every element of the list is a character?

Dan


reply via email to

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