<commit_before>(define-library (picrin experimental lambda)
  (import (rename (scheme base)
                  (lambda lambda%))
          (picrin macro))

  (define uniq
    (let ((counter 0))
      (lambda% ()
        (let ((sym (string->symbol (string-append "lv$" (number->string counter)))))
          (set! counter (+ counter 1))
          sym))))

  (define-syntax lambda
    (ir-macro-transformer
     (lambda% (form inject compare)

       (define (bind val args)
         (cond
          ((symbol? args)
           `(define ,args ,val))
          ((pair? args)
           (let ((a (uniq))
                 (b (uniq)))
             `(begin
                (define ,a (car ,val))
                (define ,b (cdr ,val))
                ,(bind a (car args))
                ,(bind b (cdr args)))))
          ((vector? args)
           ;; TODO
           (error "fixme"))
          (else
           `(unless (equal? ,val ',args)
              (error "match failure" ,val ',args)))))

       (let ((args (car (cdr form)))
             (body (cdr (cdr form))))
         (let ((var (uniq)))
          `(lambda% ,var ,(bind var args) ,@body))))))

  (export lambda))<commit_msg>refactor destructuring-lambda<commit_after>(define-library (picrin experimental lambda)
  (import (rename (scheme base)
                  (lambda lambda%))
          (picrin macro))

  (define-syntax bind
    (ir-macro-transformer
     (lambda% (form inject compare)
       (let ((formal (car (cdr form)))
             (value  (car (cdr (cdr form))))
             (body   (cdr (cdr (cdr form)))))
         (cond
          ((symbol? formal)
           `(let ((,formal ,value))
              ,@body))
          ((pair? formal)
           `(let ((value# ,value))
              (bind ,(car formal) (car value#)
                (bind ,(cdr formal) (cdr value#)
                  ,@body))))
          ((vector? formal)
           ;; TODO
           (error "fixme"))
          (else
           `(if (equal? ,value ',formal)
                (begin
                  ,@body)
                (error "match failure" ,value ',formal))))))))

  (define-syntax lambda
    (ir-macro-transformer
     (lambda% (form inject compare)
       (let ((args (car (cdr form)))
             (body (cdr (cdr form))))
         `(lambda% formal# (bind ,args formal# ,@body))))))

  (export lambda))
{'fraction_non_alphanumeric': 0.15971039182282795, 'fraction_numerical': 0.0008517887563884157, 'mean_word_length': 1.589856670341786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2122341', 'n_tokens_mistral': 711, 'n_tokens_neox': 676, 'n_words': 204}