home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / library / prolo_c / exampl65.c < prev    next >
Text File  |  1986-10-06  |  2KB  |  61 lines

  1. /*
  2.   The following C functions can be compiled with any compiler
  3.   that meets the following criteria:
  4.  
  5.     1) you must be able to compile to large memory model;
  6.     2) the compiler must not place an '_' after the names of public
  7.        identifiers;
  8.     3) the compiler must be capable of producing object files
  9.        compatible with the DOS linker;
  10.     4) you can turn off stack checking.  For example, if you are using
  11.        Lattice C, use the -v option.
  12.  
  13.   It is important that your compiler NOT reference its own startup code
  14.   in the course of simple function calls.
  15.  
  16.   the two C structures below are equivalent to the following:
  17.  
  18.   domains
  19.     ilist = integer*
  20.     ifunc = f(integer)
  21.  
  22.   A string can be passed bound as  char *string; or free as
  23.   char **string;
  24.  
  25.   For more information on parameter passing,
  26.   see page 156 of the reference manual.
  27. */
  28.  
  29. struct ilist {
  30.        char functor;           /* type of the list */
  31.        int  val;               /* the actual element */
  32.        struct ilist *next;     /* pointer to next node */
  33. };
  34.  
  35. struct ifunc {
  36.        char type;              /* type of functor */
  37.        int  value;             /* value of the functor */
  38. };
  39.  
  40. clist_0(in, out)
  41. struct ilist *in;
  42. struct ifunc **out;
  43. {
  44.        (*out)->value = in->val; /* this sets out to f(X) */
  45.        (*out)->type = 1;        /* set the functor type */
  46. }
  47.  
  48. clist_1(out, in)
  49. struct ilist **out;
  50. struct ifunc *in;
  51. {
  52.        int temp = 0;
  53.  
  54.        temp = in->value;
  55.        temp += temp;
  56.        (*out)->val = temp;      /* this returns [2*X] as a list */
  57.        (*out)->functor = 1;     /* set the list type.  If this is not */
  58.                                 /* done, no meaningful value will be  */
  59.                                 /* returned */
  60. }
  61.