[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parsing order for matrices
From: |
Max Brister |
Subject: |
Re: Parsing order for matrices |
Date: |
Thu, 18 Oct 2012 02:40:34 -0600 |
On Thu, Oct 18, 2012 at 1:50 AM, Daniel J Sebald <address@hidden> wrote:
> In trying to observe the whitespace-between-function-name-and-parenthesis I
> noticed the following behavior:
>
> octave:27> zeros (1, 10)
> ans =
>
> 0 0 0 0 0 0 0 0 0 0
>
> octave:28> [zeros (1, 10)]
> parse error:
>
> syntax error
>
>>>> [zeros (1, 10)]
>
> ^
>
> octave:28> [zeros(1, 10)]
> ans =
>
> 0 0 0 0 0 0 0 0 0 0
>
> Is it correct that the second case should be invalid and syntax error? I'm
> guessing that the parsing of the whole matrix comes before parsing of the
> elements, i.e., on the first pass Octave thinks the second case is ["zeros"
> "(1, 10)"]. Notice that Octave never gets to the stage of evaluating
> "zeros" otherwise that too would have been a syntax error.
>
> It seems to me that the algorithm could be altered slightly to evaluate an
> individual element before proceeding to the next element. I can't think of
> any ambiguity off hand.
>
> Dan
This does lead to ambiguity if the function is passed one argument, for example
octave> [i (1)]
should the result be [0+1i 1+0i] or 0+1i? In order to maintain consistency,
I think it is sane to refuse a space between the function and the parameter
when inside brackets.
--
Max Brister