Skip to content

[#544] Add `CAR k` and `CDR k` macros

Description

This MR adds the newest CAR k and CDR k macros introduced with edo. CAR k gets the 2k+1-th element of a right-combed pair, and CDR k gets the 2k-th element of a right-combed pair. Support for the new macros is also added in Lorentz.

For example, given the following right-combed pair:

    0      Depth: 0
   / \            |
  1   2           1
     / \          |
    3   4         2

The following observations are made:

  • CAR 0 and CAR 1 are equivalent to CAR and CDAR, respectively.
  • More specifically, CAR k is equivalent to CDR repeated k times followed by CAR.
  • CDR 0 is equivalent to a no-op. CDR 1 and CDR 2 are equivalent to CDR and CDDR, respectively.
  • GET 0 works with any type (not only pair) and so CDR 0 also works with any type.
  • More specifically, CDR k is equivalent to CDR repeated k times.
  • CAR k is simply { GET (2k+1) } and CDR k is simply { GET (2k) }.
  • CDR k can be also thought as traversing the right-combed pair to a depth of k from the top.

Related issue(s)

Resolves #544 (closed)

Checklist for your Merge Request

Related changes (conditional)

  • Tests (see short guidelines)

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Heitor Toledo Lassarote de Paula

Merge request reports