Node:Transforming Scheme name to C name, Next:Structuring argument lists for C functions, Up:Primitives
Normally, the name of a C function can be derived given its Scheme name, using some simple textual transformations:
-
(hyphen) with _
(underscore).
?
(question mark) with "_p".
!
(exclamation point) with "_x".
->
with "_to_".
<=
(less than or equal) with "_leq".
>=
(greater than or equal) with "_geq".
<
(less than) with "_less".
>
(greater than) with "_gr".
@
with "at". [Omit?]
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))