multiline comments

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

multiline comments

Søren Hauberg
Hi everybody
Is multiline comments supported in Octave?

/Søren



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: multiline comments

Geordie McBain
> Is multiline comments supported in Octave?

Using short-circuit Boolean operators like

        octave> 1||[
        > blah
        > blah blah
        > ];
        octave>

does the job.  Doesn't really recommend itself as a comment syntax
though, does it?  I think I recall reading something like this idea on
this list a while ago but can't find it now, and can't remember
whether anything less monstrous was suggested.

Geordie McBain
www.aeromech.usyd.edu.au/~mcbain



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: multiline comments

Quentin Spencer
Geordie McBain wrote:

>>Is multiline comments supported in Octave?
>>    
>>
>
>Using short-circuit Boolean operators like
>
> octave> 1||[
> > blah
> > blah blah
> > ];
> octave>
>
>does the job.  Doesn't really recommend itself as a comment syntax
>though, does it?  I think I recall reading something like this idea on
>this list a while ago but can't find it now, and can't remember
>whether anything less monstrous was suggested.
>  
>
I'm not sure if this is what was meant in the original question, but
Matlab 7 now supports block comments of the form
%{
   commented stuff here
%}

As far as I know this has not yet been implemented in octave. It may be
implemented eventually, but I think it's a low priority for those most
actively involved in octave development. I'm sure John would welcome a
patch to support this. Unfortunately I'm not familiar enough with
octave's parser to attempt this. In the mean time, as Geordie suggests,
there are other workaraounds (my preferred one is if(0) ... end).
-Quentin



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: multiline comments

John W. Eaton-6
On 15-Apr-2005, Quentin Spencer <[hidden email]> wrote:

| I'm not sure if this is what was meant in the original question, but
| Matlab 7 now supports block comments of the form
| %{
|    commented stuff here
| %}
|
| As far as I know this has not yet been implemented in octave.

Right.  Well, it is a relatively new addition.

| It may be
| implemented eventually, but I think it's a low priority for those most
| actively involved in octave development. I'm sure John would welcome a
| patch to support this.

Sure, it should not be too hard.  Most of the changes would be in
src/lex.l.  Some possible complications are

  * Do these comments nest?  Do you get this behavior:

      %{ 1
      %{ 2
      %} matches 2
      %} matches 1

   or

      %{ 1
      %{ 2
      %} matches 1
      %} error, warning, or just ignored (it is a valid comment)

  * You must save the text of these comments as you read them, so that
    they can be printed by the parse tree printing code, and you must
    modify the printing code to properly emit the saved comments.

  * You must maintain the line and column number information recorded
    by the lexer when you read the comments.

| Unfortunately I'm not familiar enough with  
| octave's parser to attempt this. In the mean time, as Geordie suggests,
| there are other workaraounds (my preferred one is if(0) ... end).

Yes, if(0) endif is the more common way of faking block comments.  The
disadvantage is that the text inside the if(0) endif block must be
valid code.  In a block comment, you could have anything except "%}"
at the beginning of a line.

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: multiline comments

David Bateman-3
John W. Eaton wrote:

>On 15-Apr-2005, Quentin Spencer <[hidden email]> wrote:
>
>| I'm not sure if this is what was meant in the original question, but
>| Matlab 7 now supports block comments of the form
>| %{
>|    commented stuff here
>| %}
>|
>| As far as I know this has not yet been implemented in octave.
>
>Right.  Well, it is a relatively new addition.
>
>| It may be
>| implemented eventually, but I think it's a low priority for those most
>| actively involved in octave development. I'm sure John would welcome a
>| patch to support this.
>
>Sure, it should not be too hard.  Most of the changes would be in
>src/lex.l.  Some possible complications are
>
>  * Do these comments nest?  Do you get this behavior:
>
>      %{ 1
>      %{ 2
>      %} matches 2
>      %} matches 1
>
>   or
>
>      %{ 1
>      %{ 2
>      %} matches 1
>      %} error, warning, or just ignored (it is a valid comment)
>
>  
>


Running the function

function nest ()
  %{
  disp("1");
  %{
  disp("2");
  %}
  disp("3");
  %}
end

on matlab v7sp2 displays nothing, so the first case is the way matlab
implements it, and this makes more sense, as you can comment a large
part of already commented code.

>  * You must save the text of these comments as you read them, so that
>    they can be printed by the parse tree printing code, and you must
>    modify the printing code to properly emit the saved comments.
>
>  * You must maintain the line and column number information recorded
>    by the lexer when you read the comments.
>
>| Unfortunately I'm not familiar enough with  
>| octave's parser to attempt this. In the mean time, as Geordie suggests,
>| there are other workaraounds (my preferred one is if(0) ... end).
>
>Yes, if(0) endif is the more common way of faking block comments.  The
>disadvantage is that the text inside the if(0) endif block must be
>valid code.  In a block comment, you could have anything except "%}"
>at the beginning of a line.
>
>jwe
>
>
>
>-------------------------------------------------------------
>Octave is freely available under the terms of the GNU GPL.
>
>Octave's home on the web:  http://www.octave.org
>How to fund new projects:  http://www.octave.org/funding.html
>Subscription information:  http://www.octave.org/archive.html
>-------------------------------------------------------------
>
>  
>



--
David Bateman                                [hidden email]
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: multiline comments

Quentin Spencer
In reply to this post by John W. Eaton-6
John W. Eaton wrote:

>  * Do these comments nest?  Do you get this behavior:
>
>      %{ 1
>      %{ 2
>      %} matches 2
>      %} matches 1
>
>   or
>
>      %{ 1
>      %{ 2
>      %} matches 1
>      %} error, warning, or just ignored (it is a valid comment)
>  
>
OK, I did some tests to see how it all behaves. The first thing I
discovered is that
%{ text here
is not a valid block comment;  the characters "%{" must appear on a line
by themselves (white space before or after is OK). It also appears that
the comments do nest. I tested the following code with no errors:

%{  
  block-commented text
  %{
    nested block-commented text
  %}
  is this still block-commented?
%}

Deleting the final %} gives the error:
"Unterminated %{ block. Use %} to terminate."

>...
>Yes, if(0) endif is the more common way of faking block comments.  The
>disadvantage is that the text inside the if(0) endif block must be
>valid code.  In a block comment, you could have anything except "%}"
>at the beginning of a line.
>  
>
Yes, I've noticed that as well.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------