File tree Expand file tree Collapse file tree 3 files changed +21
-35
lines changed Expand file tree Collapse file tree 3 files changed +21
-35
lines changed Original file line number Diff line number Diff line change 1
1
## [ Unreleased]
2
2
3
3
- Correctly serialize nested superscripts, e.g. ` x^{y^z} ` .
4
+ - The result of evaluation a ` Hold ` expression is now the expression itself.
5
+ - To prevent evaluation of an expression temporarily, use the ` Unevaluated `
6
+ function. The result of evaluating an ` Unevaluated ` expression is its
7
+ argument.
8
+ - The type of a ` Hold ` expression was incorrectly returned as ` string ` . It now
9
+ return the type of its argument.
4
10
5
11
## 0.26.4 _ 2024-10-17_
6
12
Original file line number Diff line number Diff line change @@ -1004,36 +1004,6 @@ function type(expr: BoxedExpression): Type | undefined {
1004
1004
// The value is a function expression
1005
1005
//
1006
1006
if ( expr . ops ) {
1007
- // If we're a Hold operator, the type is a `function`
1008
- if ( expr . operator === 'Hold' ) {
1009
- const [ op ] = expr . ops ! ;
1010
- if ( op . symbol ) return 'symbol' ;
1011
- if ( op . string !== undefined ) return 'string' ;
1012
- if ( op . isNumberLiteral ) return op . type ;
1013
-
1014
- if ( op . isFunctionExpression ) {
1015
- const def = op . functionDefinition ;
1016
- if ( def ) {
1017
- const type = def . signature ;
1018
-
1019
- if ( typeof type !== 'string' && type . kind === 'signature' ) {
1020
- // Compute the result type based on the arguments
1021
- // Return a signature modified with the computed result type
1022
- return {
1023
- ...type ,
1024
- result :
1025
- parseType ( def . type ?.( op . ops ! , { engine : expr . engine } ) ) ??
1026
- type . result ,
1027
- } ;
1028
- }
1029
- return type ;
1030
- }
1031
- }
1032
-
1033
- // For a Hold function, the default type is 'function'
1034
- return 'function' ;
1035
- }
1036
-
1037
1007
const def = expr . functionDefinition ;
1038
1008
if ( ! def ) return 'function' ;
1039
1009
Original file line number Diff line number Diff line change @@ -248,8 +248,18 @@ export const CORE_LIBRARY: IdentifierDefinitions[] = [
248
248
} ,
249
249
} ,
250
250
251
+ Unevaluated : {
252
+ description : 'Prevent an expression from being evaluated' ,
253
+ // Unlike Hold, the argume is canonicalized
254
+ hold : false ,
255
+ signature : 'any -> any' ,
256
+ type : ( [ x ] ) => x . type ,
257
+ evaluate : ( [ x ] ) => x ,
258
+ } ,
259
+
251
260
Hold : {
252
- description : 'Hold an expression, preventing it from being evaluated' ,
261
+ description :
262
+ 'Hold an expression, preventing it from being canonicalized or evaluated' ,
253
263
hold : true ,
254
264
signature : 'any -> any' ,
255
265
type : ( [ x ] ) => {
@@ -259,11 +269,11 @@ export const CORE_LIBRARY: IdentifierDefinitions[] = [
259
269
if ( x . ops ) return functionSignature ( x . type ) ?? 'function' ;
260
270
return 'expression' ;
261
271
} ,
262
- // By definition, arguments of the canonical expression of
272
+ // By definition, the argument of the canonical expression of
263
273
// `Hold` are not canonicalized.
264
- canonical : ( args , { engine : ce } ) =>
265
- args . length !== 1 ? null : ce . hold ( args [ 0 ] ) ,
266
- evaluate : ( [ x ] ) => x ,
274
+ canonical : ( args , { engine } ) =>
275
+ args . length !== 1 ? null : engine . hold ( args [ 0 ] ) ,
276
+ evaluate : ( [ x ] , { engine } ) => engine . hold ( x ) ,
267
277
} ,
268
278
269
279
HorizontalSpacing : {
You can’t perform that action at this time.
0 commit comments