GithubHelp home page GithubHelp logo

codeformatter's People

Contributors

lshifr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

codeformatter's Issues

CodeFormatterPrint sometimes produces unparsable code

I'd like to use CodeFormatterPrint to serialize definitions and a canonical but readable way. For this, all the code it produces should, when evaluated, restore the definitions I had in place.

But this does not always work:

ClearAll@f
f[veryveryveryveryveryveryveryverylongname, 
    veryveryveryveryveryveryveryverylongname] /; a > 0 := a;
CodeFormatterPrint@f

produces

f[    
     veryveryveryveryveryveryveryverylongname,
     veryveryveryveryveryveryveryverylongname
 ]
/;
  (a > 0) :=
     a

which cannot be parsed correctly because /; stands on its own.

/; should be at the end of the line above such that the expression is not yet complete.

Power[a, b] throws $Failed

a^b or Power[a, b] throws $Failed. Maybe typesetting boxes (like SuperscriptBox here and FractionBox in scdevries's example) should all be avoided?

Weird formatting of divisions

Formatting of fractions in the code can become rather weird:

Join[Total[
Join[1/2 Differences[
VeryLongFunctionNameVeryLongFunctionNameVeryLongFunctionName],
Most[defaults]]]/
Total[Join[1/2 Differences[optimal], Most[optimal]]], a]

Documentation and more descriptive naming of functions & simplified interfaces, proper error reporting & catching needed

CodeFormatterPrint should IMO be named something like PrettyPrintSymbolDefintions.

I don't think the names should include CodeFormatter as they are already in that package. Maybe have prefixes to avoid conflicts.

FullCodeFormat and consorts should IMO also accept non-box form expressions and do the conversion themselves.

Full documentation (with F1-ability) would also be nice once this matures some more.

Uncaught exception when using colorsetters as part of the code

Mathematica allows the use of colorsetters as part of the code (so that the programmer can conveniently choose a new color right in the middle of the source by just clicking). A line of code may read like this:

edgeColor = !(*
TagBox[
ColorSetterBox[RGBColor[1., 0., 0.], "Swatch"],
Setting]);

One enters this by DynamicSetting[ColorSetter[]] and executing-in-place (ctrl-shift-enter). Prettifying a line like this yields:

During evaluation of In[164]:= Throw::nocatch: Uncaught Throw[{$Failed,ColorSetterBox[RGBColor[1.,0.,0.],Swatch]},CodeFormatterPrivatepreformat] returned to top level. >>

Out[164]= Hold[
Throw[{$Failed, ColorSetterBox[RGBColor[1., 0., 0.], "Swatch"]},
CodeFormatterPrivatepreformat]]

[I know this is perverse coding]

Replacement of images

This may or may not be considered an issue: bitmaps used as part of the source code (which mathematica happily allows and advocates) are replaced with elaborate Image functions.

CodeFormatterPrint output differs from FullCodeFormat

From the code it seems as if CodeFormatterPrint uses FullCodeFormat, but on a given definition their output still differs:

ClearAll[f]
f[x : _a | _b] := 0;
CodeFormatterPrint@f
f[x : (Blank[a] | Blank[b])] :=
     0

is not as nice as

boxes = MakeBoxes[f[x : _a | _b] := 0];
prn = CellPrint[Cell[BoxData[#], "Input"]] &;
prn@FullCodeFormat@boxes
f[x : _a | _b] :=
     0

This Table-Piecewise expression causes an uncaught exception

FullCodeFormat@MakeBoxes@Table[Piecewise[{

      {1.999, -Pi < \[Theta] < -7 Pi/8},
      {(2 Sin[-6 Pi/7])/
        Sin[\[Theta]], -6 Pi/
          7 < \[Theta] < -2.0909003694838066`}, {1.001, \
-2.26998149133592` < \[Theta] < -0.6662394324925154`},
      {(2 Sin[-(Pi/10)])/
        Sin[\[Theta]], -0.6662394324925154` < \[Theta] < -(Pi/10)},
      {1.999, -(Pi/8) < \[Theta] < 0}

      }, 1.999]

    , {\[Theta], -1. Pi, 0., ds}
    ];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.