Skip to content

Instantly share code, notes, and snippets.

@JEM-Mosig
Last active October 21, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEM-Mosig/b58aa55e2da5ffcd5e29e6ac93c5ed5a to your computer and use it in GitHub Desktop.
Save JEM-Mosig/b58aa55e2da5ffcd5e29e6ac93c5ed5a to your computer and use it in GitHub Desktop.
Simple code to estimate the compatibility of a Wolfram Language script
(* author: https://github.com/JEM-Mosig *)
(* example: CodeCompatibilityData["test.wl"] *)
ClearAll[CodeCompatibilityData];
CodeCompatibilityData[wlFile_String] := Module[{str, symbols},
(* read the whole file as a string *)
str = ReadString[wlFile];
(* delete all strings in the code *)
str = StringDelete[str,"\""~~Shortest[___]~~"\""];
(* delete all comments in the code (unsafe!) *)
str = StringDelete[str,"("~~"*"~~Shortest[___]~~"*"~~")"];
(* find all symbols (heuristically) *)
symbols = Select[
DeleteDuplicates@StringCases[str, WordCharacter..],
TrueQ@Not@StringMatchQ[#, NumberString]&
];
(* determine versions introduced and last modified *)
With[{
intro = Thread[symbols -> WolframLanguageData[symbols, "VersionIntroduced"]],
modi = Thread[symbols -> WolframLanguageData[symbols, "VersionLastModified"]]
},
(* create and return a dataset with this information *)
Dataset@Table[
<|
"Symbol" -> s,
"VersionIntroduced" -> (s/.intro),
"VersionLastModified" -> (s/.modi)
|>,
{s,symbols}
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment