phino-0.0.156: test-resources/evaluate-packs/upcasts-a-bare-symbol-to-the-tuple-of-the-other-branch.yaml
# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
# The fork of 'bytes.array' from #1914: one branch is a bare symbol, the other
# a tuple holding three symbols, so a lenient join cannot tell which of them
# the bare one pairs with. A 'rewrite' line spells the tuple as the call
# 'Ξ¦.tuple( β¦ )' it was made of, and the 'upcast' block takes 'π1' and that
# call as one pair. It casts the smaller of the two, the bare 'π1', into a
# copy of the call whose every symbol is read off 'π1' by a path, and passes
# the call through as it is (#1921). The 'join' line then pairs the two metas
# the block wrote symbol by symbol, through their arguments. The program reads 'length' off the answer and gets the symbol
# standing for either length.
symbolic: |
- Ξ»: L_fork
morph:
π1: $.a
π2: $.b
rewrite:
π3:
of: π2
rules:
- name: called
pattern: β¦ tail β¦ π1, head β¦ π2, length β¦ π3, !B β§
result: Ξ¦.tuple( tail β¦ π1, head β¦ π2, length β¦ π3 )
upcast:
π4: π1
π5: π3
join:
π6: [π4, π5]
π: π6
location: 'Q.y'
input: |
β¦
tuple(tail, head, length) β¦ β¦ empty β¦ β¦β§ β§,
y β¦ β¦
a β¦ β¦ Ξ» β€ π1 β§,
b β¦ Ξ¦.tuple( tail β¦ β¦ Ξ» β€ π2 β§, head β¦ β¦ Ξ» β€ π3 β§, length β¦ β¦ Ξ» β€ π4 β§ ),
Ξ» β€ L_fork
β§.length
β§
result: 'π10:Ξ»'
protocol: |
π(Ξ¦.y):
πΌ(L_fork):
π1Β·1 := π1:Ξ» # π(ΞΎ.a)
π(Ξ¦.aπ΅1):
πΒ·1Β·1 := Ξ¦.tuple( tail β¦ π2:Ξ» )
πΒ·1Β·2 := πΒ·1Β·1( head β¦ π3:Ξ» )
πΒ·1Β·3 := πΒ·1Β·2( length β¦ π4:Ξ» )
π2Β·1 := πΒ·1Β·3 # π(ΞΎ.b)
π3Β·1 := πΒ·1Β·3 # π2
upcast(π1) := Ξ¦.tuple( tail β¦ π5:Ξ», head β¦ π6:Ξ», length β¦ π7:Ξ» )
π5 := π1.tail
π6 := π1.head
π7 := π1.length
π4Β·1 := Ξ¦.tuple( tail β¦ π5:Ξ», head β¦ π6:Ξ», length β¦ π7:Ξ» ) # π1
π5Β·1 := πΒ·1Β·3 # π3
π»(π8:Ξ») β { π»(π5:Ξ»), π»(π2:Ξ») }
π»(π9:Ξ») β { π»(π6:Ξ»), π»(π3:Ξ») }
π»(π10:Ξ») β { π»(π7:Ξ»), π»(π4:Ξ») }
π6Β·1 := Ξ¦.tuple( tail β¦ π8:Ξ», head β¦ π9:Ξ», length β¦ π10:Ξ» ) # [π4, π5]
πΒ·1Β·4 := Ξ¦.tuple( tail β¦ π8:Ξ», head β¦ π9:Ξ», length β¦ π10:Ξ» ) # π
π(πΒ·1Β·4):
πΒ·1Β·5 := Ξ¦.tuple( tail β¦ π8:Ξ» )
πΒ·1Β·6 := πΒ·1Β·5( head β¦ π9:Ξ» )
πΒ·1Β·7 := πΒ·1Β·6( length β¦ π10:Ξ» )
πΒ·1Β·8 := πΒ·1Β·7 # π(πΒ·1Β·4)