Next: , Up: Primitives


20.1.1 Transforming Scheme name to C name

Normally, the name of a C function can be derived given its Scheme name, using some simple textual transformations:

Here is an Emacs Lisp command that prompts for a Scheme function name and inserts the corresponding C function name into the buffer.

     (defun insert-scheme-to-C (name &optional use-gh)
       "Transforms Scheme NAME, a string, to its C counterpart, and inserts it.
     Prefix arg non-nil means use \"gh_\" prefix, otherwise use \"scm_\" prefix."
       (interactive "sScheme name: \nP")
       (let ((transforms '(("-"  . "_")
                           ("?"  . "_p")
                           ("!"  . "_x")
                           ("->" . "_to_")
                           ("<=" . "_leq")
                           (">=" . "_geq")
                           ("<"  . "_less")
                           (">"  . "_gr")
                           ("@"  . "at"))))
         (while transforms
           (let ((trigger (concat "\\(.*\\)"
                                  (regexp-quote (caar transforms))
                                  "\\(.*\\)"))
                 (sub (cdar transforms))
                 (m nil))
             (while (setq m (string-match trigger name))
               (setq name (concat (match-string 1 name)
                                  sub
                                  (match-string 2 name)))))
           (setq transforms (cdr transforms))))
       (insert (if use-gh "gh_" "scm_") name))