bugGNU Octave - Bugs: bug #49444, tilde output argument requires...

 
 

bug #49444: tilde output argument requires comma for parsing

Submitter:  Francesco Potortì <pot>
Submitted:  Wed 26 Oct 2016 08:14:08 AM UTC
   
 
Category:  Documentation Severity:  2 - Minor
Priority:  1 - Later Item Group:  Documentation
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 10 Jan 2017 05:07:45 PM UTC, comment #13: 

I would say

.. separated by a comma, not just a space.

Francesco Potortì <pot>
Mon 09 Jan 2017 08:25:41 PM UTC, comment #12: 

LGTM, thanks for writing something better than I can come up with.

Mike Miller <mtmiller>
Group Member
Mon 09 Jan 2017 08:14:47 PM UTC, comment #11: 

I added some more explanation about the use of the '~' placeholder to ignore arguments (http://hg.savannah.gnu.org/hgweb/octave/rev/cae62c8d4f96).  This was done on stable and will be part of the 4.2.1 bug fix release.

Rik <rik5>
Group administrator
Mon 09 Jan 2017 08:09:37 PM UTC, comment #10: 

I plan on pushing the attached change which adds a paragraph. Any changes needed to this?

(file #39415)

Mike Miller <mtmiller>
Group Member
Thu 27 Oct 2016 05:13:16 PM UTC, comment #9: 

Note that in the above expressions, the comma can be omitted in the list of output args, so for example

     [a, b] = [u, s, v] = svd (a)

is equivalent to

     [a b] = [u, s, v] = svd (a)

However, when using a tilde (~) as a placeholder for an output arg, you cannot omit commas between args.  The reason is that the tilde is also a negation operator and the comma is needed to distinguish the two uages.

Francesco Potortì <pot>
Thu 27 Oct 2016 05:05:12 PM UTC, comment #8: 

Yes, I think the text would want to say something like

When using the tilde as an argument placeholder, it must be separated from the following argument by a comma, otherwise it is interpreted as a logical not operator.

Mike Miller <mtmiller>
Group Member
Thu 27 Oct 2016 04:40:22 PM UTC, comment #7: 

I think the issue is that in other matrix list expressions,


[~ x]


is parsed as a negation expression so there is just one expression in the list.  So a comma is required here if you wish to have them treated as two separate items.  This is different from


[a b]


because in this case, two consecutive identifiers are parsed as two separate expressions.

John W. Eaton <jwe>
Group administrator
Thu 27 Oct 2016 04:27:32 PM UTC, comment #6: 

Was trying to write one, but it turns out that I do not know what to write. All the current examples use a comma.  What should the manual say?

- "use a comma because one never knows" does not look like a good thing to write in a manual

- "use a comma whn a tilde is involved because of Matlab compatibility" is maybe right, but:

1) I don't know if the problem is only with comma

2) I don't know if the reason is really Matlab compatibility

Francesco Potortì <pot>
Thu 27 Oct 2016 03:44:16 PM UTC, comment #5: 

Thanks, so Octave's behavior is correct. This could use some clarification in the manual, patches welcome on the file doc/interpreter/expr.txi, section "Assignment Ops".

Mike Miller <mtmiller>
Group Member
Thu 27 Oct 2016 01:10:19 PM UTC, comment #4: 

In matalb 2015a


>> [~, ~, x] = deal (1, 2, 3)

x =

     3

>> [~ ~ x] = deal (1, 2, 3)
Error: An array for multiple LHS assignment cannot contain expressions.

>>  [~ i] = sort(1:2)
Error: An array for multiple LHS assignment cannot contain expressions.


Anonymous
Wed 26 Oct 2016 05:56:31 PM UTC, comment #3: 

I would lean towards addressing this in documentation. To me it seems natural that tilde is a prefix operator, and can only be used in this special mode as an argument placeholder when it's followed by a comma.

What does Matlab do?

This example with sort is a little obtuse because the two output arguments are the same (both the sorted array and the indices are [1 2]). Something like this demonstrates a little more clearly


>> [~, ~, x] = deal (1, 2, 3)
x =  3
>> [~ ~ x] = deal (1, 2, 3)
parse error:

  invalid left hand side of assignment

>>> [~ ~ x] = deal (1, 2, 3)
         ^


Mike Miller <mtmiller>
Group Member
Wed 26 Oct 2016 05:39:53 PM UTC, comment #2: 

I changed the bug report title to something more specific.  I've also lowered the priority as there is an easy work-around in using commas to separate output arguments.

Rik <rik5>
Group administrator
Wed 26 Oct 2016 08:51:21 AM UTC, comment #1: 

Try to put comma between the argumnets


>>  [~, i] = sort(1:2)
i =

   1   2


Anonymous
Wed 26 Oct 2016 08:14:08 AM UTC, original submission:  

Docs from the isargout function speaks about tilde being used to ignore an output argument.  But apparently this does not work:


> [~ i] = sort(1:2)
parse error:

  invalid left hand side of assignment

>>> [~ i] = sort(1:2)
        ^


Francesco Potortì <pot>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #39415:  tilde.diff added by mtmiller (1KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by pot (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-09 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2017-01-09 mtmiller Attached File- Added tilde.diff, #39415
        StatusConfirmed Patch Submitted
    2016-10-27 mtmiller CategoryInterpreter Documentation
        Item GroupIncorrect Result Documentation
    2016-10-26 rik5 Severity3 - Normal 2 - Minor
        Priority5 - Normal 1 - Later
        StatusNone Confirmed
        Release4.0.3 dev
        Summarytilde as output argument does not work tilde output argument requires comma for parsing

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code