uCBQN/test/cases/system.bqn

449 lines
29 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

%DEF var V•internal.Variation LV•internal.ListVariations CLR•internal.ClearRefs
%DEF tvar %USE var _tvar {F _𝕣 x: (CLR@) {F 𝕩 V x}¨ LV 𝕩; w F _𝕣 x: (CLR@) (LV 𝕨) {(𝕨 V w) F 𝕩 V x} LV 𝕩}
%DEF eqvar _eqvar•args
%DEF eqvarv _eqvarv_•args
# not tested here: •Out •Show •Exit •GetLine •Cmp •CurrentError •FFI •internal.HeapDump
# standard system values
# •BQN
%USE eqvar •BQN _eqvar "1↑""""" %% " "
%USE eqvar •BQN _eqvar "1↑""""" %% " "
! ´ t•path,"custom-name", "arg"•BQN"⟨•path‿•name‿•args ⋄ •state⟩" ! •path, "custom-name", "arg" t
! ´ t•path,"custom-name" •BQN"⟨•path‿•name‿•args ⋄ •state⟩" ! •path, "custom-name", t
! ´ t•path •BQN"⟨•path‿•name‿•args ⋄ •state⟩" ! •path, "", t
! ´ t •BQN"⟨•path‿•name‿•args ⋄ •state⟩" ! "", 1t
!"•BQN: Path must be a string" % 12 •BQN "2+2"
!"•BQN: Filename must be a string" % •path, 12 •BQN "2+2"
•path, "abc/def" •BQN "•name" %% "abc/def"
!"•BQN: 𝕩 must be a string" % •BQN 3
!"No path present for •path" % •BQN"•path"
!"No arguments present for •args" % •BQN"•args"
!"No name present for •name" % •BQN"•name"
!"No arguments present for •state" % •BQN"•state"
! •path"""" •path•BQN"•state"
! """" ¯2•BQN"•state"
"args""path""name""helloworld""state"•BQN"•listsys" %% 11101
!"Failed to resolve ""path that doesn't exist"": No such file or directory" % "path that doesn't exist"•BQN"•path"
!"Failed to resolve ""path that doesn't exist"": No such file or directory" % "path that doesn't exist"•BQN"•state"
"path that doesn't exist"•BQN"2+2" %% 4
!"•file.Chars: Using relative path with no absolute base path known" % f•BQN"•FChars" F "a"
# •ReBQN
!"REPL: Filename must be a string" % f•ReBQN{} •path, 12 F "2+2"
!"REPL: Path must be a string" % f•ReBQN{} 12 F "2+2"
f•ReBQN{} ! •path, "custom-name", "arg" •path,"custom-name", "arg" F "•state"
f•ReBQN {system"all"} F "•internal.Type ↕10" %% "i8arr"
!"Unknown system function •internal" % f•ReBQN {system"none"} F "•internal.Type ↕10"
f•ReBQN {system"range" "add"+ "reverse"} F "•Reverse ¯5 •Add •Range 10" %% 4-10
f•ReBQN{} F "Ah"•internal.Variation"1↑""""" %% " "
F(•ReBQN{repl"none" })({𝕩˜𝕩@+10}•CurrentError) F"a←↕2", F"a←↕3", F"a" %% 01,012,"Undefined identifier"
F(•ReBQN{repl"loose" })({𝕩˜𝕩@+10}•CurrentError) F"a←↕2", F"a←↕3", F"a" %% 01,012,012
F(•ReBQN{repl"strict"})({𝕩˜𝕩@+10}•CurrentError) F"a←↕2", F"a←↕3", F"a" %% 01,"Redefinition",01
f •ReBQN{repl"none"} !6•Type F "a⇐1"
f •ReBQN{repl"none"} !6•Type F "⇐"
!"Cannot construct a namespace for a REPL result" % f •ReBQN{repl"loose"} F "a⇐1"
!"Cannot construct a namespace for a REPL result" % f •ReBQN{repl"loose"} F "⇐"
!"Cannot construct a namespace for a REPL result" % f •ReBQN{repl"strict"} F "a⇐1"
!"Cannot construct a namespace for a REPL result" % f •ReBQN{repl"strict"} F "⇐"
f•ReBQN {primitives'÷'-} ! ¯5 F"•BQN""÷5""" bF"•BQN" ! ¯5 B "÷5" ! 0.2 •BQN "÷5"
f•ReBQN {primitives'÷'-} a1 •bqn r1 F"•BQN" a2 A1"•BQN" r2 R1"•BQN" a3 A1"•ReBQN{⇐}" r3 R1"•ReBQN{⇐}" {𝕏"÷"}¨ a1,r1,a2,r2,a3,r3 %% ÷,-,÷,-,÷,-
f•ReBQN {repl"none" primitives'÷'÷} ! "Unknown character: '-'" F{𝕊: •CurrentError@} "-5" ! 0.2 •BQN "÷5"
f•ReBQN {repl"loose" primitives'÷'÷} ! "Unknown character: '-'" F{𝕊: •CurrentError@} "-5" ! 0.2 •BQN "÷5"
ps '÷'÷ f•ReBQN {repl"none" primitivesps} ! ps F "•primitives" ! •primitives •BQN "•primitives" ! ps F "•primitives"
ps '÷'÷ f•ReBQN {repl"loose" primitivesps} ! ps F "•primitives" ! •primitives •BQN "•primitives" ! ps F "•primitives"
f•ReBQN{primitives'÷'- system"foo", "oldbqn"•BQN, "bqn"} {𝕏 "÷5"}¨ F "⟨•foo, •OldBQN, •BQN⟩" %% "÷5", 0.2, ¯5
!"Character set conflict: ," % •ReBQN{primitives ','+}
!"•ReBQN: No system value ""baz"" to inherit" % •ReBQN{system"foo""bar", "bqn", "baz", "rebqn"}
!"•ReBQN: No system value ""bqn"" to inherit" % f•ReBQN{system"baz"1, "rebqn", "foo"2} gF"•ReBQN" G {system"foo""bar", "baz", "bqn", "rebqn"}
f•ReBQN{primitives'÷'- system"primitives", "foo", "bqn", "listsys"} F"•primitives‿•listsys" %% '÷'- "primitives","foo","bqn","listsys"
f•ReBQN{system"e1"0, "e2""", "e3"0<"hi" primitives'+',(<"")'-',(<0)} (1)¨ F "+-•e2‿•e1‿•e3" %% ' ', 0, ' ', 0, " "
# TODO test stacktrace of {𝕏"!0"}•ReBQN{⇐}
# •primitives
!´2=•Type¨ ¨•primitives
!¨ (•Type¨1¨•primitives)345
# •state
6(1) 1(2) •file.Name •state %% "testDir","system","arg0",1
# •args
1•args %% "arg0",1
# •path & •file.path
•file.Name •path %% "testDir"
•file.Name •file.path %% "testDir"
# •name
6•name %% "system"
# •wdpath
! ´ 2=•Type¨ •wdpath
# •ns
{abc1 dÊF2}•ns.Get¨ "abc", "ABC", "abC", "abc___", "DêF", "__D__Ê__F__" %% 111122
!"Field named ""abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789"" not found" % {abc1 dÊF2}•ns.Get "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789_"
{abc1 dÊF2 n103}•ns.Has¨ "abc", "ABC", "abC", "abc___", "DêF", "__D__Ê__F__", "àbc", "def", "", 0, "𝕨", "012", "n10", "n1_0" %% 11111100000011
´{}•ns.Has¨"abc123AEWQE___àÀ𝕨𝕩" %% 0
!"•ns.Has: 𝕩 must be a string" % {}•ns.Has ""
!"•ns.Has: 𝕩 must be a string" % {}•ns.Has 12
!"•ns.Get: 𝕩 must be a string" % {}•ns.Get ""
!"•ns.Get: 𝕩 must be a string" % {}•ns.Get 12
!"𝕨 •ns.Get 𝕩: 𝕨 must be a namespace" % 1•ns.Get "hi"
!"𝕨 •ns.Has 𝕩: 𝕨 must be a namespace" % 1•ns.Has "hi"
!"•ns.Keys 𝕩: 𝕩 must be a namespace" % •ns.Keys 1
{m𝕩 {𝕩 m•ns.Get 𝕩}¨ •ns.Keys m {m•ns.Has𝕩}¨ "abcABC"}¨ {a1b10} {a'a'b23cde𝕩}"abc" %% "a",1,"b",0123456789,110110,"a",'a',"cde","abc",100100
# files; tests are ordered!
{•file.Exists 𝕩? •SH"rmdir", •file.At 𝕩; 0} "testdirNested" %% 0
•file.Remove•file.Exists¨ "testfile.bqn""testfile2.bqn""testfile3B.bqn""badwrite" 1 %% 1
•file.At "/a/b" %% "/a/b"
! (•file.At "a/b") •file.path •file.At "a/b"
"a/b" •file.At "c/d" %% "a/b/c/d"
"a/b/" •file.At "c/d" %% "a/b/c/d"
"a/b/" •file.At "c/d/" %% "a/b/c/d/"
"a/b/" •file.At "/c/d" %% "/c/d"
"a/b" •file.At "/c/d/" %% "/c/d/"
•file.Exists "/dev/file that doesn't exist" %% 0
!"Couldn't read file ""/dev/file that doesn't exist""" % •FChars "/dev/file that doesn't exist"
! (•path"/") •file.Parent •file.At "hi"
!"•file.Parent: Path must be non-empty" % •file.Parent ""
!"•file.Name: Path must be non-empty" % •file.Name ""
!"𝕨 •file.Lines 𝕩: 𝕩 must be a list" % "testfile.bqn" •FLines 22<"abcd"
!"𝕨 •file.Lines 𝕩: 𝕩 must be a list" % "testfile.bqn" •file.Lines <"abcd"
!"𝕨 •file.Lines 𝕩: Elements of 𝕩 must be lists of characters" % "testfile.bqn" •FLines "abcd"
!"Expected character" % "testfile.bqn" •FLines "ab""cd"
!"Expected character" % "testfile.bqn" •FLines 12
!"Expected character" % "testfile.bqn" •FChars "abcd"
!"𝕨 •file.Chars 𝕩: 𝕩 must be a list of characters" % "testfile.bqn" •FChars <'a'
!"Expected character" % "testfile.bqn" •FBytes "abcd"
!"𝕨 •file.Bytes 𝕩: 𝕩 must be a list" % "testfile.bqn" •file.Bytes <'a'
!"Expected character" % "badwrite"•FChars """"
!"Expected character" % "badwrite"•FLines "foo"
!"𝕨 •file.Chars 𝕩: 𝕩 must be a list of characters" % "badwrite"•FChars @
! {𝕩•file.Name 𝕩 •FChars "abc"(@+10)"def𝕩"}"testfile.bqn"
! {𝕩•file.Name 𝕩 •FBytes •ToUTF8 "abc"(@+10)"def𝕩"}"testfile2.bqn"
! {𝕩•file.Name 𝕩 •FLines "abc""def𝕩"} "testfile3.bqn"
•file.Type "testfile.bqn" %% 'f'
•file.Type •file.path %% 'd'
!¨ 0{𝕏 "testfile.bqn"}¨ •file.Created•file.Accessed•file.Modified
•file.Size "testfile.bqn" %% 11
•FBytes¨ "testfile.bqn""testfile2.bqn""testfile3.bqn" %% (@+10)(2) 3< •ToUTF8 "abc"(@+10)"def𝕩"
•FChars "testfile.bqn" %% "abc"(@+10)"def𝕩"
•FBytes "testfile.bqn" %% @+97989910100101102240157149169
•FLines "testfile.bqn" %% "abc""def𝕩"
! 97989910100101102240157149169 @-˜ •file.MapBytes "testfile.bqn"
•file.Name "testfile3B.bqn" •file.Rename "testfile3.bqn" %% "testfile3B.bqn"
!"𝕨 •file.Rename 𝕩: Failed to rename file" % "testfile3B.bqn" •file.Rename "testfile.bqn"
•file.Exists¨ "testfile.bqn""nontestfile.bqn""testfile3.bqn""testfile3B.bqn" %% 1001
¯22•file.Createdir "testdirNested" %% "/testDir/testdirNested"
¯8•file.RealPath "testdirNested/.././" %% "/testDir"
!"•file.CreateDir 𝕩: Failed to create directory" % •file.Createdir "testdirNested"
"testfile.bqn""testfile2.bqn""testfile3.bqn""testfile3B.bqn""testdirNested" •file.List "." %% 11011
"testfile.bqn""testfile2.bqn""testfile3.bqn""testfile3B.bqn""testdirNested" •file.List •file.path %% 11011
•file.Remove "testfile.bqn" %% 1
•file.Remove "testfile2.bqn" %% 1
•file.Remove "testfile3B.bqn" %% 1
"testfile.bqn""testfile2.bqn""testfile3B.bqn""badwrite" •file.List "." %% 0000
!"Failed to resolve ""/dev/file that doesn't exist"": No such file or directory" % •file.RealPath "/dev/file that doesn't exist"
!"Failed to resolve ""/dev/file that doesn't exist"": No such file or directory" % •Import "/dev/file that doesn't exist"
# bad paths
!"•file.At: Path must be a list of characters" % •file.At 12
!"•file.At: Path must be a list of characters" % •file.At 12
!"•file.At: Path must be a list of characters" % "foo" •file.At 12
!"•file.At: 𝕨 must be a string" % 12 •file.At "foo"
!"•file.List: Path must be a list of characters" % •file.List 12
!"•file.Bytes: Path must be a list of characters" % •file.Bytes 12
!"•file.Chars: Path must be a list of characters" % •file.Chars 12
!"•file.Lines: Path must be a list of characters" % •file.Lines 12
!"•file.Bytes: Path must be a list of characters" % 12 •FBytes "abc"
!"•file.Chars: Path must be a list of characters" % 12 •FChars "abc"
!"•file.Lines: Path must be a list of characters" % 12 •FLines "abc""def"
!"•file.Type: Path must be a list of characters" % •file.Type 12
!"•file.Exists: Path must be a list of characters" % •file.Exists 12
!"•file.Name 𝕩: Argument must be a string" % •file.Name 12
!"•file.Parent 𝕩: Argument must be a string" % •file.Parent 12
!"•file.MapBytes: Path must be a list of characters" % •file.MapBytes 12
!"•file.CreateDir: Path must be a list of characters" % •file.CreateDir 12
!"•file.RealPath: Path must be a list of characters" % •file.RealPath 12
!"•file.Rename: Path must be a list of characters" % "foo" •file.Rename 12
!"•file.Rename: Path must be a list of characters" % 12 •file.Rename "foo"
!"•file.Remove: Path must be a list of characters" % •file.Remove 12
!"•file.Created: Path must be a list of characters" % •file.Created 12
!"•file.Modified: Path must be a list of characters" % •file.Modified 12
!"•file.Accessed: Path must be a list of characters" % •file.Accessed 12
!"•file.Size: Path must be a list of characters" % •file.Size 12
!"•file.Size: Path must be a list of characters" % •file.Size 22"abcd"
# some of •term
!"Expected character" % •term.OutRaw 2{}
!"•term.ErrRaw 𝕩: 𝕩 must be a list" % •term.ErrRaw 220
# •ParseFloat & •Repr
v1 ! •BQN•Repr +,12,+¨,(+V)(V+V),224
# v←1 ⋄ •BQN∘•Repr⊸≡ ⟨V V V, V V⟩ # TODO enable
641•bit._cast •ParseFloat¨ "123.456000000000000""123.45600000000002" %% "11101110011111011111100101011000111101001011101101111010000000100001111001111101111110010101100011110100101110110111101000000010"-'0'
! ´'e'=•ParseFloat'e'¨ "-""e2""-e2""."".e2""123e""123e-""123e+"
•ParseFloat "0."(n'0')"1234e"•Repr n1000000 %% 0.1234
•ParseFloat 1e6'1' %%
!"•ParseFloat 𝕩: Input too long" % •ParseFloat 2e6'1'
•Repr•ParseFloat¨ "1.23516411460311636e-323", "1.23516411460311637e-323" %% "1e¯323","1.5e¯323"
•Repr•ParseFloat¨ "1.235164114603116360e-323", "1.235164114603116361e-323" %% "1e¯323","1e¯323"
•Repr•ParseFloat¨ "1.2351641146031163604e-323", "1.2351641146031163605e-323" %% "1e¯323","1e¯323"
a1@3 •ParseFloat"err" a / a, 1, a, 3 %% 31, 13
!"•ParseFloat 𝕩: Input was empty" % •ParseFloat ""
!"•ParseFloat 𝕩: Input was empty" % •ParseFloat 0
!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat 3
!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat <@
!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat 11'1'
!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat 4849
!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat <48
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat "1e1e1"
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+254
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+1111
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+1114111
# •Fmt
•Fmt 123 %% "123"
# •SH
•SH"true" %% 0
•SH"false" %% 1
{stdin"𝕩"@+256} •SH"cat" %% 0, "𝕩"@+256, ""
{stdin"𝕩"@+256 raw0} •SH"cat" %% 0, "𝕩"@+256, ""
{stdin@+256 raw1} •SH"cat" %% 0, @+256, ""
# •Type
•Type¨ "ab",'a'1,1,0÷0,'a',@+1114111,+,{𝕩},¨,{𝕗},,{𝔽𝕘},{},•rand %% 00112233445566
# •Glyph
•Glyph¨ +,¨, %% "+¨∘"
# •Decompose
{! 0𝕩 •Decompose 𝕩}¨ +, ¨, ˝, , , , •internal.PureKeep
{! 1𝕩 •Decompose 𝕩}¨ {𝕩}, {𝔽}, {𝔽𝕩}, {𝔽𝕘}, {𝔽𝔾𝕩}
{! 1𝕩 •Decompose 𝕩}¨ •Type, •internal.Keep, •FChars, •_timed, •_while_
{! ¯1𝕩 •Decompose 𝕩}¨ 1,'a',"ab"
•Decompose¨ +-×, -÷, +¨, 1+ %% 3,+,-,×,2,-,÷,4,+,¨,5,1,,+
# •UnixTime
•Type •UnixTime 10 %% 1
# •MonoTime
! ´•MonoTime¨2
# •Delay
t0•MonoTime@ ! 0.1•Delay 0.1 ! 0.1(•MonoTime@)-t0
# •_timed tested more at perf.bqn
!"𝕨 𝔽•_timed 𝕩: 𝕨 must be an integer greater than 0" % 0 •_timed 2
!"Expected integer, got character" % @ •_timed 2
a1 a {𝕊: a+𝕩}•_timed 10 %% 11
a3 12 {𝕊: a+𝕩}•_timed 10 a %% 123
# •math
! ´0=|1e10×{(+´𝕩)-•math.Sum 𝕩}¨ 1000•rand.Range 0
!"•math.Sum 𝕩: 𝕩 must be a list (⟨⟩ ≡ ≢𝕩)" % •math.Sum 2
!"•math.Sum 𝕩: 𝕩 must be a list (2‿2 ≡ ≢𝕩)" % •math.Sum 221
!"•math.Sum 𝕩: 𝕩 elements must be numbers" % •math.Sum 1'a'
# two assumptions made by the following tests
%DEF nan nan164•bit._cast/5113 nans nan-nan
%USE nan 6432•bit._cast nans %% 0¯52428802146959360
%USE nan 6432•bit._cast (¯1×) (3)nan %% 2100¯21474836480¯10747904000¯10737418240¯10485760¯524288000107269324801073741824021464350720¯524288
6432•bit._cast π, 0, •ParseFloat"-0" %% 14137541361074340347000¯2147483648
! {(𝕩 •math.Atan2 0) 𝕩 •math.Atan2 •ParseFloat"-0"} (-) ˜3
! {(0 •math.Atan2 𝕩) (•ParseFloat"-0") •math.Atan2 𝕩} (-) ˜3
E•internal.EEqual a(¯1×) (3)0÷0 {𝕩!(a 𝕏 0)E a 𝕏 •ParseFloat"-0" 𝕩!(0 𝕏 a)E(•ParseFloat"-0") 𝕏 a}¨ ({𝕏¨}¨) +,-,×,÷,,,,,|,¬,,,<,>,,=,,, •math.Atan2,•math.Comb,•math.Hypot
E•internal.EEqual {! (𝕏 40) E 𝕏 1¯1×π40}¨ ({𝕏¨}¨) +,-,×,÷,,,,,|,¬, •math.Sin,•math.Cos,•math.Tan,•math.Asin,•math.Acos,•math.Atan,•math.Sinh,•math.Cosh,•math.Tanh,•math.Asinh,•math.Acosh,•math.Atanh,•math.Cbrt,•math.Log2,•math.Log10,•math.Log1p,•math.Expm1,•math.Fact,•math.LogFact,•math.Erf,•math.ErfC
•internal.EEqual´¨ 1˘¨{•math.Atan22𝕩, •math.Atan20𝕩, 2•math.Atan2𝕩, 0•math.Atan2𝕩} (¯1×) 1.20 %% 1111
(0÷0) •internal.EEqual -0÷0 %% 1
%USE eqvar •internal.EEqual _eqvar- 0÷0, 30 %% 1
{15 𝕏 10}¨ •math.GCD,•math.LCM %% 530
1e5×{0.1 𝕏 0.2}¨ •math.Atan2,•math.Comb,•math.Hypot,•math.Atan2,•math.Atan2˜ %% 1107149695922360202749331
1e5×{=˜99¨ 𝕏 0.13}¨ •math.Acos,•math.Acosh,•math.Asin,•math.Asinh,•math.Atan,•math.Atanh,•math.Cbrt,•math.Cos,•math.Cosh,•math.Erf,•math.ErfC,•math.Expm1,•math.Fact,•math.Log10,•math.Log1p,•math.Log2,•math.LogFact,•math.Sin,•math.Sinh,•math.Tan,•math.Tanh %% 1470629900000,9900000176274,100169900000,9983181844,9966124904,100339900000,46415144224,99500¯99000,1005001006766,1124699997,887532,105171908553,95135600000,¯10000047712,9531138629,¯332193158496,¯4988179175,998314112,100161001787,10033¯14255,996699505
{𝕩 ! 12 (𝕏 𝕏¨) 34}¨ •math.Atan2,•math.Comb,•math.Hypot,•math.Atan2,•math.Atan2˜,•math.GCD,•math.LCM
!"𝕨 •math.GCD 𝕩: Inputs other than natural numbers not yet supported" % 1.5 •math.GCD 3
!"𝕨 •math.LCM 𝕩: Inputs other than natural numbers not yet supported" % 3 •math.LCM 1.5
!"𝕨 •math.LCM 𝕩: Unexpected argument types" % "foo" •math.LCM 3
!"𝕨 •math.GCD 𝕩: Unexpected argument types" % 3 •math.GCD {+}
!"•math.Sin 𝕩: 𝕩 contained non-number" % •math.Sin "foo"
!"•math.Log10 𝕩: 𝕩 contained non-number" % •math.Log10 "foo"
!"𝕨 •math.Atan2 𝕩: Unexpected argument types" % 1 •math.Atan2 'a'
!"𝕨 •math.Atan2⁼ 𝕩: Unexpected argument types" % 1 •math.Atan2 {}
!"𝕨 •math.Atan2˜𝕩: Unexpected argument types" % {} •math.Atan2˜ 'b'
# •rand / •MakeRand
0 (•MakeRand 0).Range¨2 %%
00 (•MakeRand 0).Range¨2 %%
(•MakeRand 0).Deal 0 %%
0 (•MakeRand 0).Subset 0 %%
{!(•rand.Deal 𝕩)𝕩}¨ ¯101+222 # %SLOW
!"𝕨 (rand).Range 𝕩: Result rank too large (256≡≢𝕨)" % (2561) •rand.Range 0
! ˝ a{r•MakeRand 𝕩 r.Range 1e9, 100 r.Range 1e9, r.Deal 100, 100 r.Deal 200, 100 r.Deal 200, 100 r.Subset 200}¨ 222 !¨´ a
r•MakeRand 1 ! 1¨ {𝕊: 800 r.Subset 1000}¨ 4
r•MakeRand 1 ! 1¨ {𝕊: 50 r.Subset 10000}¨ 4
r•MakeRand 1 ! 1¨ {𝕊: 10 r.Range 10000}¨ 4
r•MakeRand 1 ! 1¨ {𝕊: 1010 r.Range 128}¨ 4
r•MakeRand 1 ! 1¨ {𝕊: r.Deal 1000}¨ 4
r•MakeRand 1 ! 1¨ {𝕊: 500 r.Deal 1000}¨ 4
# •bit
!"•bit._cast: 𝕩 must have rank at least 1" % 81 •bit._cast 123
(10) {! (𝕨¯1) 1𝕩•bit._cast (𝕨×𝕩)1} 81632
%USE eqvar {t𝕩18163264 1t? {t•bit._cast 𝕩}_eqvar 128; @}¨ 44
%USE eqvar {t𝕩18163264 {t•bit._cast 𝕩}_eqvar 4=128}¨ 44
! 101 816•bit._cast c02'a'+11 •rand.Range 26 ! 102 c
! 101 816•bit._cast c 2'a'+11 •rand.Range 26 ! 102 c
!"•bit._cast: incompatible lengths" % 18•bit._cast 10
!"•bit._cast: incompatible lengths" % 832•bit._cast 20
!"•bit._cast: incompatible lengths" % 832•bit._cast 100
!"•bit._cast: unsupported width 1073741824" % (2230)•bit._cast 0
!"•bit._cast: unsupported width 1125899906842624" % (2250)•bit._cast 0 %USZ64
!"Integer out of range: 1125899906842624" % (2250)•bit._cast 0 %USZ32
!"Integer out of range: 1.180591620717411e21" % (2270)•bit._cast 0
!"Integer out of range: ∞" % (2)•bit._cast 0
!"•bit._cast: unsupported width 12" % 112•bit._cast 110
!"•bit._cast: unsupported width 12" % 1232•bit._cast (12×32)0
!"•bit._cast: unsupported width 12" % 812•bit._cast (8×12)0
!"•bit._cast: unsupported width 0" % 032•bit._cast 1280
!"•bit._cast: unsupported width 0" % 80•bit._cast 1280
!"•bit._cast: unsupported width 16 for type 'f'" % 16'f',32•bit._cast 1280
!"•bit._cast: unsupported width 32 for type 'f'" % 32,32'f'•bit._cast 1280
!"•bit._cast: unsupported width 0 for type 'u'" % 0'u',32•bit._cast 1280
!"•bit._cast: unsupported width 8 for type 'u'" % 8'u',32•bit._cast 1280
!"•bit._cast: unsupported width 32 for type 'u'" % 8,32'u'•bit._cast 1280
!"•bit._cast: unsupported width 1 for type 'i'" % 8, 1'i'•bit._cast 1280
%USE eqvar {𝕊 f: {•internal.Keep 𝕩1 •internal.Validate F 𝕩}_eqvar 64}¨ ({𝕩•bit._neg}¨ 8163264) {𝕩 •bit._cast}¨ ´¨/ 8163264 18163264
%USE eqvar {𝕊 f: {•internal.Keep 𝕩1 •internal.Validate F 𝕩}_eqvar 64}¨ ({𝕩•bit._neg}¨ 8163264) {𝕩 •bit._cast}¨ ´¨/ 8163264 18163264
%USE eqvar {𝕊 f: {•internal.Squeeze 𝕩 •internal.Validate F 𝕩}_eqvar 642}¨ ({𝕩•bit._neg}¨ 8163264) {𝕩 •bit._cast}¨ ´¨/ 8 18163264
%USE eqvar {𝕊 w: {𝕩, w•bit._not 8𝕩}_eqvar 16}¨ 8163264
# •platform
Str {!=𝕩 !×𝕩 ! ´2=•Type¨𝕩} Str •platform.os Str •platform.cpu.arch Str •platform.bqn.impl_version Str •platform.environment
•platform.bqn.impl %% "CBQN"
# CBQN-specific extensions
# •_while_
1+•_while_{𝕊: ´𝕩20} 10 %% 12+10
(101) +•_while_{𝕊: ´𝕩20} 10 %% 12+10
# •Hash
! ´ •Hash¨ 2<10,"ab"
! ´1 •Hash¨ 2<10,"ab"
# •ToUTF8 & •FromUTF8
@-˜•ToUTF8 "𝕩⍉hello" %% 240157149169226141137104101108108111
! •FromUTF8•ToUTF8 "𝕩⍉hello"
(
%USE eqvar
ip¨ i@+0((¯5+11)+220)1114111-10
{! 𝕩•FromUTF8•ToUTF8 𝕩 •ToUTF8 _eqvar 𝕩}¨ i
t •ToUTF8¨ ip
! (t)•ToUTF8 i
! ip •FromUTF8¨ t
! (¨t) ¯1+`/04993148197
)
# •internal.GC
•internal.GC 10 %% 1
# •internal.Type & •internal.Variation & •internal.ElType & •internal.ListVariations
(
raw {("a"¨ 𝕩)"s"¨ 1𝕩} "b","i8","i16","i32","f64","c8","c16","c32","h","f"
var {ae: a-32, e}¨ raw
ty { {"a":"arr";"slice"}{"b":"bit"; "f":"fill"; 𝕩} {𝕎𝕩}¨ 𝕩}¨ raw
ty {"type"𝕨𝕩 ! 𝕨 •internal.Type 𝕩 •internal.Variation }¨ var
! 0123456788123456788 {•internal.ElType 𝕩 •internal.Variation }¨ var
# TODO test •internal.ListVariations
)
%USE eqvarv •internal.ListVariations _eqvarv_"i" π×10 %% "Af64","Sf64","Af64Inc","Sf64Inc","Ah","Sh","AhInc","ShInc","Af","Sf","AfInc","SfInc"
%USE eqvarv •internal.ListVariations _eqvarv_"i" (π×10){} %% "Ah","Sh","AhInc","ShInc","Af","Sf","AfInc","SfInc"
%USE eqvarv •internal.ListVariations _eqvarv_"i" 1000 %% "Ai16","Si16","Ai16Inc","Si16Inc","Ai32","Si32","Ai32Inc","Si32Inc","Af64","Sf64","Af64Inc","Sf64Inc","Ah","Sh","AhInc","ShInc","Af","Sf","AfInc","SfInc"
%USE eqvarv •internal.ListVariations _eqvarv_"i" 10010 %% "Ab","AbInc","Ai8","Si8","Ai8Inc","Si8Inc","Ai16","Si16","Ai16Inc","Si16Inc","Ai32","Si32","Ai32Inc","Si32Inc","Af64","Sf64","Af64Inc","Sf64Inc","Ah","Sh","AhInc","ShInc","Af","Sf","AfInc","SfInc"
# •internal.Keep
•internal.Keep 10 %% 10
!"This function can't be called dyadically" % 1 •internal.Keep 1
# •internal.Refc
•internal.Refc •internal.Unshare 10 %% 1
a•internal.Unshare 10 b10<a ! 11 •internal.Refc a •internal.Keep b
# •internal.IsPure
•internal.IsPure¨ @,1,,¨,,{},12,{𝕩}{𝔽}{𝔽𝔾𝕩} %% 81
! 1 •internal.IsPure +¨++
! 1 •internal.IsPure 123+¨++
! 1 •internal.IsPure -
! 0 •internal.IsPure {𝕩}-
! 1 •internal.IsPure 12{𝕩}+¨++
! 0 •internal.IsPure •show
! 0 •internal.IsPure •file.chars
! 0 •internal.IsPure •internal.keep
! 1 •internal.IsPure •internal.pureKeep
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝕩}¨
! 0 •internal.IsPure {𝔽𝕩}
! 0 •internal.IsPure {𝕩}
! 0 •internal.IsPure {𝔽𝔾𝕩}
! 0 •internal.IsPure {𝕩}
# •internal.Info
•internal.Info 1 %% "3ff0000000000000: not heap-allocated"
33•internal.Info •internal.Unshare 10 %% "fff7: refc:1 type:23=i8arr alloc:"
# •internal.HasFill
•internal.HasFill¨ 0, 10, , 'a'1, "" %% 11001
# •internal.Squeeze
a"Ai32"•internal.Variation 10 •internal.Type •internal.Squeeze a %% "i8arr"
{! 𝕩 •internal.Squeeze 𝕩}¨ {0•Cmp´0¯1𝕩? 𝕩@; 𝕩@}¨ {´1e9|0¯1𝕩? 𝕩; 𝕩,"Ai32"•internal.Variation 𝕩}¨ 11000/¨ {0𝕩,𝕩0}¨ 12¯1 ¯1- 0¯1 + 271531
# •internal.DeepSqueeze
a"Ai32"•internal.Variation 10 •internal.Type •internal.DeepSqueeze a %% "i8arr"
# •internal.ClearRefs
•internal.ClearRefs@ •internal.Variation(10)¨ 10<"Ai32Inc" •internal.ClearRefs "foo" %% 10
# •internal.Unshare
•internal.Refc•internal.Unshare¨ 0, "", , 10 %% 1111
abc •internal.Unshare {a2},"hi",3 abc %% 01, "hi", 3
# •internal.EEqual
%USE nan a1nans•ParseFloat¨"0""1.2""-0" a •internal.EEqual a %% 1
# •internal.Validate
! •internal.Validate 10
! •internal.Validate 1000