Re: Suggestion: ephemeron-case
Daphne Preston-Kendal 09 Oct 2025 12:33 UTC
> Am So., 3. Aug. 2025 um 17:29 Uhr schrieb Marc Nieper-Wißkirchen
> <xxxxxx@gmail.com>:
>>
>> Maybe I don't understand the semantics of your ephemeron-case form.
>> Reading your first post, there does not seem to be a reference barrier
>> on the key in the broken path. Can you give a syntax-case definition
>> of ephemeron case?
(define-syntax ephemeron-case
(syntax-rules (else)
((_ eph-expr
((k-id . v-id) expr_0 expr_1 ...)
(else broken-expr_0 broken-expr_1 ...))
(let* ((eph eph-expr)
(k (ephemeron-key eph))
(v (ephemeron-value eph))) ; why has this name been changed? grr
(if (ephemeron-broken? eph)
(begin broken-expr_0 broken-expr_1 ...)
(let-syntax ((k-id (identifier-syntax k))
(v-id (identifier-syntax v)))
(dynamic-wind
(lambda () #f)
(lambda () expr_0 expr_1 ...)
(lambda () (reference-barrier k)))))))))
> On 3 Aug 2025, at 17:30, Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:
>
> PS And maybe give a simple example of how a user would typically use it.
(define (ephemeron-alist-ref ephal key)
(let loop ((more ephal))
(if (null? more)
(assertion-violation 'ephemeron-alist-ref "nothing found for key" ephal)
(ephemeron-case (car ephal)
((found-key . value)
(if (eqv? found-key value)
value
(loop (cdr more))))
(else (loop (cdr more)))))))
Daphne