The Bot Bikeshed
-
@error_bot roll "let toHit=d20; let isCrit=toHit eq 20; let isHit=toHit ge 16; isHit: isHit; isCrit: isCrit; toHit: toHit"
-
isHit: trueisHit = trueisCrit: falseisCrit = falsetoHit: 19toHit = 19
-
-
@error_bot roll "let hitDie=d20; let isCrit=hitDie eq 20; hit: hitDie+6; damage: (isCrit ? 2 : 1)d6"
-
Error: lex failed; remaining: ? 2 : 1)d6; match: null
-
@error_bot roll "let hitDie=d20; let isCrit=hitDie eq 20; hit: hitDie+6; isCrit: isCrit; damage: ((1 + isCrit)*2)d6 + 4"
-
hit: 26hitDie (20) + 6 = 26isCrit: trueisCrit (true) = truedamage: 18((1 + isCrit (true)) * 2)d6 (6, 1, 4, 3) + 4 = 18
-
5e crit damage inline is unwieldy but I don't have a better solution offhand.
-
@PleegWat said in The Bot Bikeshed:
5e crit damage inline is unwieldy but I don't have a better solution offhand.
Multiplication by bools is an unintended feature. Congraturation.
-
@error Addition, actually. I tried
(isCrit ? 2 : 1)
but it balked.Maybe I could
let diceMul = 1 + isCrit
.
-
@PleegWat said in The Bot Bikeshed:
actually. I tried (isCrit ? 2 : 1) but it balked.
Yeah, ternary is on the roadmap but I haven't figured out the proper way to parse it.
-
@error with signum, addition, and multiplication you could forgo conditionals entirely - make people simulate the effect of booleans on an expression result with arithmetic, branchless style.
-
I could easily make Iif like Excel has. It would be eagerly evaluated, though.
-
Short circuit logic would just require some kind of Lazy wrapper on expression evaluation.
-
@error said in The Bot Bikeshed:
Short circuit logic would just require some kind of Lazy wrapper on expression evaluation.
yes. let the gloves flow through you.
-
isCrit ? 2 : 1
is an easy parse, but what aboutisCrit ? isSuper ? 3 : 2 : 1
?Maybe I just need to only allow one term on either side of
:
, and you can use brackets if you need something more complex.
-
Similarly:
d20 > 3 ? 1 : 0
gets the order of operations wrong, but if I do ternary after binary then what of1 + isCrit ? 1 : 0
...
-
It seems like it should be after comparison operators but before arithmetic, but right now there's no actual distinction (they're all "binary operators"). I guess I need to subdivide.
-
So arithmetic needs to come before comparison but after ternary, but comparison needs to come after arithmetic.
-
I guess the actual implementation is easy but without brackets the order of operations is going to be confusing at best.
-
Lazy evaluation and ternary together gives us recursive UDFs though.
-
@PleegWat said in The Bot Bikeshed:
@error_bot roll "let hitDie=d20; let isCrit=hitDie eq 20; hit: hitDie+6; isCrit: isCrit; damage: ((1 + isCrit)*2)d6 + 4"
It's also remarkable that your first test of crit logic (that compiled) was actually a crit.
-
@PleegWat said in The Bot Bikeshed:
5e crit damage inline is unwieldy but I don't have a better solution offhand.
It's also really trivial for me to implement builtin functions if you need them, which can be as simple or as complex as you like.
-
@error How about following popular programming languages?
Just remember to not do a PHP,
a ? b : c ? d : e
isa ? b : (c ? d : e)
not(a ? b : c) ? d : e
.
-
@error 5e crits double all dice counts in the damage roll.
-
@PleegWat Huh, not what I expected. I'll try it after binary then. Unary, binary, ternary makes a certain kind of sense.
-
@error said in The Bot Bikeshed:
@PleegWat said in The Bot Bikeshed:
5e crit damage inline is unwieldy but I don't have a better solution offhand.
It's also really trivial for me to implement builtin functions if you need them, which can be as simple or as complex as you like.
THAC0?
-
@error said in The Bot Bikeshed:
@PleegWat Huh, not what I expected. I'll try it after binary then. Unary, binary, ternary makes a certain kind of sense.
It's the exact opposite of 3.5 and all precedent. But, it's cohesively documented now, which helps.
-
@PleegWat said in The Bot Bikeshed:
Just remember to not do a PHP, a ? b : c ? d : e is a ? b : (c ? d : e) not (a ? b : c) ? d : e.
Right to left associativity? I can probably do that. But just use brackets instead of writing something ambiguous looking.
-
@error So you're saying you're going to repeat PHP's mistakes?
-
@PleegWat said in The Bot Bikeshed:
@error So you're saying you're going to repeat PHP's mistakes?
I just said I can do it right-to-left as requested, but I feel anyone writing expressions like that without brackets is
.
-
@error_bot eval def fib(n) => n le 1 ? 1 : fib(n-1) + fib(n-2); 0: fib(0); 1: fib(1); 2: fib(2); 3: fib(3); 4: fib(4); 5: fib(5); 6: fib(6); 7: fib(7); 8: fib(8); 9: fib(9)
-
0: 1fib(0) = 11: 1fib(1) = 12: 2fib(2) = 23: 3fib(3) = 34: 5fib(4) = 55: 8fib(5) = 86: 13fib(6) = 137: 21fib(7) = 218: 34fib(8) = 349: 55fib(9) = 55
-
Conditionals! Recursion!
-
@error_bot roll "let toHit=d20; let isCrit=toHit == 20; damage: ( isCrit ? 4 : 2 )d8"
-
damage: 4(2)d8 (3, 1) = 4
-
@error_bot roll 2( 1d2 == 1 ? 2d20 : 3d20 + 1 )
-
682(1d2 (1) == 1 (true) ? 2d20 (19, 15: 34) : 3d20 + 1 (34)) (68) = 68
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; hotpo(1)
-
Error: lex failed; remaining: % 2 == 0 ? n / 2 : 3 * n + 1 ; hotpo(1); match: null
-
No
%
operator. XOR?
-
@error_bot eval def hotpo(n) => n mod 2 == 0 ? n / 2 : 3 * n + 1 ; hotpo(1)
-
Error: def statement should have 3 children
-
@error said in The Bot Bikeshed:
No
%
operator. XOR?modulus - trying to do Collatz / hailstone numbers
-
@Gribnit Just a second...
-
@Gribnit said in The Bot Bikeshed:
@error said in The Bot Bikeshed:
No
%
operator. XOR?modulus - trying to do Collatz / hailstone numbers
@error_bot eval 13 % 2; 12 mod 2
-
113 % 2 (1) = 1012 mod 2 (0) = 0
-
@error_bot eval def hotpo(n) => n mod 2 == 0 ? n / 2 : 3 * n + 1 ; hotpo(1)
-
4hotpo(1) (4) = 4
-
@error_bot eval def hotpo(n) => n % 2 == 0 ? n / 2 : 3 * n + 1 ; def collatz_descend(n, i) => n == 1 ? i : collatz_descend(hotpo(n), i + 1) ; def collatz(n) => collatz_descend(n, 0) ; collatz(7)