Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

lambda/prop in Racket

View lambda-prop.rkt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#lang racket
 
(struct proc/prop (f v)
#:property prop:procedure 0)
 
(define (procedure-property p [fail #f])
(if (proc/prop? p)
(proc/prop-v p)
fail))
 
(define-syntax-rule (lambda/prop #:prop e formals . body)
(proc/prop (λ formals . body)
e))
 
(provide lambda/prop procedure-property)
Owner
samth commented

A sample interaction:

> (define f (lambda/prop #:prop 3 (x) x))
> f
#<procedure>
> (f 4)
4
> (procedure-property f)
3
> (procedure-property +)
#f
> (procedure-property + 'nope)
'nope
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.