Les listes comme en Lisp

Ce programme présente la manipulation des listes comme en Lisp.

Le fichier source est ${UPS_HOME}/upssdk/demo/${UPS_LANGUAGE}/lisp.upl.

Mode compilé

Commande de compilation

upscmp Source=lisp.upl

Commande d'exécution

lisp

Mode interprété

upssng Source=lisp.upl

Fichier source

Source Composant "Exemple de listes employées comme en Lisp" Version 4.0.0;

Procedure P1(O : Nul Ou Caractere)
/********************************/
Debut
Ecran.Ecrire(O);
Fin Procedure

Procedure P2(O1 : Nul Ou Caractere, O2 : Nul Ou Entier)
/*****************************************************/
Debut
Ecran.Ecrire(O1+" "+Caractere(O2));
Fin Procedure

Fonction F1(O : Nul Ou Caractere) Retourner Nul Ou Caractere
/**********************************************************/
Debut
Retourner O.Majuscule();
Fin Fonction

Fonction F2(O1 : Nul Ou Caractere, O2 : Nul Ou Entier) Retourner Nul Ou Caractere
/*******************************************************************************/
Debut
Retourner O1.Majuscule()+" "+Caractere(O2);
Fin Fonction

Fonction F3(O1 : Nul Ou Caractere) Retourner Nul Ou Booleen
/*********************************************************/
Debut
Retourner O1<="hello!!!";
Fin Fonction

Fonction F4(O1 : Nul Ou Caractere, O2 : Nul Ou Caractere) Retourner ComparaisonObjet
/**********************************************************************************/
Debut Si O1==Nul Ou O2==Nul Alors Fin Si
Si O1<O2 Alors Fin Si
Si O1>O2 Alors Fin Si
Retourner ComparaisonEgal;
Fin Fonction

Procedure EcrireListe(L : Nul Ou ListeDe Nul Ou Caractere)
/********************************************************/
Variable
/******/ Debut
Pour C=L.ParcoursAuDebut() JusquA L.DernierElement() Pas L.Suivant() Faire Fin Pour
Fin Procedure

Principal Optimiser(NePasFactoriserChaine)
/****************************************/
Variable
/******/
Debut
L1=ListeDe("bonjour");
L1+="hello";
L1+="guten tag";
L2=ListeDe(1);
L2+=2;
L2+=3;

Ecran.Ecrire("P1:");
L1.Appliquer(P1);
Ecran.Ecrire("P2:");
L1.Appliquer(P2, L2);

Ecran.Ecrire("F1:");
L3=L1.Appliquer(F1);
EcrireListe(L3);
Ecran.Ecrire("F2:");
L3=L1.Appliquer(F2, L2);
EcrireListe(L3);

Ecran.Ecrire("F3:");
L3=L1.Filtrer(F3);
EcrireListe(L3);

Ecran.Ecrire("F4:");
L1+="hello";
L1+="bonjour";
L3=L1.Grouper(F4);
EcrireListe(L3);

Ecran.Ecrire("F4Bis:");
L1+="coucou";
L1+="salut";
L1+="hie";
L1+="schluss";
L3=L1.Trier(F4);
EcrireListe(L3);
L3=L1.Trier(F4, Faux);
EcrireListe(L3);
Fin Principal

Résultat de l'exécution

P1: bonjour hello guten tag P2: bonjour 1 hello 2 guten tag 3 F1: BONJOUR HELLO GUTEN TAG F2: BONJOUR 1 HELLO 2 GUTEN TAG 3 F3: bonjour hello guten tag F4: bonjour guten tag hello F4Bis: bonjour bonjour coucou guten tag hello hello hie salut schluss schluss salut hie hello hello guten tag coucou bonjour bonjour