@@ -600,8 +600,8 @@ protected static IExpr loadPackage(final EvalEngine engine, final String is) {
600
600
try {
601
601
final List <ASTNode > node = parseReader (is , engine );
602
602
return evaluatePackage (node , engine );
603
- } catch (final Exception e ) {
604
- LOGGER . error ( "Get.loadPackage() failed" , e );
603
+ } catch (final RuntimeException rex ) {
604
+ Errors . printMessage ( S . Get , rex , engine );
605
605
}
606
606
return S .Null ;
607
607
}
@@ -1188,6 +1188,70 @@ public int[] expectedArgSize(IAST ast) {
1188
1188
}
1189
1189
}
1190
1190
1191
+ /**
1192
+ * <pre>
1193
+ * <code>Save("path-to-filename", expression)
1194
+ * </code>
1195
+ * </pre>
1196
+ *
1197
+ * <p>
1198
+ * if the file system is enabled, export the <code>FullDefinition</code> of the
1199
+ * <code>expression</code> to the "path-to-filename" file. The saved file can be
1200
+ * imported with <code>Get</code>.
1201
+ * </p>
1202
+ *
1203
+ * <pre>
1204
+ * <code>Save("path-to-filename", "Global`*")
1205
+ * </code>
1206
+ * </pre>
1207
+ *
1208
+ * <p>
1209
+ * if the file system is enabled, export the <code>FullDefinition</code> of all symbols in the
1210
+ * <code>"Global</code>*"` context to the "path-to-filename" file.
1211
+ * </p>
1212
+ *
1213
+ * <h3>Examples</h3>
1214
+ * <p>
1215
+ * Save a definition with dependent symbol definitions into temporary file
1216
+ * </p>
1217
+ *
1218
+ * <pre>
1219
+ * <code>>> g(x_) := x^3;
1220
+ *
1221
+ * >> g(x_,y_) := f(x,y);
1222
+ *
1223
+ * >> SetAttributes(f, Listable);
1224
+ *
1225
+ * >> f(x_) := g(x^2);
1226
+ *
1227
+ * >> temp = FileNameJoin({$TemporaryDirectory, \"savedlist.txt\"});Print(temp);
1228
+ *
1229
+ * >> Save(temp, {f,g})
1230
+ *
1231
+ * >> ClearAll(f,g)
1232
+ *
1233
+ * >> "Attributes(f)
1234
+ *
1235
+ * >> {f(2),g(7)}
1236
+ *
1237
+ * >> Get(temp)
1238
+ *
1239
+ * >> {f(2),g(7)}
1240
+ * {64,343}
1241
+ *
1242
+ * >> Attributes(f)
1243
+ * {Listable}
1244
+ * </code>
1245
+ * </pre>
1246
+ *
1247
+ * <h3>Related terms</h3>
1248
+ * <p>
1249
+ * <a href="BinaryDeserialize.md">BinaryDeserialize</a>,
1250
+ * <a href="BinarySerialize.md">BinarySerialize</a>, <a href="ByteArray.md">ByteArray</a>,
1251
+ * <a href="ByteArrayQ.md">ByteArrayQ</a>, <a href="Export.md">Export</a>,
1252
+ * <a href="Import.md">Import</a>
1253
+ * </p>
1254
+ */
1191
1255
private static final class Save extends AbstractFunctionEvaluator {
1192
1256
1193
1257
@ Override
@@ -1210,7 +1274,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
1210
1274
boolean ignoreCase = false ;
1211
1275
symbolsList = IOFunctions .getSymbolsByPattern (arg2 , ignoreCase , ast , engine );
1212
1276
}
1213
- if (symbolsList .isPresent ()) {
1277
+ if (symbolsList .isPresent ()) {
1214
1278
String str = ISymbol .fullDefinitionListToString (symbolsList );
1215
1279
try (FileWriter writer = new FileWriter (fileName .toString ())) {
1216
1280
writer .write (str );
@@ -1377,8 +1441,13 @@ private static IExpr evaluatePackageRecursive(final List<ASTNode> node, int i,
1377
1441
result = evaluatePackageRecursive (((FunctionNode ) astNode ), 1 , compoundExpression , ast2Expr ,
1378
1442
engine );
1379
1443
} else {
1380
- temp = ast2Expr .convert (astNode );
1381
- result = engine .evaluate (temp );
1444
+ try {
1445
+ temp = ast2Expr .convert (astNode );
1446
+ result = engine .evaluate (temp );
1447
+ } catch (final RuntimeException rex ) {
1448
+ result = S .Null ;
1449
+ Errors .printMessage (S .Get , rex , engine );
1450
+ }
1382
1451
}
1383
1452
i ++;
1384
1453
}
0 commit comments