Skip to content

Instantly share code, notes, and snippets.

@shubhamkumar13
Created August 16, 2021 00:47
Show Gist options
  • Save shubhamkumar13/5deec7204a1365d71629212e3755fccf to your computer and use it in GitHub Desktop.
Save shubhamkumar13/5deec7204a1365d71629212e3755fccf to your computer and use it in GitHub Desktop.
SDF dsl exercise
(define (spread-combine h f g)
(let ((n (get-arity f)) (m (get-arity g)))
(let ((t (+ n m)))
(define (the-combination . args)
(assert (= (length args) t))
(h (apply f (list-head args n))
(apply g (list-tail args n))
)
)
(restrict-arity the-combination t)
)
)
)
(define (restrict-arity proc nargs)
(hash-table-set! arity-table proc nargs)
proc
)
(define (get-arity proc)
(or (hash-table-ref arity-table proc #f)
(let ((a (procedure-arity proc)))
(assert (eqv? (procedure-arity-min a)
(procedure-arity-max a)
)
)
(procedure-arity-min a)
)
)
)
(define arity-table (make-key-weak-eqv-hash-table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment