bugGNU Octave - Bugs: bug #44036, classdef classes can not be...


bug #44036: classdef classes can not be defined on the command line or in script files (only standalone files)

Submitted by:  Carnë Draug <carandraug>
Submitted on:  Sun 18 Jan 2015 03:26:31 PM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  3 - Low Item Group:  Feature Request
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  Closed
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)

Sun 03 Mar 2019 09:17:35 PM UTC, comment #7: 

I think that's fine, particularly given all the other improvements I would like to see in Octave ahead of this one.  Maybe at some point in the future this can be re-visited if some has free coding time AND it can be shown not create any architectural problems in the code.

Rik <rik5>
Project Administrator
Sun 03 Mar 2019 07:41:42 PM UTC, comment #6: 

I'm strongly leaning toward closing this as "Won't Fix" because it simplifies the implementation to not have to worry about classdef objects being defined anywhere except inside .m files that contain classdef blocks and that are named the same as the classdef object.

Matlab also requires that classdef constructors and all functions that use dots in their names, including "Converter methods that must use the package name as part of the class name because the class is contained in packages" and "Property set and get access methods".

Maybe these requirements are arbitrary and we could work around them.  But I'd rather not, unless we can prove without a doubt that defining classdef blocks in scripts or at the command line or putting the constructor in a separate file won't cause trouble for us in the future.

John W. Eaton <jwe>
Project Administrator
Mon 19 Jan 2015 01:57:48 PM UTC, comment #5: 

How important this is is obviouly a matter of opinion and
programming style. Everyone has their own of both.

So, does anyone know how hard it would be to implement
this? Obviously, if it is pretty easy it would be "nice."
And, if it is hard and time consuming it is not likely
to get done anyhow.

Michael Godfrey <godfrey>
Project Member
Mon 19 Jan 2015 12:45:02 PM UTC, comment #4: 

A simple usage case, which I believe is related to this, is being able to define a new class on an Octave program or script. We can do this in Octave (not in Matlab), and it's a great feature which allows us to write a program in a single file, i.e., something such as

#!/usr/bin/octave -qf

classdef new_class

function foobar ()

## a much nicer programming language

Also, being able to define things at the prompt is very handy while writing code. One probably won't create new classdef at the prompt to work on real time, but may do so to test one while writing it.

Carnë Draug <carandraug>
Project Member
Mon 19 Jan 2015 04:37:34 AM UTC, comment #3: 

Defining classes at the command line doesn't seem nearly as useful as functions.  A class is more likely to be long with properties and class methods and the chance of entering it correctly on the command line is pretty low.  It doesn't bother me that Octave doesn't allow this, but maybe there is a usage case I'm not seeing.

Rik <rik5>
Project Administrator
Sun 18 Jan 2015 06:30:02 PM UTC, comment #2: 

Why is not expected to work? Not implemented yet or not possible at all? Being able to define functions at the Octave prompt is a very handy feature missing in Matlab, would be nice if it was possible to also define classdef blocks.

Carnë Draug <carandraug>
Project Member
Sun 18 Jan 2015 05:42:29 PM UTC, comment #1: 

I don't think this is expected to work.

Do you want a better error message that says that classdef objects must be defined in files?

Looking at oct-parse.in.yy, I see:

classdef_beg    : CLASSDEF
                    if (! lexer.reading_classdef_file)
                        parser.bison_error ("classdef must appear inside a file containing only a class definition");

                    lexer.parsing_classdef = true;
                    $$ = $1;

I guess this message is somehow not being triggered for your example.

John W. Eaton <jwe>
Project Administrator
Sun 18 Jan 2015 03:26:31 PM UTC, original submission:  

Creating a new class with classdef in a file works fine but when trying to define a new class on the interpreter, Octave does not recognize it.

octave-gui:1> classdef new_class < handle
parse error:

  syntax error

>>> classdef new_class < handle

Carnë Draug <carandraug>
Project Member


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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by carandraug (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-03 rik5 StatusConfirmed => Wont Fix
        Open/ClosedOpen => Closed
    2019-03-03 rik5 Priority5 - Normal => 3 - Low
        Item GroupNone => Feature Request
        StatusNone => Confirmed
        Summaryinterpreter does not recognize classdef (syntax error) => classdef classes can not be defined on the command line or in script files (only standalone files)

    Back to the top

    Powered by Savane 3.6