[CM] Question about unexpected let binding behaviour

chohag at jtan.com chohag at jtan.com
Tue Apr 21 11:47:24 PDT 2026


I don't know if this is a bug or just a bit strange. At least it's
not in the optimiser this time. I think. It's possible for a let
to have multiple bindings of the same symbol:

        (define l (inlet 'a 24 'a '(* 6 7))) ; backwards
        (format #t "list ~A\n" (map values l))
        (format #t "a ~A\n" (l 'a))
        ; list ((a . 24) (a * 6 7)) ; aside: it's obvious why this isn't
                                    ; (a . (* 6 7)) but sh/could it be?
        ; a (* 6 7)

        (set! (l 'a) (* 7 6))
        (format #t "list ~A\n" (map values l))
        (format #t "a ~A\n" (l 'a))
        ; list ((a . 24) (a . 42))
        ; a 42

        (varlet l 'a 21)
        (format #t "list ~A\n" (map values l))
        (format #t "a ~A\n" (l 'a))
        ; list ((a . 21) (a . 24) (a . 42))
        ; a 21

        (set! (l 'a) 84)
        (format #t "list ~A\n" (map values l))
        (format #t "a ~A\n" (l 'a))
        ; list ((a . 84) (a . 24) (a . 42))
        ; a 84

        (varlet l 'a 'question)
        (format #t "list ~A\n" (map values l))
        (format #t "a ~A\n" (l 'a))
        ; list ((a . question) (a . 84) (a . 24) (a . 42))
        ; a question

Why do the first and second forms evaluate to the last binding in
the list but the later forms (after varlet) the first?

But most importantly, is this consistent or is it happening this
way by chance, or in other words can I rely on it happening like
this? It seems to work but I don't like relying on "it seems to".

Or, of course, is this a bug and those extra bindings should have
been removed? Notably, straight let doesn't let (!) you do that:

        ./s7 '(display (let ((a 1) (a 2)) (curlet)))'

        ;duplicate identifier in let: a in (let ((a 1) (a 2)) (curlet))

Matthew


More information about the Cmdist mailing list