Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.