bugGNU Octave - Bugs: bug #52488, genvarname substitutes underscore...

 
 

bug #52488: genvarname substitutes underscore for invalid characters in string

Submitted by:  None
Submitted on:  Thu 23 Nov 2017 04:16:14 PM UTC  
 
Category:  Octave Function Severity:  2 - Minor
Priority:  1 - Later Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Motius Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  dev
Operating System:  Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 19 Jan 2018 03:00:39 AM UTC, comment #6:

Submitting a changeset to fix this bug. I initially made the parameter default to "" for Matlab compatibility but realized this would then require all existing m-files and tests to possibly need updates, so I've set the default to "_" for now. Let me know what you all think.

(file #42971)

Stevie Schraudner <stevietodd>
Sat 25 Nov 2017 12:18:55 PM UTC, comment #5:

genvarname is an .m-file function so it should be easy to add some option in the input, maybe as an optional third argument.
Could be something like "" (= do like Matlab) or (default?) "_" (= replace invalid chars by underscores).

I have no time for it now but after perusing genvarname.m this looks like a nice little project for a novice contributor.

Release => dev
OS => any

Philip Nienhuis <philipnienhuis>
Project Member
Fri 24 Nov 2017 09:33:33 AM UTC, comment #4:

How about providing a choice for the user?
Something along these lines:

  • default behavior is to strip invalid characters (as does Matlab)
  • provide an option to override with a substitute character (I do agree with Rik that underscores make the name easier to read, but this breaks Matlab code...)
Motius <motius>
Thu 23 Nov 2017 09:09:54 PM UTC, comment #3:

True, it would be easy to call strtrim on the inputs. But, I figured since Octave was already not 100% compatible it didn't matter much.

Rik <rik5>
Project Administrator
Thu 23 Nov 2017 08:39:01 PM UTC, comment #2:

One could argue that trailing spaces cn be removed rather than replaced by underscores.

Philip Nienhuis <philipnienhuis>
Project Member
Thu 23 Nov 2017 05:19:41 PM UTC, comment #1:

According to Matlab's documentation,

The only requirements are that the name be "similar" and that the name is a valid syntax for the interpreter.

Although Octave doesn't remove spaces as Matlab does, it does produce a valid variable name that is "similar" to the original. It meets the requirements of the function genvarname, and I prefer the use of underscores as I think it makes the generated names easier to read. Imagine you have a variable name that encodes something about a measurement in the name.

The Matlab name is very difficult to decipher.

Rik <rik5>
Project Administrator
Thu 23 Nov 2017 04:16:14 PM UTC, original submission:

SYNOPSIS

The following snippet illustrates diverging behaviors between Octave and MatLab

EXAMPLE

genvarname("foo ")
genvarname('bar ')

RESULTS

Gives the following result under Octave:

and the following one under MatLab:

VERSION

Tested with Octave :

  • v4.0.3;
  • v4.2.1 (1a8b7b3ae5f2);

and MatLab v2017a

PATCH

is a suggested patch.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #42971:  52488.cset added by stevietodd (4KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by stevietodd (Updated the item)
  • -email is unavailable- added by motius (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-01-19 stevietodd Attached File- => Added 52488.cset, #42971
    2017-11-25 philipnienhuis Release4.2.1 => dev
        Operating SystemGNU/Linux => Any
    2017-11-23 rik5 Summarygenvarname substitutes underscore to invalid characters in string => genvarname substitutes underscore for invalid characters in string
    2017-11-23 rik5 Severity3 - Normal => 2 - Minor
        Priority5 - Normal => 1 - Later
        StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.3