Skip to content

Instantly share code, notes, and snippets.

@mrsolarius
Created March 9, 2022 09:21
Show Gist options
  • Save mrsolarius/1fbad495779f5c6fc1c68d65575c5f9e to your computer and use it in GitHub Desktop.
Save mrsolarius/1fbad495779f5c6fc1c68d65575c5f9e to your computer and use it in GitHub Desktop.
Comment verifier que un ellement apartien à une liste en erlang ?
% Spéc et implementation d'une fonction d'appartenance d'un élément à une liste
% app(E,L) renvoie vrai si E appartient à L
%
% app(X,L) vrai ssi X appartient à L
%
% Exemple :
% app(1,[1,2,3,4]) = true
% app(5,[1,2,3,4]) = false
% Analyse sur L : 2 cas
% 1) L = []
app(_,[])->false;
% 2) L /= [] : L = [Pr|Fin]
% a) X = Pr : vrai
app(X,[X|_])->true;
% b) X /Pr
app(X,[Pr|Fin]) when X=/=Pr -> app(X,Fin).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment