Skip to content

Commit

Permalink
Add built-in tuple primitives to the prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
chengluyu committed Nov 13, 2024
1 parent d65804e commit b0a4d41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:js
:ucs desugared

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

// Drop the first and last elements.
tupleSlice([1, 2, 3, 4], 1, -1)
Expand All @@ -23,7 +23,7 @@ fun stupid(xs) = if xs is
//│ Desugared:
//│ > if
//│ > xs@59 is []>=0 and
//│ > let $rest@60 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@59#2, 0, 0)
//│ > let $rest@60 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@59#2, 0, 0)
//│ > let ys@61 = $rest@60#0
//│ > else ys@61#666
//│ > xs@59 is []=0 then "empty"
Expand Down Expand Up @@ -58,8 +58,8 @@ fun foo(xs) = if xs is
//│ > if
//│ > xs@71 is []>=2 and
//│ > let $first0@74 = xs@71#2.0
//│ > let $rest@73 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@71#3, 1, 1)
//│ > let $last0@72 = globalThis:block#1#666.tupleGet‹member:tupleGet›(xs@71#4, -1)
//│ > let $rest@73 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@71#3, 1, 1)
//│ > let $last0@72 = globalThis:import#Tuple#666.tupleGet‹member:tupleGet›(xs@71#4, -1)
//│ > let x@75 = $first0@74#0
//│ > let ys@76 = $rest@73#0
//│ > let y@77 = $last0@72#0
Expand Down Expand Up @@ -108,8 +108,8 @@ fun nested_tuple_patterns(xs) = if xs is
//│ > if
//│ > xs@96 is []>=2 and
//│ > let $first0@99 = xs@96#2.0
//│ > let $rest@98 = globalThis:block#1#666.tupleSlice‹member:tupleSlice›(xs@96#3, 1, 1)
//│ > let $last0@97 = globalThis:block#1#666.tupleGet‹member:tupleGet›(xs@96#4, -1)
//│ > let $rest@98 = globalThis:import#Tuple#666.tupleSlice‹member:tupleSlice›(xs@96#3, 1, 1)
//│ > let $last0@97 = globalThis:import#Tuple#666.tupleGet‹member:tupleGet›(xs@96#4, -1)
//│ > let x@100 = $first0@99#0
//│ > $rest@98 is []=2 and
//│ > let $first0@102 = $rest@98#1.0
Expand Down
2 changes: 2 additions & 0 deletions hkmc2/shared/src/test/mlscript/ucs/prelude/Tuple.mls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fun tupleSlice(xs, i, j) = globalThis.Array.prototype.slice.call(xs, i, xs.length - j)
fun tupleGet(xs, i) = globalThis.Array.prototype.at.call(xs, i)

0 comments on commit b0a4d41

Please sign in to comment.