/* cduce --compile tiki_of_html.cd cduce --run tiki_of_html.cdo --arg http://digicosme.lri.fr/innovation.html */ let tiki_of_html (h : [ Any* ]) : [Byte*] = /* Applique le pattern a chaque element de la liste. l'expression de droite doit etre une liste, et le tout est reconcaténé: Équivalent de List.concat (List.map f l) où f est la transformation faite par le pattern */ transform h with /* on ignore le header */ _ -> [] /* Le gras */ | (l&[Any*]) -> "__" @ tiki_of_html l @ "__" /* Les liens */ | (l&[Any*]) -> "[" @ url @ "|" @ tiki_of_html l @ "]" /* Les listes non */ | <((`ul|`ol)&tag) ..>(l&[Any*]) -> let sym = if tag = `ol then "# " else "* " in let res = transform "\n" @ l with
  • (l&[Any*]) -> sym @ tiki_of_html l @"\n" | x -> tiki_of_html [ x ] in res /* Un tag qu'on ne connait pas, on se rapplique récursivement */ | <_ ..>(l&[Any*]) -> " "@tiki_of_html l@" " /* Un charactère, on le copie dans la sortie */ | Byte & c -> [ c ] /* Autre chose ? on l'ignore */ | _ -> [] ;; let [] = match argv [] with [ (url & Latin1) ] -> print (tiki_of_html (load_html url)) | _ -> print "Nombre d'arguments invalides\n"; exit 1