Last active
October 21, 2017 09:48
-
-
Save JEM-Mosig/b58aa55e2da5ffcd5e29e6ac93c5ed5a to your computer and use it in GitHub Desktop.
Simple code to estimate the compatibility of a Wolfram Language script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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