Azzera filtri
Azzera filtri

Strange limitations on script files?

3 visualizzazioni (ultimi 30 giorni)
Klaus-Dieter
Klaus-Dieter il 22 Set 2023
Risposto: Walter Roberson il 23 Set 2023
Just wanted to clarify: Are there specific reasons to enforce scripts to
  • have function definitions only at the end of the file
  • disallow classdef in script files
?
This feels especially unnatural in live scripts, where it disallows naturally adding functions or data structures in the course of the document.
  1 Commento
dpb
dpb il 22 Set 2023
I have absolutely no inside knowledge, but I would presume the reason is to make the parsing/compilation of code simpler by minimizing complexity.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 23 Set 2023
  • Not allowing function definitions in the middle of a script file removes ambiguity about whether code after a function definition is there accidentally (such as if there is an extra end in the code)
  • requiring that classdef be the only (non-comment) thing in the file removes ambiguity about what exactly is executed when the class is defined or invoked.

Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by