Skip to content

subst/proc captures free variable #274

Closed

Description

@ccshan

Hello, I'm following the tutorial but trying to define unrestricted beta-reduction for the untyped lambda calculus:

#lang racket
(require (only-in redex/reduction-semantics
                  define-language redex-match define-metafunction term
                  reduction-relation --> in-hole apply-reduction-relation)
         (only-in redex/tut-subst subst/proc))

(define-language L
  (e (e e)
     (λ x e)
     x)
  (x variable-not-otherwise-mentioned)
  (E (E e)
     (e E)
     hole))

(define x? (redex-match L x))

(define-metafunction L
  subst : x e_1 e_0 -> e
  [(subst x e_1 e_0)
   ,(subst/proc x? (list (term x)) (list (term e_1)) (term e_0))])

(define red
  (reduction-relation
   L
   #:domain e
   (--> (in-hole E ((λ x e_0) e_1))
        (in-hole E (subst x e_1 e_0))
        "β")))

(define twice '(λ f1 (λ x9 (f1 (f1 x9)))))
(define redex-with-x1-free `(,twice (,twice x1)))
(define result-without-x1-free
  (for/or ((result (apply-reduction-relation red redex-with-x1-free)))
    (match result (`(λ x1 ,_) result) (_ #f))))
result-without-x1-free

There seems to be a bug in subst/proc that turns a term with x1 free into a term without x1 free.

Activity

  1. ccshan commented on Feb 26, 2026

    @ccshan
    ContributorAuthor

    It looks like fvs needs a case for "(λ x ... e) for untyped".

  2. added a commit that references this issue on Feb 26, 2026
  3. rfindler commented on Feb 26, 2026

    @rfindler
    Member

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions