git @ Cat's Eye Technologies Robin / master stdlib / delete.robin
master

Tree @master (Download .tar.gz)

delete.robin @masterraw · history · blame

;'<<SPEC'

<!--
Copyright (c) 2012-2024, Chris Pressey, Cat's Eye Technologies.
This file is distributed under a 2-clause BSD license.  See LICENSES/ dir.
SPDX-License-Identifier: LicenseRef-BSD-2-Clause-X-Robin
-->

### `delete` ###

    -> Tests for functionality "Evaluate Robin Expression (with List)"

`delete` evaluates its first argument to a value of any type, and its
second argument to obtain an alist.  A new alist is returned which
contains no pairs whose first element are equal to the given element.

    | (delete (literal b) (literal ((a 1) (b 2) (c 3))))
    = ((a 1) (c 3))

All pairs with the given element as key are removed.

    | (delete (literal b) (literal ((a 1) (b 2) (c 3) (b 4))))
    = ((a 1) (c 3))

If there are no pairs with the given element as key, the same alist
is returned unchanged.

    | (delete (literal r) (literal ((a 1) (b 2) (c 3))))
    = ((a 1) (b 2) (c 3))

The following should be true for any identifier i and alist x.

    | (let ((i (literal a))
    |       (x (literal ((a 5) (b 7)))))
    |   (lookup i (delete i x)))
    = ()

    | (delete (literal q) 55)
    ? abort (expected-list 55)

    | (delete (literal q) (literal ((a 7) 99 (q 4))))
    ? abort (expected-list 99)

'<<SPEC'

(define delete (fun (id alist)
  (filter (fun (x) (if (equal? (head x) id) #f #t)) alist)))