Skip to content

Commit bfdf811

Browse files
committed
Add built-in tuple primitives to the prelude
1 parent 897eb28 commit bfdf811

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
:js
22
:ucs desugared
33

4-
fun tupleSlice(xs, i, j) = globalThis.Array.prototype.slice.call(xs, i, xs.length - j)
5-
fun tupleGet(xs, i) = globalThis.Array.prototype.at.call(xs, i)
4+
:import ../Prelude/Tuple.mls
5+
//│ Imported 2 member(s)
66

77
// Drop the first and last elements.
88
tupleSlice([1, 2, 3, 4], 1, -1)
@@ -23,7 +23,7 @@ fun stupid(xs) = if xs is
2323
//│ Desugared:
2424
//│ > if
2525
//│ > xs@41 is []>=0 and
26-
//│ > let $rest@42 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@41#2, 0, 0)
26+
//│ > let $rest@42 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@41#2, 0, 0)
2727
//│ > let ys@43 = $rest@42#0
2828
//│ > else ys@43#666
2929
//│ > xs@41 is []=0 then "empty"
@@ -58,8 +58,8 @@ fun foo(xs) = if xs is
5858
//│ > if
5959
//│ > xs@53 is []>=2 and
6060
//│ > let $first0@56 = xs@53#2.0
61-
//│ > let $rest@55 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@53#3, 1, 1)
62-
//│ > let $last0@54 = globalThis:block#1#666.tupleGet‹member:tupleGet›(xs@53#4, -1)
61+
//│ > let $rest@55 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@53#3, 1, 1)
62+
//│ > let $last0@54 = globalThis:import#Tuple#666.tupleGet‹member:tupleGet›(xs@53#4, -1)
6363
//│ > let x@57 = $first0@56#0
6464
//│ > let ys@58 = $rest@55#0
6565
//│ > let y@59 = $last0@54#0
@@ -108,8 +108,8 @@ fun nested_tuple_patterns(xs) = if xs is
108108
//│ > if
109109
//│ > xs@78 is []>=2 and
110110
//│ > let $first0@81 = xs@78#2.0
111-
//│ > let $rest@80 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@78#3, 1, 1)
112-
//│ > let $last0@79 = globalThis:block#1#666.tupleGet‹member:tupleGet›(xs@78#4, -1)
111+
//│ > let $rest@80 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@78#3, 1, 1)
112+
//│ > let $last0@79 = globalThis:import#Tuple#666.tupleGet‹member:tupleGet›(xs@78#4, -1)
113113
//│ > let x@82 = $first0@81#0
114114
//│ > $rest@80 is []=2 and
115115
//│ > let $first0@84 = $rest@80#1.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fun tupleSlice(xs, i, j) = globalThis.Array.prototype.slice.call(xs, i, xs.length - j)
2+
fun tupleGet(xs, i) = globalThis.Array.prototype.at.call(xs, i)

0 commit comments

Comments
 (0)