| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Guile's application programming interface (API) makes functionality available that an application developer can use in either C or Scheme programming. The interface consists of elements that may be macros, functions or variables in C, and procedures, variables, syntax or other types of object in Scheme. Broadly speaking, the interface as a whole can be divided into three groups.
Functions/procedures in the first group are often known as
primitives, subrs or builtins. An example is the
assq Scheme procedure, which is also available as scm_assq
in C.
Elements in the second and third groups exist because they provide
additional language-specific benefits in either Scheme or C. Examples
are the C macro SCM_CONSP, which is faster and more convenient in
C programming than the primitive scm_pair_p, and the
procedure-with-setter make-object-property, which provides a
more convenient property handling interface in Scheme than the
primitives on which it is based.
20.1 Identical Function in both Scheme and C Identical function for Scheme and C. 20.2 Elements Available Only in C Elements only available in C. 20.3 Elements Available Only in Scheme Elements only available in Scheme. 20.4 Reference Material Layout The layout of this part of the manual.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
They form the majority of the API, and allow both C and Scheme programmers to perform identical operations.
Scheme procedures marked "primitive functions" have a regular interface when calling from C, reflected in two areas: the name of a C function, and the convention for passing non-required arguments to this function.
20.1.1 Transforming Scheme name to C name 20.1.2 Structuring argument lists for C functions
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The C function's arguments will be all of the Scheme procedure's
arguments, both required and optional; if the Scheme procedure takes a
"rest" argument, that will be a final argument to the C function. The
C function's arguments, as well as its return type, will be SCM.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For C this is usually a matter of better performance (e.g. the
SCM_CONSP macro) or of accepting C language types rather than the
generic SCM.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This part of the reference manual documents all of Guile's core Scheme-level language and features in functionally-related groups. Where a particular section of the manual includes both R5RS-compliant parts and Guile-specific extensions, the text indicates which parts of the documentation describe R5RS behaviour and which parts describe Guile extensions.
For a quick way of identifying the parts of Guile that implement R5RS-compliant features, see the R5RS index: R5RS Index.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |