Browse thread
empty list
- marche@l...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | marche@l... |
| Subject: | empty list |
Hello caml-lighters,
For my own program, I have written a small "list" C module, since
this may be of a general interest, I send it to the list...
----------------- camllist.h ----------------
/***************************************************************************
Le type list de CAML : interface
Projet: NORMCOMP
Auteur(s): Claude March\'e
Nom du fichier: camllist.h
Creation: 27 jan 93
Derniere Modification: 02 fev 93
***************************************************************************/
#if !defined(CAMLLIST_H)
#include <mlvalues.h>
typedef value liste;
/*=============
Constructeurs
=============*/
liste liste_vide(void);
liste construit_liste(value x,liste l);
/*===============
Observateurs
===============*/
#define EST_VIDE(l) (!Tag_val(l))
#define N_EST_PAS_VIDE(l) (Tag_val(l))
#define TETE_DE_LISTE(l) (Field(l,0))
#define QUEUE_DE_LISTE(l) (Field(l,1))
/*========================
Fonctions sur les listes
========================*/
liste concatene_listes(liste l1,liste l2);
#define CAMLLIST_H
#endif
----------------- camllist.c ----------------
/***************************************************************************
Le type list de CAML : corps
Projet: NORMCOMP
Auteur(s): Claude Marche'
Nom du fichier: camllist.c
Creation: 27 jan 93
Derniere Modification: 05 fev 93
***************************************************************************/
#include "camllist.h"
#include <alloc.h>
#include <memory.h>
/*=============
Constructeurs
=============*/
#define NIL_tag 0
#define CONS_tag 1
liste liste_vide(void)
{
return Atom(NIL_tag);
}
liste construit_liste(value x,liste l)
{
value m;
Push_roots(r,2);
r[0] = x;
r[1] = l;
m=alloc(2,CONS_tag);
Field(m,0) = r[0];
Field(m,1) = r[1];
Pop_roots();
return m;
}
/*============
Observateurs
============*/
/*========================
Fonctions sur les listes
========================*/
liste concatene_listes(liste l1,liste l2)
{
liste result;
Push_roots(r,3);
r[0] = l1;
r[1] = l2;
if (N_EST_PAS_VIDE(r[0]))
{
r[2] = concatene_listes(QUEUE_DE_LISTE(r[0]),r[1]);
result = construit_liste(TETE_DE_LISTE(r[0]),r[2]);
}
else
{
result = r[1];
}
Pop_roots();
return result;
}