maxitg / SetReplace

C++/Wolfram Language package for exploring set and graph rewriting systems
MIT License
216 stars 43 forks source link

Messages with Association arguments #606

Closed maxitg closed 3 years ago

maxitg commented 3 years ago

Changes

Comments

Examples

image image
expr : HalfInteger[x_] := ModuleScope[
  result = Catch[halfInteger[x], _ ? FailureQ, message[HalfInteger, #, <|"expr" -> HoldForm[expr]|>] &];
  result /; !FailureQ[result]
];

halfInteger[x_ ? EvenQ] := x / 2;

declareMessage[HalfInteger::odd, "The number `number` in `expr` is odd."];
halfInteger[x_ ? OddQ] := throw[Failure["odd", <|"number" -> x|>]];
In[] := HalfInteger[4]
Out[] = 2
In[] := HalfInteger[3]
During evaluation of In[] := HalfInteger::odd: The number 3 in HalfInteger[3] is odd.
Out[] = HalfInteger[3]

This change is Reviewable

maxitg commented 3 years ago

@taliesinb, @daneelsan, this is ready for review. I don't plan to implement anything else here.

maxitg commented 3 years ago

@taliesinb, @daneelsan, could you give an ETA on when can you look at this (I need it for Multihistory)?

daneelsan commented 3 years ago

@maxitg Looking at it now

daneelsan commented 3 years ago

It seems there is/was an attempt to make Message work with templates:

In[] := Message[MessageObject[<|"MessageSymbol" -> HoldForm[b], 
    "MessageTemplate" -> "Hello `world`!", 
    "MessageParameters" -> <|"world" -> 3|>|>]]; $Failed
Hello 3!

Out[] = $Failed