public
Created

lambda/prop in Racket

  • Download Gist
lambda-prop.rkt
Racket
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)

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
> 

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.