octave-maintainers
[Top][All Lists]

## 'end' odds & ends

 From: John W. Eaton Subject: 'end' odds & ends Date: Thu, 10 Feb 2005 11:36:01 -0500

```On 29-Jan-2005, Daniel J Sebald <address@hidden> wrote:

| There are a few details about using 'end' as the index of a matrix or
| vector...
|
| The command-line documentation does not mention this use of 'end'.  That
| is, it only says
|
| -----------------
| *** end:
|
| Mark the end of any for, if, do, while, or function block.
| ------------------
|
| Also, it would be good to include comments about 'end' under the 'help
| -i' documentation for section 10.1 Index Expressions.  Furthermore,
| better organizing the text under 10.1 Index Expressions might make it
| more clear.

Sure, there is a lot of work to do on the manual.

| There is a discussion of how to generate a vector and
| matrix using indices, but then after that is a note to not do such a thing.
|
| -----------
|     Similarly, indexing a scalar with two vectors of ones can be used to
| create a matrix.  For example the following statements
|
|      a = 13;
|      a ([1, 1], [1, 1, 1])
|
| create a 2 by 3 matrix with all elements equal to 13.
|
|    This is an obscure notation and should be avoided.  It is better to
| use the function `ones' to generate a matrix of the appropriate size
| whose elements are all one, and then to scale it to produce the desired
| result.  *Note Special Utility Matrices::.
| ---------
|
| Why explain it if it isn't to be recommended?

So people will understand what happens when they do this kind of
thing?  It's possible, just not necessarily the clearest way of doing
this operation.  Proably you want repamat here.  Maybe that should be
stated, but the text quoted above was written long before repmat.

| Now, the second detail about 'end'.  The emacs lisp file doesn't
| recognize 'end' except as the end of a conditional or loop.  Therefore,
| it claims a mismatch and loses track of indentation.  (I know zilch
| about Lisp.)  Anyone familiar with Lisp know if this is an easy fix?  Or
| might there be something tricky about it?

Yes, it is somewhat tricky to decide whether end is being used inside
an index expression.  What rule would you use (need not be stated in
Lisp)?  Once you've decided that, the fix is to either modify
octave-block-end-regexp appropriately, or, if the rule can't be stated
in a regexp, to replace occurrences of

(looking-at octave-block-end-regexp)

with the function that can determine whether we are looking at the end
of a block and that is not confused by other uses of "end".

jwe

```