QP_atom_from_string(), QP_atom_from_padded_string()

Synopsis

     #include <quintus/quintus.h>
     
     QP_atom QP_atom_from_string(string)
     char *string;
     

Returns the canonical representation of the atom whose printed representation is the (null-terminated) string string.

     QP_atom QP_atom_from_padded_string(p_atom, p_string, p_length)
     QP_atom *p_atom;
     char    *p_string;
     int     *p_length;
     

Computes the canonical representation of the atom whose printed representation is the (blank-padded) string p_string in a character array of length p_length.

Description

QP_atom_from_string() returns the canonical representation of the atom whose printed representation is string. string must be a valid null-terminated string. The string is copied and internalised by Prolog and the foreign function can reuse the string and its space.

QP_atom_from_padded_string() is useful for Pascal and FORTRAN and can be used with any language that has a C-compatible calling convention for passing integers and pointers (on the user's platform). e.g. some Pascal and FORTRAN compilers running under UNIX.

p_string is a pointer to a character array and p_length is a pointer to an integer specifying the length of the array. QP_atom_from_padded_string() sets the atom referenced by p_atom to the canonical representation of the atom whose printed representation is the string (less any trailing blanks) in the character array. It returns the length of the resulting atom (not the character array's length) as the function value.

Examples

rev_atom() is a C function that takes an atom and returns an atom whose string representation is the reverse of the string representation of the atom passed in.

                                     
foo.pl
foreign(rev_atom, c, rev_atom(+atom, [-atom])).
                                      
foo.c
QP_atom rev_atom(atom) QP_atom atom; { char *string[MAX_ATOM_LEN]; strcpy(string, QP_string_from_atom(atom)); reverse(string); /* reverses string in place */ return QP_atom_from_string(string); }

Giving:

     | ?- rev_atom(draw, X).
     
     X = ward
     
     yes
     | ?-
     

See Also

QP_string_from_atom(), QP_padded_string_from_atom() fli-p2f-atm