{"id":85,"date":"2006-02-01T22:43:15","date_gmt":"2006-02-01T22:43:15","guid":{"rendered":""},"modified":"2010-03-13T14:24:32","modified_gmt":"2010-03-13T13:24:32","slug":"ein-rekursives-vergnugen","status":"publish","type":"post","link":"https:\/\/mentalschnupfen.org\/?p=85","title":{"rendered":"Ein rekursives Vergn\u00fcgen"},"content":{"rendered":"<p>Wer kennt die Programmiersprache <a href=\"http:\/\/en.wikipedia.org\/wiki\/Lisp_programming_language\">LISP<\/a> noch? Den Listenprozessor? Nach FORTRAN ist LISP die zweit\u00e4lteste Hochprogrammiersprache. Entwickelt wurde sie Ende der f\u00fcnfziger Jahre am MIT von John McCarthy. Rekursion ist in LISP, \u00e4hnlich wie in Prolog, eine noch weitaus bedeutendere Technik als in anderen Sprachen. Die typischen Schleifenkonstrukte vom \"for\" oder \"while\"-Typus sind in LISP in aller Regel schlechter Stil, obwohl dergleichen inzwischen auch in die Sprache eingebaut wurde. 'Die Sprache' ist n\u00e4mlich ohnehin ein problematischer Ausdruck, denn LISP wurde erst 1994 standardisiert (ANSI Common Lisp); bis dahin waren bereits unz\u00e4hlige Dialekte der Sprache entstanden. Babylonisches Lispeln.<br \/>\nDer wichtigste Datentyp in LISP ist die Liste. Und nicht nur komplexe Datenstrukturen, auch Funktionen sind Listen. Deswegen k\u00f6nnen LISP-Programme besonders gut andere LISP-Programme maltr\u00e4tieren, ver\u00e4ndern und zur Not auch schonmal schreiben... Darum war - und ist - die Sprache f\u00fcr KI-Zwecke und dynamische Prozesse besonders beliebt und geeignet.<\/p>\n<p>Ich habe heute angefangen, mich ein wenig mit dem guten St\u00fcck zu besch\u00e4ftigen und habe erst einmal vier Funktionen geschrieben: JOINL nimmt zwei Listen als Argument und f\u00fcgt sie zusammen (concatenation); REVERSEL nimmt eine Liste als Argument und kehrt die Reihenfolge der Elemente um; SORTEDL nimmt eine List (am besten von Zahlen) als Argument und \u00fcberpr\u00fcft, ob sie aufsteigend geordnet ist; SORTL nimmt eine Liste (am besten von Zahlen) als Argument und ordnet sie aufsteigend. Voil\u00e1:<br \/>\n<!--more--><br \/>\n(DEFUN JOINL<\/p>\n<p>\t(La Lb)<\/p>\n<p>\t(COND<\/p>\n<p>\t<sup id=\"rf1-85\"><a href=\"#fn1-85\" title=\"NULL La) &lt;br \/&gt;\n\t\t\tLb)&lt;br \/&gt;\n\t\t((NULL (CDR La\" rel=\"footnote\">1<\/a><\/sup><br \/>\n\t\t\t(CONS (CAR La) Lb))<br \/>\n\t\t(T <br \/>\n\t\t\t(CONS (CAR La) (JOINL (CDR La) Lb)))\t<\/p>\n<p>\t)<br \/>\n)<\/p>\n<p>\n(DEFUN REVERSEL<\/p>\n<p>\t(L)<\/p>\n<p>\t(COND<\/p>\n<p>\t<sup id=\"rf2-85\"><a href=\"#fn2-85\" title=\"NULL (CDR L\" rel=\"footnote\">2<\/a><\/sup><br \/>\n\t\t\tL)<br \/>\n\t\t(T<br \/>\n\t\t\t(JOINL <br \/>\n\t\t\t\t(REVERSE (CDR L)) (CONS (CAR L) NIL)<br \/>\n\t\t\t)<br \/>\n\t\t)<\/p>\n<p>\t)<br \/>\n)<\/p>\n<p>\n(DEFUN SORTEDL<\/p>\n<p>\t(L)<\/p>\n<p>\t(COND<br \/>\n\t<sup id=\"rf3-85\"><a href=\"#fn3-85\" title=\"NULL (CDR L\" rel=\"footnote\">3<\/a><\/sup><br \/>\n\t\t\tT)<\/p>\n<p>\t\t(T <br \/>\n\t\t\t(IF (SORTEDL (CDR L))<br \/>\n\t\t\t\t(<= (CAR L) (CAR (CDR L)))<br \/>\n\t\t\t\tNIL<br \/>\n\t   \t\t)<br \/>\n\t\t)<br \/>\n\t)<\/p>\n<p>)<\/p>\n<p>\n(DEFUN SORTL<\/p>\n<p>\t(L)<\/p>\n<p>\t(COND <br \/>\n\t<sup id=\"rf4-85\"><a href=\"#fn4-85\" title=\"SORTEDL L) &lt;br \/&gt;\n\t\t\tL)&lt;\/p&gt;\n&lt;p&gt;\t\t((SORTEDL (CDR L\" rel=\"footnote\">4<\/a><\/sup><\/p>\n<p>\t\t\t(SORTL <\/p>\n<p>\t\t\t(JOINL (LIST (CAR (CDR L)) (CAR L)) (CDR (CDR L)))\t<\/p>\n<p>\t\t\t)<br \/>\n\t\t)<\/p>\n<p>\t\t(T (SORTL (CONS (CAR L) (SORTL (CDR L)))))<br \/>\n\t)<\/p>\n<p>)<\/p>\n<p>(DEFUN SORTL2<\/p>\n<p>\t(L)<\/p>\n<p>\t(COND <br \/>\n\t<sup id=\"rf5-85\"><a href=\"#fn5-85\" title=\"SORTEDL L) &lt;br \/&gt;\n\t\t\tL)&lt;\/p&gt;\n&lt;p&gt;\n\t\t((&gt; (CAR L) (CAR (CDR L\" rel=\"footnote\">5<\/a><\/sup>)<\/p>\n<p>\t\t\t(SORTL2 (CONS (CAR (CDR L)) (CONS (CAR L) (CDR (CDR L))))))<\/p>\n<p>\n\t\t(T (SORTL2 (CONS (CAR L) (SORTL2 (CDR L)))))<br \/>\n\t)<br \/>\n)<\/p>\n<hr class=\"footnotes\"><ol class=\"footnotes\" style=\"list-style-type:decimal\"><li id=\"fn1-85\"><p >NULL La) <br \/>\n\t\t\tLb)<br \/>\n\t\t((NULL (CDR La&nbsp;<a href=\"#rf1-85\" class=\"backlink\" title=\"Return to footnote 1.\">&#8617;<\/a><\/p><\/li><li id=\"fn2-85\"><p >NULL (CDR L&nbsp;<a href=\"#rf2-85\" class=\"backlink\" title=\"Return to footnote 2.\">&#8617;<\/a><\/p><\/li><li id=\"fn3-85\"><p >NULL (CDR L&nbsp;<a href=\"#rf3-85\" class=\"backlink\" title=\"Return to footnote 3.\">&#8617;<\/a><\/p><\/li><li id=\"fn4-85\"><p >SORTEDL L) <br \/>\n\t\t\tL)<\/p>\n<p>\t\t((SORTEDL (CDR L&nbsp;<a href=\"#rf4-85\" class=\"backlink\" title=\"Return to footnote 4.\">&#8617;<\/a><\/p><\/li><li id=\"fn5-85\"><p >SORTEDL L) <br \/>\n\t\t\tL)<\/p>\n<p>\n\t\t((&gt; (CAR L) (CAR (CDR L&nbsp;<a href=\"#rf5-85\" class=\"backlink\" title=\"Return to footnote 5.\">&#8617;<\/a><\/p><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Wer kennt die Programmiersprache LISP noch? Den Listenprozessor? Nach FORTRAN ist LISP die zweit\u00e4lteste Hochprogrammiersprache. Entwickelt wurde sie Ende der f\u00fcnfziger Jahre am MIT von John McCarthy. Rekursion ist in LISP, \u00e4hnlich wie in Prolog, eine noch weitaus bedeutendere Technik als in anderen Sprachen. Die typischen Schleifenkonstrukte vom \"for\" oder \"while\"-Typus sind in LISP in&#8230; <a href=\"https:\/\/mentalschnupfen.org\/?p=85\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Ein rekursives Vergn\u00fcgen<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=\/wp\/v2\/posts\/85"}],"collection":[{"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=85"}],"version-history":[{"count":0,"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=\/wp\/v2\/posts\/85\/revisions"}],"wp:attachment":[{"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mentalschnupfen.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}