diff --git a/docs/system.md b/docs/system.md index 1610b939..56805eb5 100644 --- a/docs/system.md +++ b/docs/system.md @@ -59,7 +59,7 @@ Get the hash of `𝕩`. Monadically, use the global secret value which will differ between CBQN sessions. -Dyadically, use the integer left argument as the secret. Will be the same between multiple CBQN sessions, but may change between versions. +Dyadically, use the integer left argument as the seed. Will be the same between multiple CBQN sessions, but may change between CBQN versions. ## `•PrimInd` @@ -75,7 +75,13 @@ Compare arguments. Equal to `((⊑⍋-⍒)⋈)`. Convert the argument UTF-8 byte array (or character array consisting of codepoints 0-255) to a string. -May be removed in the future. +May be removed or renamed in the future. + +## `•ToUTF8` + +Convert the argument character list to a UTF-8-encoded byte array, represented as a list of characters with codepoints 0-255. + +May be removed or renamed in the future. ## `•CurrentError` diff --git a/src/builtins.h b/src/builtins.h index 9749fa9a..bab03036 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -9,7 +9,7 @@ /* sort.c*/A(gradeUp,"⍋") A(gradeDown,"⍒") \ /* everything before the definition of •Type is defined to be pure, and everything after is not */ \ /* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•GroupOrd") \ -/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(currentError,"•CurrentError") \ +/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(toUtf8,"•ToUTF8") M(currentError,"•CurrentError") \ /* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime") M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \ /* sysfn.c*/M(fName,"•file.Name") M(fParent,"•file.Parent") \ /* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \ diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 4350afa7..018ec42e 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -850,6 +850,15 @@ B fromUtf8_c1(B t, B x) { return r; } +B toUtf8_c1(B t, B x) { + if (!isArr(x)) thrM("•ToUTF8: Argument must be a character or number array"); + u64 len = utf8lenB(x); + u8* rp; B r = m_c8arrv(&rp, len); + toUTF8(x, (char*)rp); + dec(x); + return r; +} + extern char** environ; #if __has_include() && __has_include() && !WASM