Changeset 8013 in project


Ignore:
Timestamp:
01/31/08 19:37:02 (12 years ago)
Author:
Kon Lovett
Message:

Expanded example.

Location:
release/3/procedure-decoration
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/procedure-decoration/tags/1.0/procedure-decoration.wiki

    r7997 r8013  
    211211
    212212<enscript language=scheme>
     213(use procedure-decoration)
     214(use (srfi 89))
     215
    213216;; Procedure documentation string API
    214217(define-procedure-extender docstring procedure-documentation documented-procedure?)
    215218
     219;; Procedure documentation 'define' wrappers
     220
     221; Common code helper
     222(define-macro ($define/doc ?defknd ?head ?docstr ?body)
     223  (let ([nam (let loop ([hd ?head])
     224               (if (pair? hd)
     225                   (loop (car hd))
     226                   hd))])
     227    `(begin
     228       (,?defknd ,?head ,@?body)
     229       (set! (procedure-documentation ,nam) ,?docstr)
     230       (begin) ) ) )
     231
     232; Chicken 'define'
     233(define-macro (define/doc ?head ?docstr . ?body)
     234  `($define/doc define ,?head ,?docstr ,?body) )
     235
     236; Chicken SRFI-89 'define*'
     237(define-macro (define*/doc ?head ?docstr . ?body)
     238  `($define/doc define* ,?head ,?docstr ,?body) )
     239
    216240;; Try it out
    217 (define (test-proc) #t)                                         ;=>
    218 (documented-procedure? test-proc)                               ;=> #f
    219 (set! (procedure-documentation test-proc) "test-proc is foo")   ;=>
    220 (procedure-documentation test-proc)                             ;=> "test-proc is foo"
     241
     242(define/doc (foo . args)
     243  "procedure is foo"
     244  #t )
     245
     246(procedure-documentation foo) ;=> "procedure is foo"
     247
     248(define*/doc (h2 (key: k #f) a . r) "h2 is srfi-89 proc" (list a k r))
     249
     250(procedure-documentation h2) ;=> "h2 is srfi-89 proc"
    221251</enscript>
    222252
  • release/3/procedure-decoration/trunk/procedure-decoration.wiki

    r7997 r8013  
    211211
    212212<enscript language=scheme>
     213(use procedure-decoration)
     214(use (srfi 89))
     215
    213216;; Procedure documentation string API
    214217(define-procedure-extender docstring procedure-documentation documented-procedure?)
    215218
     219;; Procedure documentation 'define' wrappers
     220
     221; Common code helper
     222(define-macro ($define/doc ?defknd ?head ?docstr ?body)
     223  (let ([nam (let loop ([hd ?head])
     224               (if (pair? hd)
     225                   (loop (car hd))
     226                   hd))])
     227    `(begin
     228       (,?defknd ,?head ,@?body)
     229       (set! (procedure-documentation ,nam) ,?docstr)
     230       (begin) ) ) )
     231
     232; Chicken 'define'
     233(define-macro (define/doc ?head ?docstr . ?body)
     234  `($define/doc define ,?head ,?docstr ,?body) )
     235
     236; Chicken SRFI-89 'define*'
     237(define-macro (define*/doc ?head ?docstr . ?body)
     238  `($define/doc define* ,?head ,?docstr ,?body) )
     239
    216240;; Try it out
    217 (define (test-proc) #t)                                         ;=>
    218 (documented-procedure? test-proc)                               ;=> #f
    219 (set! (procedure-documentation test-proc) "test-proc is foo")   ;=>
    220 (procedure-documentation test-proc)                             ;=> "test-proc is foo"
     241
     242(define/doc (foo . args)
     243  "procedure is foo"
     244  #t )
     245
     246(procedure-documentation foo) ;=> "procedure is foo"
     247
     248(define*/doc (h2 (key: k #f) a . r) "h2 is srfi-89 proc" (list a k r))
     249
     250(procedure-documentation h2) ;=> "h2 is srfi-89 proc"
    221251</enscript>
    222252
Note: See TracChangeset for help on using the changeset viewer.