s c h e m a t i c s : c o o k b o o k

/ Cookbook.IdiomDocumentedProcedures

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Accessing Procedure Source Code

Problem

JavaScript? programmers are familiar with accessing the source code of a procedure at runtime. Can we do this in Scheme?

We would also like to store other meta-information about a procedure, say, to provide a documentation string for the procedure, similar to Emacs Lisp doc-strings.

Solution

The answer is a qualified "yes," provided that the procedure is created with a special form described here.

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Discussion

The doc-lambda macro turns its source code into an S-expression by quoting it and storing it in a struct. It creates the actual procedure and stores that in the struct as well, along with the provided documentation string.

The struct is executable as a procedure thanks to MzScheme's "structs as procedures" (see chapter 4.6 in the MzScheme language manual): the final argument to make-struct-type tells MzScheme to treat the 0th item in the struct as the procedure to invoke when the struct is applied as a procedure.


Comments about this recipe

Contributors

-- DaveHerman - 16 May 2006

CookbookForm
TopicType: Recipe
ParentTopic: IdiomRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest