Skip to content

Commit 2041ec5

Browse files
committed
add recursiveNatToString
1 parent 49ed9f9 commit 2041ec5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Applib/Show.juvix

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Applib.Show;
2+
3+
import Stdlib.Prelude open;
4+
import Stdlib.Math open;
5+
6+
--- non-builtin equivalent of ;natToString;
7+
terminating
8+
recursiveNatToString (n : Nat) : String :=
9+
let
10+
showDigit (d : Nat) : String :=
11+
if
12+
| d == 0 := "0"
13+
| d == 1 := "1"
14+
| d == 2 := "2"
15+
| d == 3 := "3"
16+
| d == 4 := "4"
17+
| d == 5 := "5"
18+
| d == 6 := "6"
19+
| d == 7 := "7"
20+
| d == 8 := "8"
21+
| d == 9 := "9"
22+
| else := "impossible";
23+
in if
24+
| n < 10 := showDigit n
25+
| else := recursiveNatToString (div n 10) ++ showDigit (mod n 10);

BaseLayer/ResourceMachine.juvix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module BaseLayer.ResourceMachine;
22

33
import BaseLayer.AnomaAtom open public;
4+
import Applib.Show open;
45
import Anoma.Encode open;
56
import Stdlib.Debug open;
67
import Anoma.Builtin.System open;
@@ -215,7 +216,10 @@ with
215216
| else :=
216217
trace "bytearraysize: "
217218
>-> trace (ByteArray.size b)
218-
>-> failwith "Nonce.fromByteArray incorrect size";
219+
>-> failwith
220+
("Nonce.fromByteArray incorrect size. Was passed a bytearray with size "
221+
++ recursiveNatToString (ByteArray.size b)
222+
++ ".");
219223

220224
from32SizedByteArray : ByteArray -> Nonce := fromByteArray;
221225

0 commit comments

Comments
 (0)