README 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. -*- outline -*-
  2. * Overview
  3. This directory includes an example program for extending Guile with a
  4. new (and even useful) data type, putting it into a shared library, so it
  5. can be called from an unmodified guile interpreter. Further, the shared
  6. library defines a new guile module.
  7. * Build Instructions
  8. To build the example, simply type
  9. make libbox-module
  10. in this directory.
  11. * The Box Data Type
  12. A box is simply an object for storing one other object in. It can be
  13. used for passing parameters by reference, for example. You simply
  14. store an object into a box, pass it to another procedure which can
  15. store a new object into it and thus return a value via the box.
  16. ** Usage
  17. Box objects are created with `make-box', set with `box-set!' and
  18. examined with `box-ref'. Note that these procedures are placed in a
  19. module called (box-module) and can thus only be accessed after using
  20. this module. See the following example session for usage details.
  21. ** The Module (box-module)
  22. Extend your LD_LIBRARY_PATH variable (or equivalent) to include . and
  23. .libs and make sure that your current working directory is the one
  24. this file is contained in.
  25. $ guile
  26. guile> (use-modules (box-module))
  27. guile> (define b (make-box))
  28. guile> b
  29. #<box #f>
  30. guile> (box-set! b '(list of values))
  31. guile> b
  32. #<box (list of values)>
  33. guile> (box-ref b)
  34. (list of values)
  35. guile> (quit)
  36. $
  37. ** The Module (box-mixed)
  38. The following example uses the module (box-mixed), also included in
  39. this directory. It uses the shared library libbox-module like the
  40. module (box-module) above, but does not export the procedures from
  41. that module. It only implements some procedures for dealing with box
  42. objects.
  43. $ guile
  44. guile> (use-modules (box-mixed))
  45. guile> (define bl (make-box-list 1 2 3))
  46. guile> bl
  47. (#<box 1> #<box 2> #<box 3>)
  48. guile> (box-map 1+ bl)
  49. (#<box 2> #<box 3> #<box 4>)
  50. guile> (quit)
  51. $
  52. If you like this example so much that you want to have it available
  53. for normal usage, install the dynamic libraries in the .libs directory
  54. to the directory $(prefix)/lib and the scheme file `box-module.scm' in
  55. a directory in your GUILE_LOAD_PATH.