home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part03 / interp / F_ss.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-05  |  2.4 KB  |  72 lines

  1.  
  2. /****** F_ss.c ********************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:  July 4, 1985          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include "struct.h"
  25. #include "node.h"
  26.  
  27. /*************************** Searching and Sorting ***************************/
  28.  
  29. /*
  30.  * F_Assoc
  31.  *
  32.  * Just like LISP assoc, except that #f is returned if the key is not found.
  33.  *
  34.  * [association-list,key] | assoc == element of association list or #f
  35.  */
  36. private F_Assoc (InOut)
  37.    ObjectPtr InOut;
  38.    {
  39.       register ListPtr P;
  40.       register ObjectPtr Key;
  41.  
  42.       if (!PairTest (InOut,1<<LIST,~0))
  43.       FunError (ArgSeqOb,InOut);
  44.  
  45.       else {
  46.  
  47.      P = InOut->List;
  48.      Key = &P->Next->Val;
  49.  
  50.      for (P = P->Val.List; P != NULL; P=P->Next)
  51.         if (P->Val.Tag != LIST) {
  52.            FunError ("element not sequence",InOut);
  53.            return;
  54.         } else
  55.            if (ObEqual (&P->Val.List->Val,Key)) {
  56.           RepObject (InOut,&P->Val);
  57.           return;
  58.            }
  59.  
  60.      RepBool (InOut,0);     /* key not found, return #f */
  61.       }
  62.    }
  63.  
  64.  
  65. void D_ss ()
  66.    {
  67.       (void) PrimDef (F_Assoc,"assoc",SysNode);
  68.    }
  69.  
  70. /******************************* end of F_ss.c *******************************/
  71.  
  72.