Open rocky opened 1 month ago
@rocky, in mathics.builtin.string.operations
, the Builtin StringReplace
has a doctest with that form:
StringReplace acts on lists of strings too:
>> StringReplace[{"xyxyxxy", "yxyxyxxxyyxy"}, "xy" -> "A"]
= {AAxA, yAAxxAyA}
Can you paste the example that does not work,here?
@rocky, in
mathics.builtin.string.operations
, the BuiltinStringReplace
has a doctest with that form:StringReplace acts on lists of strings too: >> StringReplace[{"xyxyxxy", "yxyxyxxxyyxy"}, "xy" -> "A"] = {AAxA, yAAxxAyA}
Can you paste the example that does not work,here?
One place you can get ChemTools from git is https://github.com/b3m2a1/mathematica-ChemTools.git
When I try loading I see:
In[1]:= Get["/tmp/github/mathematica-ChemTools/ChemToolsLoader.m", Trace->True]
Reading file: /tmp/github/mathematica-ChemTools/ChemToolsLoader.m
3:
4: (* ::Text::GrayLevel[0.5]:: *)
7:
8: Unprotect[ChemTools`PackageScope`Private`$TopLevelLoad];
11:
12: BeginPackage["ChemTools`"];
14:
15: ClearAll[ChemTools];
18:
19: (* ::Subsubsection::Closed:: *)
22:
23: System`Private`NewContextPath@
StringReplace::strse: String or list of strings expected at position 1 in StringReplace[FileNameDrop[{/tmp/github/mathematica-ChemTools/Packages/Compute, /tmp/github/mathematica-ChemTools/Packages/Compute/Structural.m, /tmp/github/mathematica-ChemTools/Packages/Compute/Symmetry.m, /tmp/github/mathematica-ChemTools/Packages/DVR, /tmp/github/mathematica-ChemTools/Packages/DVR/DVR.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Class.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Class.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Grid.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Grid.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/GuessWavefunctions.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/GuessWavefunctions.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/KineticEnergy.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/KineticEnergy.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Object.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Object.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Plots.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Plots.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/PotentialEnergy.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/PotentialEnergy.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/PotentialOptimization.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/PotentialOptimization.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/ResultsObject.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/ResultsObject.nb, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Wavefunctions.m, /tmp/github/mathematica-ChemTools/Packages/DVR/Package/Wavefunctions.nb, /tmp/github/mathematica-ChemTools/Packages/Data, /tmp/github/mathematica-ChemTools/Packages/Data/CharacterTables, /tmp/github/mathematica-ChemTools/Packages/Data/CharacterTables/CharacterTables.m, /tmp/github/mathematica-ChemTools/Packages/Data/CharacterTables/CharacterTables.nb, /tmp/github/mathematica-ChemTools/Packages/Data/CharacterTables/Package, /tmp/github/mathematica-ChemTools/Packages/Data/CharacterTables/Package/Package.m, /tmp/github/mathematica-ChemTools/Packages/Data/ChemSpider, /tmp/github/mathematica-ChemTools/Packages/Data/ChemSpider/ChemSpider.m, /tmp/github/mathematica-ChemTools/Packages/Data/ChemSpider/ChemSpider.nb, /tmp/github/mathematica-ChemTools/Packages/Data/DataFramework.m, /tmp/github/mathematica-ChemTools/Packages/Data/DataSources.m, /tmp/github/mathematica-ChemTools/Packages/Data/PubChem, /tmp/github/mathematica-ChemTools/Packages/Data/PubChem/PubChem.m, /tmp/github/mathematica-ChemTools/Packages/Data/PubChem/PubChem.nb, /tmp/github/mathematica-ChemTools/Packages/Data/RawDatasets, /tmp/github/mathematica-ChemTools/Packages/Data/RawDatasets/Datasets.m, /tmp/github/mathematica-ChemTools/Packages/Data/RawDatasets/Datasets.nb, /tmp/github/mathematica-ChemTools/Packages/DataStructures, /tmp/github/mathematica-ChemTools/Packages/DataStructures/GridFunctionObject.m, /tmp/github/mathematica-ChemTools/Packages/DataStructures/GridObject.m, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/GridFunctions.m, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/GridFunctions.nb, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/GridTools.m, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/GridTools.nb, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/Plotting, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/Plotting/GFPlotCore.m, /tmp/github/mathematica-ChemTools/Packages/DataStructures/Package/Plotting/GridFunctions.m, /tmp/github/mathematica-ChemTools/Packages/Experimental, /tmp/github/mathematica-ChemTools/Packages/Experimental/Cystallography.m, /tmp/github/mathematica-ChemTools/Packages/Experimental/Inorganic.m, /tmp/github/mathematica-ChemTools/Packages/Experimental/PES.m, /tmp/github/mathematica-ChemTools/Packages/Extensions, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/CMake.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/CMake.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Eigen.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Eigen.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Swig.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Swig.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Utils.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/Build/Utils.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/OpenBabel, /tmp/github/mathematica-ChemTools/Packages/Extensions/OpenBabel/OpenBabelConnection.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/OpenBabel/OpenBabelConnection.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/Psi4, /tmp/github/mathematica-ChemTools/Packages/Extensions/Psi4/Psi4Connection.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/Psi4/Psi4Connection.nb, /tmp/github/mathematica-ChemTools/Packages/Extensions/SP, /tmp/github/mathematica-ChemTools/Packages/Extensions/SP/SPConnection.m, /tmp/github/mathematica-ChemTools/Packages/Extensions/SP/SPConnection.nb, /tmp/github/mathematica-ChemTools/Packages/Formats, /tmp/github/mathematica-ChemTools/Packages/Formats/Formats.m, /tmp/github/mathematica-ChemTools/Packages/Formats/Package, /tmp/github/mathematica-ChemTools/Packages/Formats/Package/FormatsPackage.m, /tmp/github/mathematica-ChemTools/Packages/Formats/Package/FormatsPackage.nb, /tmp/github/mathematica-ChemTools/Packages/Graphics, /tmp/github/mathematica-ChemTools/Packages/Graphics/Graphics.m, /tmp/github/mathematica-ChemTools/Packages/Graphics/Objects, /tmp/github/mathematica-ChemTools/Packages/Graphics/Objects/GraphicsObjects.m, /tmp/github/mathematica-ChemTools/Packages/Graphics/Objects/GraphicsObjects.nb, /tmp/github/mathematica-ChemTools/Packages/Import, /tmp/github/mathematica-ChemTools/Packages/Import/CubeFiles.m, /tmp/github/mathematica-ChemTools/Packages/Import/ElectronicStructure.m, /tmp/github/mathematica-ChemTools/Packages/Import/Import.m, /tmp/github/mathematica-ChemTools/Packages/Import/__Pre__.m, /tmp/github/mathematica-ChemTools/Packages/Objects, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Atom.m, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Atom.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Atomset.m, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Atomset.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Bond.m, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Bond.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/Group.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/ObjectFramework.m, /tmp/github/mathematica-ChemTools/Packages/Objects/ObjectFramework/ObjectFramework.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/Objects.m, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/GeometricAtomsets.m, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/GeometricAtomsets.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/Import.m, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/Import.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/ObjectUtils.m, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/ObjectUtils.nb, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/__Pre__.m, /tmp/github/mathematica-ChemTools/Packages/Objects/Utilities/__Pre__.nb, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Handling.m, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Handling.nb, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Import.m, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Import.nb, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Object.m, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Object.nb, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Plotting.m, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Package/Plotting.nb, /tmp/github/mathematica-ChemTools/Packages/Spectroscopy/Spectroscopy.m, /tmp/github/mathematica-ChemTools/Packages/Utilities, /tmp/github/mathematica-ChemTools/Packages/Utilities/Compile.m, /tmp/github/mathematica-ChemTools/Packages/Utilities/HOrbitals.m, /tmp/github/mathematica-ChemTools/Packages/Utilities/UnitConvert.m, /tmp/github/mathematica-ChemTools/Packages/Utilities/Utilities.m, /tmp/github/mathematica-ChemTools/Packages/WSim, /tmp/github/mathematica-ChemTools/Packages/WSim/Package, /tmp/github/mathematica-ChemTools/Packages/WSim/Package/Class.m, /tmp/github/mathematica-ChemTools/Packages/WSim/Package/Class.nb, /tmp/github/mathematica-ChemTools/Packages/WSim/Package/Manager.m, /tmp/github/mathematica-ChemTools/Packages/WSim/Package/Manager.nb, /tmp/github/mathematica-ChemTools/Packages/WSim/WSim.m, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/Package, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/Package/Plotting, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/Package/Plotting/Wavefunctions.m, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/Package/WavefunctionTools.m, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/Package/WavefunctionTools.nb, /tmp/github/mathematica-ChemTools/Packages/Wavefunctions/WavefunctionsObject.m}, 4], / → `].
StringJoin::string: String expected.
Join::heads: Heads List and Select[DirectoryQ[#1] ∧ StringMatchQ[StringReplace[FileNameDrop[#1, FileNameDepth[DirectoryName[$InputFileName]]], $PathnameSeparator → `], ($ | WordCharacter)..]&] are expected to be the same.
Here, the problem is not in StringReplace, but in FileNameDrop
(https://reference.wolfram.com/language/ref/FileNameDrop.html) which is not already implemented in Mathics.
Looking at https://github.com/Mathics3/mathics-core/tree/add-FileNameDrop, the problem is that you didn't implement FileNameDrop
acting over lists.
@rocky, just add this rule
"FileNameDrop[list_List, parms___]": "FileNameDrop[#1,parms]&/@list"
to the rule list of your implementation of FileNameDrop
Then, this example works:
StringReplace[FileNameDrop[{"/tmp/github/mathematica-ChemTools/Packages/Wavefunctions/WavefunctionsObject.m"}, 4], "/"->"`"]
@mmatera: adding this gives:
new_expression = apply_fn(expression, vars, options, evaluation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/github/Mathics3/mathics3-debugger/pymathics/debugger/tracing.py", line 269, in <lambda>
lambda *args, **kwargs: traced_eval_method(
^^^^^^^^^^^^^^^^^^^
File "/tmp/github/Mathics3/mathics3-debugger/pymathics/debugger/tracing.py", line 242, in traced_eval_method
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/github/Mathics3/mathics-core/mathics/core/rules.py", line 354, in apply_function
return self.function(evaluation=evaluation, **vars_noctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FileNameDrop.eval_with_n_to_m() missing 1 required positional argument: 'm'
I have been looking into trying to run Mathematica Packages on https://paclets.github.io/PacletServer/ - I have been using the experimental debugger to help me find problems as well as guide what is needed in the debugger.)
For ChemTools,
ChemToolsLoader.m
uses the formStringReplace[{s1, s2, ...}, rules]
which we don't have implemented.NB: In a branch I have started implementing FileDrop which is also needed.