abelsiqueira / DiceRolls.jl

Julia package defining dice and operations with them
Other
9 stars 4 forks source link

Allow subtractions #12

Open rongcuid opened 2 years ago

rongcuid commented 2 years ago

Currently there is no operator for subtracting dice:

roll(d100 - d100)
ERROR: MethodError: no method matching -(::Dice, ::Dice)
Closest candidates are:
  -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_types/thunks.jl:32
  -(::ChainRulesCore.NoTangent, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_arithmetic.jl:61
  -(::ChainRulesCore.ZeroTangent, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_arithmetic.jl:101
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[23]:1

It would be great to add such functionality.

abelsiqueira commented 2 years ago

That would be a good addition, thanks for the suggestion. For now, you can get the same result with

roll = CompositeRoll([1d10, 1d10], 0, x -> x[1] - x[2])

This could also be one of the ways to implement it, in case you want to give it a try.