Created
August 16, 2021 00:47
-
-
Save shubhamkumar13/5deec7204a1365d71629212e3755fccf to your computer and use it in GitHub Desktop.
SDF dsl exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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