aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux
blob: 2006f836f726d39dc2bcd422ae1b5c04791686e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except Scope #Function #Apply #locals i64)
   [abstract
    [monad (.only do)]
    [equivalence (.only Equivalence)]
    [hash (.only Hash)]]
   [control
    ["[0]" maybe]]
   [data
    ["[0]" sum]
    ["[0]" product]
    ["[0]" bit (.use "[1]#[0]" equivalence)]
    ["[0]" text (.use "[1]#[0]" equivalence)
     ["%" \\format (.only Format format)]]
    [collection
     ["[0]" list (.use "[1]#[0]" functor)]
     ["[0]" dictionary (.only Dictionary)]]]
   [math
    [number
     ["n" nat]
     ["i" int]
     ["f" frac]
     ["[0]" i64]]]
   [meta
    [macro
     ["^" pattern]]]]]
 ["[0]" /
  ["[1][0]" simple (.only Simple)]
  ["[1][0]" access (.only Access)
   ["[2][0]" side (.only Side)]
   ["[2][0]" member (.only Member)]]
  [//
   ["[0]" analysis (.only Environment)
    ["[1]/[0]" complex (.only Complex)]]
   ["[0]" phase (.only)
    ["[0]" extension (.only Extension)]]
   [///
    [arity (.only Arity)]
    ["[0]" reference (.only Reference)
     ["[0]" variable (.only Register Variable)]]]]])

(type .public Resolver
  (Dictionary Variable Variable))

(type .public State
  (Record
   [#locals Nat
    ... https://en.wikipedia.org/wiki/Currying
    #currying? Bit]))

(def .public fresh_resolver
  Resolver
  (dictionary.empty variable.hash))

(def .public init
  State
  [#locals 0
   #currying? false])

(type .public (Road value next)
  (Record
   [#when value
    #then next]))

(type .public (Fork value next)
  [(Road value next)
   (List (Road value next))])

(type .public (Path' s)
  (Variant
   {#Pop}
   {#Bind Register}
   {#Access Access}
   {#Bit_Fork Bit (Path' s) (Maybe (Path' s))}
   {#I64_Fork (Fork I64 (Path' s))}
   {#F64_Fork (Fork Frac (Path' s))}
   {#Text_Fork (Fork Text (Path' s))}
   {#Seq (Path' s) (Path' s)}
   {#Alt (Path' s) (Path' s)}
   {#Then s}))

(type .public (Abstraction' s)
  (Record
   [#environment (Environment s)
    #arity Arity
    #body s]))

(type .public (Apply' s)
  (Record
   [#function s
    #arguments (List s)]))

(type .public (Branch s)
  (Variant
   {#Exec s s}
   {#Let s Register s}
   {#If s s s}
   {#Get (List Member) s}
   {#When s (Path' s)}))

(type .public (Scope s)
  (Record
   [#start Register
    #inits (List s)
    #iteration s]))

(type .public (Loop s)
  (Variant
   {#Scope (Scope s)}
   {#Again (List s)}))

(type .public (Function s)
  (Variant
   {#Abstraction (Abstraction' s)}
   {#Apply (Apply' s)}))

(type .public (Control s)
  (Variant
   {#Branch (Branch s)}
   {#Loop (Loop s)}
   {#Function (Function s)}))

(with_expansions [@ ($ (Term' $))]
  (type .public (Term' $)
    (Variant
     {#Simple Simple}
     {#Structure (Complex @)}
     {#Reference Reference}
     {#Control (Control @)}
     {#Extension (Extension @)})))

(type .public Term
  (Ann Location
       (Term' (Ann Location))))

(type .public Operation
  (phase.Operation State))

(type .public Phase
  (phase.Phase State analysis.Term Term))

(with_template [<special> <general>]
  [(type .public <special>
     (<general> ..State analysis.Term Term))]

  [Handler   extension.Handler]
  [Bundle    extension.Bundle]
  [Extender  extension.Extender]
  )

(type .public Path
  (Path' Term))

(def .public path/pop
  Path
  {#Pop})

(with_template [<name> <kind>]
  [(def .public <name>
     (template (<name> content)
       [(.<| {..#Access}
             {<kind>}
             content)]))]

  [path/side   /access.#Side]
  [path/member /access.#Member]
  )

(with_template [<name> <access> <lefts> <right?>]
  [(def .public <name>
     (template (<name> lefts right?)
       [(.<| {..#Access}
             {<access>}
             [<lefts> lefts
              <right?> right?])]))]

  [side /access.#Side /side.#lefts /side.#right?]
  [member /access.#Member /member.#lefts /member.#right?]
  )

(with_template [<access> <side> <name>]
  [(def .public <name>
     (template (<name> lefts)
       [(<access> lefts <side>)]))]

  [..side #0 side/left]
  [..side #1 side/right]

  [..member #0 member/left]
  [..member #1 member/right]
  )

(with_template [<name> <tag>]
  [(def .public <name>
     (template (<name> content)
       [{<tag> content}]))]

  [path/bind ..#Bind]
  [path/then ..#Then]
  )

(with_template [<name> <tag>]
  [(def .public <name>
     (template (<name> left right)
       [{<tag> left right}]))]

  [path/alt  ..#Alt]
  [path/seq  ..#Seq]
  )

(type .public Abstraction
  (Abstraction' Term))

(type .public Apply
  (Apply' Term))

(def .public unit
  Text
  "")

(with_template [<with> <query> <tag> <type>]
  [(def .public (<with> value)
     (-> <type>
         (All (_ of)
           (-> (Operation of)
               (Operation of))))
     (phase.temporary (has <tag> value)))

   (def .public <query>
     (Operation <type>)
     (phase.read (the <tag>)))]

  [with_locals    locals    #locals    Nat]
  [with_currying? currying? #currying? Bit]
  )

(def .public with_new_local
  (All (_ of)
    (-> (Operation of)
        (Operation of)))
  (<<| (do phase.monad
         [locals ..locals])
       (..with_locals (++ locals))))

(with_template [<name> <tag>]
  [(def .public <name>
     (template (<name> <@> content)
       [[<@> {..#Simple {<tag> content}}]]))]

  [bit  /simple.#Bit]
  [i64  /simple.#I64]
  [f64  /simple.#F64]
  [text /simple.#Text]
  )

(with_template [<name> <tag>]
  [(def .public <name>
     (template (<name> <@> content)
       [(.<| [<@>]
             {..#Structure}
             {<tag>}
             content)]))]

  [variant analysis/complex.#Variant]
  [tuple   analysis/complex.#Tuple]
  )

(with_template [<name> <tag>]
  [(def .public <name>
     (template (<name> <@> content)
       [(.<| [<@>]
             {..#Reference}
             <tag>
             content)]))]

  [variable         reference.variable]
  [constant         reference.constant]
  [variable/local   reference.local]
  [variable/foreign reference.foreign]
  )

(with_template [<name> <family> <tag>]
  [(def .public <name>
     (template (<name> <@> content)
       [(.<| [<@>]
             {..#Control}
             {<family>}
             {<tag>}
             content)]))]

  [branch/when          ..#Branch   ..#When]
  [branch/exec          ..#Branch   ..#Exec]
  [branch/let           ..#Branch   ..#Let]
  [branch/if            ..#Branch   ..#If]
  [branch/get           ..#Branch   ..#Get]

  [loop/again           ..#Loop     ..#Again]
  [loop/scope           ..#Loop     ..#Scope]

  [function/abstraction ..#Function ..#Abstraction]
  [function/apply       ..#Function ..#Apply]
  )

(def .public (%path' %then value)
  (All (_ of)
    (-> (Format of)
        (Format (Path' of))))
  (when value
    {#Pop}
    "_"

    {#Bit_Fork test then else}
    (format "(?"
            " " (%.bit test) " " (%path' %then then)
            (when else
              {.#Some else}
              (format " " (%.bit (not test)) " " (%path' %then else))

              {.#None}
              "")
            ")")
    
    (^.with_template [<tag> <format>]
      [{<tag> item}
       (|> {.#Item item}
           (list#each (function (_ [test then])
                        (format (<format> test) " " (%path' %then then))))
           (text.interposed " ")
           (text.enclosed ["(? " ")"]))])
    ([#I64_Fork (|>> .int %.int)]
     [#F64_Fork %.frac]
     [#Text_Fork %.text])
    
    {#Access it}
    (/access.format it)
    
    {#Bind register}
    (format "(@ " (%.nat register) ")")
    
    {#Alt left right}
    (format "(| " (%path' %then left) " " (%path' %then right) ")")
    
    {#Seq left right}
    (format "(& " (%path' %then left) " " (%path' %then right) ")")
    
    {#Then then}
    (|> (%then then)
        (text.enclosed ["(! " ")"]))))

(def .public (%synthesis [_ value])
  (Format Term)
  (when value
    {#Simple it}
    (/simple.format it)

    {#Structure structure}
    (when structure
      {analysis/complex.#Variant [lefts right? content]}
      (|> (%synthesis content)
          (format (%.nat lefts) " " (%.bit right?) " ")
          (text.enclosed ["{" "}"]))
      
      {analysis/complex.#Tuple members}
      (|> members
          (list#each %synthesis)
          (text.interposed " ")
          (text.enclosed ["[" "]"])))

    {#Reference reference}
    (reference.format reference)

    {#Control control}
    (when control
      {#Function function}
      (when function
        {#Abstraction [environment arity body]}
        (let [environment' (|> environment
                               (list#each %synthesis)
                               (text.interposed " ")
                               (text.enclosed ["[" "]"]))]
          (|> (format environment' " " (%.nat arity) " " (%synthesis body))
              (text.enclosed ["{#function " "}"])))
        
        {#Apply func args}
        (|> args
            (list#each %synthesis)
            (text.interposed " ")
            (format (%synthesis func) " ")
            (text.enclosed ["(" ")"])))

      {#Branch branch}
      (when branch
        {#Exec this that}
        (|> (format (%synthesis this) " " (%synthesis that))
            (text.enclosed ["{#exec " "}"]))
        
        {#Let input register body}
        (|> (format (%.nat register) " " (%synthesis input) " " (%synthesis body))
            (text.enclosed ["{#let " "}"]))
        
        {#If test then else}
        (|> (format (%synthesis test) " " (%synthesis then) " " (%synthesis else))
            (text.enclosed ["{#if " "}"]))

        {#Get members record}
        (|> (format (%.list (%path' %synthesis)
                            (list#each (|>> {/access.#Member} {#Access}) members))
                    " " (%synthesis record))
            (text.enclosed ["{#get " "}"]))
        
        {#When input path}
        (|> (format (%synthesis input) " " (%path' %synthesis path))
            (text.enclosed ["{#when " "}"])))
      
      {#Loop loop}
      (when loop
        {#Scope scope}
        (|> (format (%.nat (the #start scope))
                    " " (|> (the #inits scope)
                            (list#each %synthesis)
                            (text.interposed " ")
                            (text.enclosed ["[" "]"]))
                    " " (%synthesis (the #iteration scope)))
            (text.enclosed ["{#loop " "}"]))
        
        {#Again args}
        (|> args
            (list#each %synthesis)
            (text.interposed " ")
            (text.enclosed ["{#again " "}"]))))

    {#Extension [[_ name] args]}
    (|> (list#each %synthesis args)
        (text.interposed " ")
        (format (%.text name) " ")
        (text.enclosed ["(" ")"]))))

(def .public %path
  (Format Path)
  (%path' %synthesis))

(def .public (path'_equivalence equivalence)
  (All (_ of)
    (-> (Equivalence of)
        (Equivalence (Path' of))))
  (implementation
   (def (= reference sample)
     (when [reference sample]
       [{#Pop} {#Pop}]
       true

       [{#Bit_Fork reference_when reference_then reference_else}
        {#Bit_Fork sample_when sample_then sample_else}]
       (and (bit#= reference_when sample_when)
            (= reference_then sample_then)
            (of (maybe.equivalence =) = reference_else sample_else))

       (^.with_template [<tag> <equivalence>]
         [[{<tag> reference_item}
           {<tag> sample_item}]
          (of (list.equivalence (product.equivalence <equivalence> =)) =
              {.#Item reference_item}
              {.#Item sample_item})])
       ([#I64_Fork (is (Equivalence I64) i64.equivalence)]
        [#F64_Fork f.equivalence]
        [#Text_Fork text.equivalence])
       
       (^.with_template [<tag> <equivalence>]
         [[{<tag> reference'} {<tag> sample'}]
          (of <equivalence> = reference' sample')])
       ([#Access /access.equivalence]
        [#Then   equivalence])
       
       [{#Bind reference'} {#Bind sample'}]
       (n.= reference' sample')

       (^.with_template [<tag>]
         [[{<tag> leftR rightR} {<tag> leftS rightS}]
          (and (= leftR leftS)
               (= rightR rightS))])
       ([#Alt]
        [#Seq])

       _
       false))))

(def (path'_hash super)
  (All (_ of)
    (-> (Hash of)
        (Hash (Path' of))))
  (implementation
   (def equivalence
     (..path'_equivalence (of super equivalence)))
   
   (def (hash value)
     (when value
       {#Pop}
       2

       {#Access access}
       (n.* 3 (of /access.hash hash access))

       {#Bind register}
       (n.* 5 (of n.hash hash register))

       {#Bit_Fork when then else}
       (all n.* 7
            (of bit.hash hash when)
            (hash then)
            (of (maybe.hash (path'_hash super)) hash else))

       (^.with_template [<factor> <tag> <hash>]
         [{<tag> item}
          (let [when_hash (product.hash <hash>
                                        (path'_hash super))
                item_hash (product.hash when_hash (list.hash when_hash))]
            (n.* <factor> (of item_hash hash item)))])
       ([11 #I64_Fork i64.hash]
        [13 #F64_Fork f.hash]
        [17 #Text_Fork text.hash])

       (^.with_template [<factor> <tag>]
         [{<tag> fork}
          (let [again_hash (path'_hash super)
                fork_hash (product.hash again_hash again_hash)]
            (n.* <factor> (of fork_hash hash fork)))])
       ([19 #Alt]
        [23 #Seq])

       {#Then body}
       (n.* 29 (of super hash body))
       ))))

(def (branch_equivalence (open "#[0]"))
  (All (_ of)
    (-> (Equivalence of)
        (Equivalence (Branch of))))
  (implementation
   (def (= reference sample)
     (when [reference sample]
       [{#Let [reference_input reference_register reference_body]}
        {#Let [sample_input sample_register sample_body]}]
       (and (#= reference_input sample_input)
            (n.= reference_register sample_register)
            (#= reference_body sample_body))

       [{#If [reference_test reference_then reference_else]}
        {#If [sample_test sample_then sample_else]}]
       (and (#= reference_test sample_test)
            (#= reference_then sample_then)
            (#= reference_else sample_else))
       
       [{#Get [reference_path reference_record]}
        {#Get [sample_path sample_record]}]
       (and (of (list.equivalence /member.equivalence) = reference_path sample_path)
            (#= reference_record sample_record))
       
       [{#When [reference_input reference_path]}
        {#When [sample_input sample_path]}]
       (and (#= reference_input sample_input)
            (of (path'_equivalence #=) = reference_path sample_path))
       
       _
       false))))

(def (branch_hash super)
  (All (_ of)
    (-> (Hash of)
        (Hash (Branch of))))
  (implementation
   (def equivalence
     (..branch_equivalence (of super equivalence)))
   
   (def (hash value)
     (when value
       {#Exec this that}
       (all n.* 2
            (of super hash this)
            (of super hash that))
       
       {#Let [input register body]}
       (all n.* 3
            (of super hash input)
            (of n.hash hash register)
            (of super hash body))

       {#If [test then else]}
       (all n.* 5
            (of super hash test)
            (of super hash then)
            (of super hash else))
       
       {#Get [path record]}
       (all n.* 7
            (of (list.hash /member.hash) hash path)
            (of super hash record))
       
       {#When [input path]}
       (all n.* 11
            (of super hash input)
            (of (..path'_hash super) hash path))
       ))))

(def (loop_equivalence (open "/#[0]"))
  (All (_ of)
    (-> (Equivalence of)
        (Equivalence (Loop of))))
  (implementation
   (def (= reference sample)
     (when [reference sample]
       [{#Scope [reference_start reference_inits reference_iteration]}
        {#Scope [sample_start sample_inits sample_iteration]}]
       (and (n.= reference_start sample_start)
            (of (list.equivalence /#=) = reference_inits sample_inits)
            (/#= reference_iteration sample_iteration))

       [{#Again reference} {#Again sample}]
       (of (list.equivalence /#=) = reference sample)
       
       _
       false))))

(def (loop_hash super)
  (All (_ of)
    (-> (Hash of)
        (Hash (Loop of))))
  (implementation
   (def equivalence
     (..loop_equivalence (of super equivalence)))
   
   (def (hash value)
     (when value
       {#Scope [start inits iteration]}
       (all n.* 2
            (of n.hash hash start)
            (of (list.hash super) hash inits)
            (of super hash iteration))

       {#Again resets}
       (all n.* 3
            (of (list.hash super) hash resets))
       ))))

(def (function_equivalence (open "#[0]"))
  (All (_ of)
    (-> (Equivalence of)
        (Equivalence (Function of))))
  (implementation
   (def (= reference sample)
     (when [reference sample]
       [{#Abstraction [reference_environment reference_arity reference_body]}
        {#Abstraction [sample_environment sample_arity sample_body]}]
       (and (of (list.equivalence #=) = reference_environment sample_environment)
            (n.= reference_arity sample_arity)
            (#= reference_body sample_body))
       
       [{#Apply [reference_abstraction reference_arguments]}
        {#Apply [sample_abstraction sample_arguments]}]
       (and (#= reference_abstraction sample_abstraction)
            (of (list.equivalence #=) = reference_arguments sample_arguments))
       
       _
       false))))

(def (function_hash super)
  (All (_ of)
    (-> (Hash of)
        (Hash (Function of))))
  (implementation
   (def equivalence
     (..function_equivalence (of super equivalence)))
   
   (def (hash value)
     (when value
       {#Abstraction [environment arity body]}
       (all n.* 2
            (of (list.hash super) hash environment)
            (of n.hash hash arity)
            (of super hash body))
       
       {#Apply [abstraction arguments]}
       (all n.* 3
            (of super hash abstraction)
            (of (list.hash super) hash arguments))
       ))))

(def (control_equivalence (open "#[0]"))
  (All (_ of)
    (-> (Equivalence of)
        (Equivalence (Control of))))
  (implementation
   (def (= reference sample)
     (when [reference sample]
       (^.with_template [<tag> <equivalence>]
         [[{<tag> reference} {<tag> sample}]
          (of (<equivalence> #=) = reference sample)])
       ([#Branch ..branch_equivalence]
        [#Loop ..loop_equivalence]
        [#Function ..function_equivalence])
       
       _
       false))))

(def (control_hash super)
  (All (_ of)
    (-> (Hash of)
        (Hash (Control of))))
  (implementation
   (def equivalence
     (..control_equivalence (of super equivalence)))

   (def (hash value)
     (when value
       (^.with_template [<factor> <tag> <hash>]
         [{<tag> value}
          (n.* <factor> (of (<hash> super) hash value))])
       ([2 #Branch ..branch_hash]
        [3 #Loop ..loop_hash]
        [5 #Function ..function_hash])
       ))))

(def .public equivalence
  (Equivalence Term)
  (implementation
   (def (= [_ reference] [_ sample])
     (when [reference sample]
       (^.with_template [<tag> <equivalence>]
         [[{<tag> reference'} {<tag> sample'}]
          (of <equivalence> = reference' sample')])
       ([#Simple /simple.equivalence]
        [#Structure (analysis/complex.equivalence =)]
        [#Reference reference.equivalence]
        [#Control (control_equivalence =)]
        [#Extension (extension.equivalence =)])

       _
       false))))

(def .public path_equivalence
  (Equivalence Path)
  (path'_equivalence equivalence))

(def .public hash
  (Hash Term)
  (implementation
   (def equivalence ..equivalence)

   (def (hash value)
     (let [again_hash [..equivalence hash]]
       (when value
         (^.with_template [<factor> <tag> <hash>]
           [[_ {<tag> value}]
            (n.* <factor> (of <hash> hash value))])
         ([02 #Simple /simple.hash]
          [03 #Structure (analysis/complex.hash again_hash)]
          [05 #Reference reference.hash]
          [07 #Control (..control_hash again_hash)]
          [11 #Extension (extension.hash again_hash)]))))))

(def .public !bind_top
  (template (!bind_top register thenP)
    [(all ..path/seq
          {..#Bind register}
          {..#Pop}
          thenP)]))

(def .public !multi_pop
  (template (!multi_pop nextP)
    [(all ..path/seq
          {..#Pop}
          {..#Pop}
          nextP)]))

... TODO: There are sister patterns to the simple side checks for tuples.
... These correspond to the situation where tuple members are accessed
... and bound to variables, but those variables are never used, so they
... become POPs.
... After re-implementing unused-variable-elimination, must add those
... pattern-optimizations again, since a lot of BINDs will become POPs
... and thus will result in useless code being translated.
(with_template [<name> <side>]
  [(def .public <name>
     (template (<name> idx nextP)
       [(all ..path/seq
             (<side> idx)
             {..#Pop}
             nextP)]))]

  [simple_left_side ..side/left]
  [simple_right_side ..side/right]
  )