Re: use end or endif is indifferent?

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

Re: use end or endif is indifferent?

Luca Manzari
Octave already treats whatever follows % as a comment, so nothing
prevents you from writing end%if or end%for already. Doing so makes for
code that is both Octave and Matlab compatible.

/Luca

On 2018-11-29 14:43, Ardid Ramirez, Joan Salvador wrote:

>    Hello Sergei,
>    
>    this is correct for Octave, but please keep in mind that Matlab (2016a) does
>    not support "endif" and "endfor". So when you have to cooparate with people
>    using Matlab, you could instead use "end%if" and "end%for" which will
>    increase readability of your code, though you will losse Octave's advanced
>    diagnostic abilities as mentioned in your link.
>    
>
> Mmm, thinking about it, it would actually be great if Octave would accept end%if as an alias of endif and end%for as an alias of endfor. This would bring the best of the two worlds, keeping all Octave's goodness, while keeping Matlab compatibility.
>
> Sending it to maintainers to see if Octave Devs would consider this as a feasible option...
>
> ....
> a.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

Ardid Ramirez, Joan Salvador
El dijous, 29 de novembre de 2018, a les 10:17:15 EST, Luca Manzari va escriure:

  Octave already treats whatever follows % as a comment, so nothing
  prevents you from writing end%if or end%for already. Doing so makes for
  code that is both Octave and Matlab compatible.
 
  /Luca
 
  On 2018-11-29 14:43, Ardid Ramirez, Joan Salvador wrote:
  >    Hello Sergei,
  >    
  >    this is correct for Octave, but please keep in mind that Matlab (2016a) does
  >    not support "endif" and "endfor". So when you have to cooparate with people
  >    using Matlab, you could instead use "end%if" and "end%for" which will
  >    increase readability of your code, though you will losse Octave's advanced
  >    diagnostic abilities as mentioned in your link.
  >    
  >
  > Mmm, thinking about it, it would actually be great if Octave would accept end%if as an alias of endif and end%for as an alias of endfor. This would bring the best of the two worlds, keeping all Octave's goodness, while keeping Matlab compatibility.
  >
  > Sending it to maintainers to see if Octave Devs would consider this as a feasible option...
  >
  > ....
  > a.
  >
  >
 
I very well know about it, what I'm actually saying is whether Octave Devs would consider treating "end%if" as "endif" (and so on), so it can benefit in terms of error diagnostic. See below about this from up-to-date documentation (https://octave.org/doc/interpreter/Statements.html#index-end-statement):

"You can use the keyword end anywhere a more specific end keyword is expected, but using the more specific keywords is preferred because if you use them, Octave is able to provide better diagnostics for mismatched or missing end tokens."



Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

nrjank
In reply to this post by Luca Manzari


On Thu, Nov 29, 2018 at 10:17 AM Luca Manzari <[hidden email]> wrote:
Octave already treats whatever follows % as a comment, so nothing
prevents you from writing end%if or end%for already. Doing so makes for
code that is both Octave and Matlab compatible.


it's compatible, but as mentioned earlier using end instead of endif loses Octave's 'advanced diagnostic abilities'.  end%if is still just end as far as Octave is concerned.  I can't imagine, though, the level of interpreter changes that would be required to have it selectively parse something that would otherwise be handled as a comment, and the number of false parses this could generate.
Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

Ardid Ramirez, Joan Salvador

El dijous, 29 de novembre de 2018, a les 10:24:09 EST, Nicholas Jankowski va escriure:

  On Thu, Nov 29, 2018 at 10:17 AM Luca Manzari <[hidden email]> wrote:
 
  > Octave already treats whatever follows % as a comment, so nothing
  > prevents you from writing end%if or end%for already. Doing so makes for
  > code that is both Octave and Matlab compatible.
  >
  >
  it's compatible, but as mentioned earlier using end instead of endif loses
  Octave's 'advanced diagnostic abilities'.  end%if is still just end as far
  as Octave is concerned.  I can't imagine, though, the level of interpreter
  changes that would be required to have it selectively parse something that
  would otherwise be handled as a comment, and the number of false parses
  this could generate.


Fair enough :)



Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

Ardid Ramirez, Joan Salvador
In reply to this post by nrjank

El dijous, 29 de novembre de 2018, a les 10:24:09 EST, Nicholas Jankowski va escriure:

  On Thu, Nov 29, 2018 at 10:17 AM Luca Manzari <[hidden email]> wrote:
 
  > Octave already treats whatever follows % as a comment, so nothing
  > prevents you from writing end%if or end%for already. Doing so makes for
  > code that is both Octave and Matlab compatible.
  >
  >
  it's compatible, but as mentioned earlier using end instead of endif loses
  Octave's 'advanced diagnostic abilities'.  end%if is still just end as far
  as Octave is concerned.  I can't imagine, though, the level of interpreter
  changes that would be required to have it selectively parse something that
  would otherwise be handled as a comment, and the number of false parses
  this could generate.
 

I thought having end%if, %end%for, .and so on, as Octave's keywords would not imply much of a problem, I suppose I was just wrong :)


Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

Ardid Ramirez, Joan Salvador
  %end%for


Sorry, I meant end%for


Reply | Threaded
Open this post in threaded view
|

Re: use end or endif is indifferent?

Luca Manzari
In reply to this post by nrjank
Whops, apologies since I see that I missed the point -- and yeah it
would definitely be a plus.

Would there be any advantage in implementing the ability to parse
"special" comments?
I think of emacs local variables, where any comment block in whatever
language containing the strings "Local Variables:" and "End:" allows to
set file-specific variables. [1]

If this feature was worth adding, then one might have things like

end%<whateverSpecialIdentifier>if

Again, whether it's worth the effort I can't really say.

/Luca

[1]
https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html


On 2018-11-29 16:24, Nicholas Jankowski wrote:

>
>
> On Thu, Nov 29, 2018 at 10:17 AM Luca Manzari <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Octave already treats whatever follows % as a comment, so nothing
>     prevents you from writing end%if or end%for already. Doing so makes for
>     code that is both Octave and Matlab compatible.
>
>
> it's compatible, but as mentioned earlier using end instead of endif
> loses Octave's 'advanced diagnostic abilities'.  end%if is still just
> end as far as Octave is concerned.  I can't imagine, though, the level
> of interpreter changes that would be required to have it selectively
> parse something that would otherwise be handled as a comment, and the
> number of false parses this could generate.