Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samth
Created April 21, 2011 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samth/935350 to your computer and use it in GitHub Desktop.
Save samth/935350 to your computer and use it in GitHub Desktop.
lambda/prop in Racket
#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)
@samth
Copy link
Author

samth commented Apr 21, 2011

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