ob-scheme.el 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;; ob-scheme.el --- org-babel functions for Scheme
  2. ;; Copyright (C) 2010 Free Software Foundation
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research, scheme
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Now working with SBCL for both session and external evaluation.
  24. ;;
  25. ;; This certainly isn't optimally robust, but it seems to be working
  26. ;; for the basic use cases.
  27. ;;; Requirements:
  28. ;; - a working scheme implementation
  29. ;; (e.g. guile http://www.gnu.org/software/guile/guile.html)
  30. ;;; Code:
  31. (require 'ob)
  32. (require 'ob-eval)
  33. (defvar org-babel-default-header-args:scheme '()
  34. "Default header arguments for scheme code blocks.")
  35. (defcustom org-babel-scheme-cmd "guile"
  36. "Name of command used to evaluate scheme blocks."
  37. :group 'org-babel
  38. :type 'string)
  39. (defun org-babel-expand-body:scheme (body params &optional processed-params)
  40. "Expand BODY according to PARAMS, return the expanded body."
  41. (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
  42. (if (> (length vars) 0)
  43. (concat "(let ("
  44. (mapconcat
  45. (lambda (var) (format "%S" (print `(,(car var) ',(cdr var)))))
  46. vars "\n ")
  47. ")\n" body ")")
  48. body)))
  49. (defun org-babel-execute:scheme (body params)
  50. "Execute a block of Scheme code with org-babel.
  51. This function is called by `org-babel-execute-src-block'"
  52. (let* ((processed-params (org-babel-process-params params))
  53. (session (not (string= (nth 0 processed-params) "none")))
  54. (result-type (nth 3 processed-params))
  55. (full-body (org-babel-expand-body:scheme body params processed-params)))
  56. (read
  57. (if session
  58. ;; session evaluation
  59. (error "Scheme sessions are not yet supported.")
  60. ;; external evaluation
  61. (let ((script-file (org-babel-temp-file "lisp-script-")))
  62. (with-temp-file script-file
  63. (insert
  64. ;; return the value or the output
  65. (if (string= result-type "value")
  66. (format "(display %s)" full-body)
  67. full-body)))
  68. (org-babel-eval
  69. (format "%s %s" org-babel-scheme-cmd script-file) ""))))))
  70. (defun org-babel-prep-session:scheme (session params)
  71. "Prepare SESSION according to the header arguments specified in PARAMS."
  72. (error "not yet implemented"))
  73. (defun org-babel-scheme-initiate-session (&optional session)
  74. "If there is not a current inferior-process-buffer in SESSION
  75. then create. Return the initialized session."
  76. (error "Scheme sessions are not yet supported."))
  77. (provide 'ob-scheme)
  78. ;; arch-tag: 6b2fe76f-4b25-4e87-ad1c-225b2f282a71
  79. ;;; ob-scheme.el ends here