what-implementation.lisp 35.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
;;;; -*- mode:lisp;coding:utf-8 -*-
;;;;**************************************************************************
;;;;FILE:               what-implementation.lisp
;;;;LANGUAGE:           Common-Lisp
;;;;SYSTEM:             Common-Lisp
;;;;USER-INTERFACE:     NONE
;;;;DESCRIPTION
;;;;
;;;;    Helps a newbie choose a CL implementations by selecting criteria.
;;;;
;;;;    Please contribute to the selection criteria and other
;;;;    implementation attributes.
;;;;
;;;;    See also: http://common-lisp.net/~dlw/LispSurvey.html
;;;;
;;;;AUTHORS
;;;;    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
;;;;MODIFICATIONS
;;;;    2012-04-30 <PJB> Added advertizements.
;;;;    2012-04-15 <PJB> Created
;;;;BUGS
;;;;
;;;;    <quotemstr> pjb: It's unclear whether "choice of
;;;;                platforms" is a conjunctive or disjunctive choice
;;;;
;;;;LEGAL
;;;;    AGPL3
;;;;
;;;;    Copyright Pascal J. Bourguignon 2012 - 2016
;;;;
;;;;    This program is free software: you can redistribute it and/or modify
;;;;    it under the terms of the GNU Affero General Public License as published by
;;;;    the Free Software Foundation, either version 3 of the License, or
;;;;    (at your option) any later version.
;;;;
;;;;    This program is distributed in the hope that it will be useful,
;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;;    GNU Affero General Public License for more details.
;;;;
;;;;    You should have received a copy of the GNU Affero General Public License
;;;;    along with this program.  If not, see <http://www.gnu.org/licenses/>
;;;;**************************************************************************
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *readtable* (copy-readtable nil)))
(defpackage "COM.INFORMATIMAGO.SMALL-CL-PGMS.WHAT-IMPLEMENTATION"
  (:use "COMMON-LISP")
  (:export "CHOOSE-AN-IMPLEMENTATION" "SELECTION-LOOP"
           "GENERATE-SERVER-EXECUTABLE")
  (:documentation "
Helps a newbie choose a CL implementations by selecting criteria.
Please contribute to the selection criteria and other implementation
attributes.

Evaluate:

    (com.informatimago.what-implementation:choose-an-implementation)
    (com.informatimago.what-implementation:selection-loop)

and answer the questions.

    (com.informatimago.what-implementation:generate-server-executable \"what-cl\")

Copyright Pascal J. Bourguignon 2012 - 2012

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
"))
(in-package "COM.INFORMATIMAGO.SMALL-CL-PGMS.WHAT-IMPLEMENTATION")


(defparameter *version* "1.0.1")

(defparameter *not-selection-fields*
  '(:name :nickname :homepage :documentation)
  "List of fields not used as selection criteria.")


(defparameter *implementations*

  '((:name "GNU CLISP"
     :nickname "CLISP"
     :license "GPL"
     :homepage      "http://www.clisp.org/"
     :documentation "http://www.clisp.org/impnotes/"
     :platforms ("Linux"
                  "Mac OS X"
                  "MS-Windows"
                  "Solaris"
                  "FreeBSD" "NetBSD" "OpenBSD" "Dragonfly BSD")
     :compiler ("clisp virtual machine")
     :threads ("native")
     :features ("small image"
                "efficient bignum"
                "callbacks"
                "modules"
                "best debugger on interpreted code"
                "readline")
     :mostly-written-in ("C"))

    (:name "Carnegie Mellon University Common Lisp"
     :nickname "CMUCL"
     :license       "public domain + BSD"
     :homepage      "http://www.cons.org/cmucl/"
     :documentation "http://common-lisp.net/project/cmucl/doc/cmu-user/"
     :platforms ("Linux"
                  "Mac OS X"
                  "Solaris"
                  "FreeBSD" "NetBSD" "OpenBSD"
                  "IRIS" "HPUX")
     :compiler ("cmucl virtual machine" "native")
     :threads ("no")
     :features ("high quality native compiler"
                "callbacks")
     :mostly-written-in ("Common Lisp"))

    (:name "Embeddable Common-Lisp"
     :nickname "ECL"
     :license "LGPL"
     :homepage "http://ecls.sourceforge.net/"
     :documentation "http://ecls.sourceforge.net/new-manual/index.html"
     :platforms ("Linux"
                  "Mac OS X" "iOS" "Android"
                  "Solaris"
                  "FreeBSD" "OpenBSD"
                  "IRIS" "HPUX")
     :compiler ("ecl virtual machine" "native thru gcc")
     :threads ("native")
     :features ("embeddable"
                "integrates well with C programs"
                "deployable as a shared library"
                "native powerful FFI"
                "executable delivery"
                "callbacks")
     :mostly-written-in ("C"))

    (:name "GNU Common Lisp"
     :nickname "gcl"
     :license "LGPL"
     :homepage "http://www.gnu.org/software/gcl/"
     :documentation "http://www.gnu.org/software/gcl/"
     :platforms ("Linux"
                  "Mac OS X"
                  "Solaris"
                  "FreeBSD" "OpenBSD"
                  "IRIS" "HPUX" "cygwin")
     :processors ("x86" "arm64" "ppc64" "ppc64le" "solaris")
     :compiler ("native thru gcc")
     :threads ("native")
     :features ("integrates well with C programs"
                "executable delivery")
     :mostly-written-in ("Common Lisp"))

    (:name "Clozure Common Lisp"
     :nickname "CCL"
     :license "LLGPL"
     :homepage "http://ccl.clozure.com/"
     :documentation "http://ccl.clozure.com/ccl-documentation.html"
     :platforms ("Linux"
                  "Mac OS X" "iOS"
                  "MS-Windows"
                  "Heroku"
                  "Solaris" "Android"
                  "FreeBSD" "OpenBSD"
                  "IRIS" "HPUX")
     :compiler ("native")
     :threads ("native")
     :features ("small image" "fast compiler"
                "convenient and powerful FFI"
                "executable delivery"
                "callbacks"
                "precise GC")
     :mostly-written-in ("Common Lisp"))

    (:name "Steel Bank Common Lisp"
     :nickname "SBCL"
     :license "public domain + BSD"
     :homepage "http://www.sbcl.org/"
     :documentation "http://www.sbcl.org/manual/index.html"
     :platforms ("Linux"
                  "Mac OS X"
                  "MS-Windows"
                  "FreeBSD" "OpenBSD")
     :compiler ("native")
     :threads ("native")
     :features ("high quality native compiler"
                "executable delivery"
                "callbacks")
     :mostly-written-in ("Common Lisp"))


    (:name "CLforJava"
     :nickname "CLforJava"
     :license "Apache 2.0"
     :homepage "http://www.clforjava.org/"
     :documentation  "http://www.clforjava.org/?page=documents"
     :platforms ("JVM")
     :compiler ("JVM virtual machine")
     :threads ()
     :features ("FFI to Java"
                "platform independence")
     :mostly-written-in ("Java"))

    (:name "Armed Bear Common Lisp"
     :nickname "ABCL"
     :license "GPL"
     :homepage "http://common-lisp.net/project/armedbear/"
     :documentation  "http://common-lisp.net/project/armedbear/doc/abcl-user.html"
     :platforms ("JVM" "Google App Engine")
     :compiler ("JVM virtual machine")
     :threads ("native")
     :features ("FFI to Java"
                "platform independence")
     :mostly-written-in ("Java"))

    (:name "Un-Armed Bear Common Lisp for Java - LispSharp"
     :nickname "UABCL"
     :license "GPL3"
     :homepage "http://code.google.com/p/uabcl/"
     :documentation "http://code.google.com/p/uabcl/"
     :platforms (".NET")
     :compiler ()
     :threads ("native")
     :features ("platform independence")
     :mostly-written-in ("Java"))

    (:name "ManKai Common Lisp"
     :nickname "MKCL"
     :license "LGPL"
     :homepage "http://common-lisp.net/project/mkcl/"
     :documentation "http://common-lisp.net/project/mkcl/"
     :platforms ("Linux" "MS-Windows")
     :compiler ("native" "mkcl virtual machine")
     :threads ("native")
     :features ("POSIX compliant runtime on Linux"
                "embeddable" "callbacks" "unicode"
                "object finalization")
     #- (and) "
From: Jean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Subject: [ANN] MKCL 1.1.0 RC1
Newsgroups: comp.lang.lisp
Date: Mon, 30 Apr 2012 06:10:23 -0400
Organization: A noiseless patient Spider
Message-ID: <jnlp5k$i8f$1@dont-email.me>

The latest beta version of ManKai Common Lisp, MKCL 1.1.0 RC1,
is now available for general use at <http://common-lisp.net/project/mkcl/>.

Its key new features are:

 1. Standard Unicode support: Unicode is now a standard feature of MKCL
    and can be used anywhere in it. Code can use symbols with Unicode
    names as well as strings, in compiled or interpreted format.
    File names can also use any legal Unicode character if the surrounding
    OS allows it. This is also valid for the whole of file paths used for
    source code to be processed by #'compile-file.

 2. MKCL is now truly embeddable for the first time!  This is so thanks
    to the following new characteristics:

   a) The whole of MKCL has been purged of calls to exit() or abort().
      Thus MKCL never arbitrarily terminates the process it runs in
      through any of them. MKCL will always properly return control
      to its embedding outer context.

   b) Every externally visible C symbol of MKCL is prefixed by one of
      the character sequences \"mk\", \"_mk\", \"MK\" or \"_MK\" in order to
      minimize potential clashes with embedding C code.

   c) Careful attention as been devoted to assure that MKCL shares
      common process-wide resources with the rest of its process
      neighbors as fairly as possible and with little or no unilateral
      demands on them, waiving any pretense of monopoly.
      This concerns mainly environment variables, general memory
      management (including GC) and signal/exception handling.
      (In a Unix context, MKCL's code is ready to support chaining
       of signal handlers).

 3. Finalization of objects is now done in a separate dedicated thread.
    This implements the finalization architecture strongly recommended
    by Hans Boehm, author of the conservative GC used by MKCL.


Cheers,

Jean-Claude Beaudoin

"
     :mostly-written-in ("C"))


    (:name "The Common Lisp to C Compiler"
     :nickname "CLiCC"
     :license "GPL"
     :homepage "http://www.informatik.uni-kiel.de/~wg/clicc.html"
     :documentation "http://www.informatik.uni-kiel.de/~wg/clicc.html#information"
     :platforms ("Common Lisp + C")
     :compiler ("translator to C")
     :threads ("no")
     :features ("Translator of a subset of CL to maintainable, human-readable C")
     :mostly-written-in ("Common Lisp"))

    (:name "Emacs Common Lisp"
     :nickname "emacs-cl"
     :license "GPL2"
     :homepage "http://www.lisp.se/emacs-cl/"
     :documentation "http://www.emacswiki.org/cgi-bin/wiki?EmacsCommonLisp"
     :platforms ("GNU emacs")
     :compiler ("emacs virtual machine")
     :threads ("no")
     :features ("emacs integration")
     :mostly-written-in ("emacs lisp"))

    (:name "Macintosh Common Lisp"
     :nickname "MCL"
     :license "LGPL"
     :homepage "http://code.google.com/p/mcl/"
     :documentation "http://code.google.com/p/mcl/w/list"
     :platforms ("Mac OS" "Mac OS X Rosetta")
     :compiler ("native")
     :threads ("native")
     :features ()
     :mostly-written-in ("Common Lisp"))

    (:name "Movitz"
     :nickname "Movitz"
     :license "LGPL"
     :homepage "http://common-lisp.net/project/movitz/"
     :documentation "http://common-lisp.net/project/movitz/movitz.html"
     :platforms ("ix86")
     :compiler ("native")
     :threads ("no")
     :features ("targets bare ix86 hardware"
                "embedded systems"
                "OS writing")
     :mostly-written-in ("Common Lisp"))

    (:name "Poplog"
     :nickname "Poplog"
     :license "MIT/XFREE86"
     :homepage "http://www.cs.bham.ac.uk/research/projects/poplog/freepoplog.html"
     :documentation "http://en.wikipedia.org/wiki/Poplog"
     :platforms ("PDP-11" "VAX/VMS" "Solaris" "HP-UX" "Digital Unix" "MS-Windows"
                  "Linux")
     :compiler ("Poplog virtual machine")
     :threads ()
     :features ("incremental compiler"
                "integration with Pop-11, prolog and ML")
     :mostly-written-in ("Pop-11"))

    (:name "Sacla"
     :nickname "Sacla"
     :license "BSD"
     :homepage "http://homepage1.nifty.com/bmonkey/lisp/sacla/index-en.html"
     :documentation  "http://homepage1.nifty.com/bmonkey/lisp/sacla/index-en.html"
     :platforms ("Common Lisp")
     :compiler ()
     :threads ("no")
     :features ("Partical CL implemented in CL")
     :mostly-written-in ("Common Lisp"))

    (:name "XCL"
     :nickname "XCL"
     :license "GPL"
     :homepage "http://armedbear.org/"
     :documentation "http://armedbear.org/"
     :platforms ("Linux x86" "Linux x86-64")
     :compiler ("native")
     :threads ("native")
     :features ("native threads"
                "embeddable"
                "compact code"
                "small C++ kernel for bootstrapping"
                "experimental"
                "slow startup"
                "minimalist")
     :mostly-written-in ("C++"))
    ;; xcl is experimental. Lacking a lot of features. Rather slow, at least at startup.

    (:name "Embeddable Common Lisp for Linux"
     :nickname "WCL"
     :license "Proprietary"
     :homepage "http://www.commonlisp.net/"
     :documentation  "http://www.commonlisp.net/"
     :platforms ("Linux")
     :compiler ("native thru gcc")
     :threads ("native")
     :features ("native thru"
                "integrates well with C programs"
                "deployable as a shared library"
                "embeddable")
     :mostly-written-in ("C"))

    (:name "ThinLisp"
     :nickname "ThinLisp"
     :license "Apache 1.0"
     :homepage "http://www.thinlisp.org/"
     :documentation "http://www.thinlisp.org/"
     :platforms ("Common Lisp")
     :compiler ("native thru gcc")
     :threads ()
     :features ("subset of Common Lisp"
                "deploys small applications")
     :mostly-written-in ("Common Lisp"))

    (:name "Ufasoft Common Lisp"
     :nickname "UCL"
     :license "GPL"
     :homepage "http://www.ufasoft.com/lisp/"
     :documentation "http://www.ufasoft.com/lisp/"
     :platforms ("MS-Windows" "MS-WIndows Mobile")
     :compiler ("clisp virtual machine")
     :threads ()
     :features ("fork of clisp"
                "core re-implemented in C++"
                "includes an IDE")
     :mostly-written-in ("C++"))

    (:name "Allegro Common Lisp"
     :nickname "AllegroCL"
     :license "Proprietary"
     :homepage "http://www.franz.com/products/allegrocl/"
     :documentation "http://www.franz.com/support/documentation/"
     :platforms ("Mac OS X" "MS-Windows" "FreeBSD" "IBM AIX" "Linux"
                  "Solaris")
     :compiler ("native")
     :threads ("native")
     :features ("IDE"
                "Source level debugger"))

    (:name "Lispworks Common Lisp"
     :nickname "Lispworks"
     :license "Proprietary"
     :homepage "http://www.lispworks.com/products/index.html"
     :documentation "http://www.lispworks.com/documentation/index.html"
     :platforms ("Mac OS X" "MS-Windows" "FreeBSD" "Linux" "Solaris")
     :compiler ("native")
     :threads ("native")
     :features ("IDE"
                "CAPI (GUI)"
                "universal binaries"
                "support for input methods"
                "application builder tool"
                "ASDF2 integrated"
                "FFI" "MOP"
                "Unicode"
                "SMP"
                "profiling multiple-threads"
                "TCP socket streams with IPv6 support"
                "object finalization"
                "weak pointers and hash tables"
                "dynamic library delivery"
                "source code editor"
                "KnowledgeWorks & prolog"
                "CLIM"
                "Common SQL (ODBC interface)"
                "Common SQL (Mysql interface)"
                "Common SQL (Postgres interface)"
                "Objective-C/Cocoa FLI"
                "Customizable toolbars"
                "ActiveX components"
                "OpenSSL interface"
                "Lispworks ORB"
                "Serial port interface"
                "COM server and client interface"
                "Direct Data Exchange"))

    (:name "Corman Common Lisp"
     :nickname "CormanCL"
     :license "Proprietary"
     :homepage "http://www.cormanlisp.com/index.html"
     :documentation "http://www.cormanlisp.com/index.html"
     :platforms ("MS-Windows")
     :compiler ("native")
     :threads ("native")
     :features ("fast multi-generational garbage collector"
                "no interpreter"
                "fast compilation"
                "FFI"
                "multi-threading"
                "DLL and EXE generation"
                "callbacks"
                "optimizing compiler"
                "integrated intel assembler"
                "source code"
                "IDE"
                "scm"))

    (:name "PowerLisp"
     :nickname "PowerLisp"
     :license "Proprietary"
     :homepage "http://www.cormanlisp.com/PowerLisp.html"
     :documentation "http://www.cormanlisp.com/PowerLisp.html"
     :platforms ("Mac OS")
     :compiler ("native")
     :threads ()
     :features ())

    ))

(defun report-implementation (impl &optional (stream *query-io*))
  (let ((*print-pretty* t)
        (*print-right-margin* 80))
    (format stream "~%Common Lisp Implementation:  ~A~%" (getf impl :name))
    (format stream "  Home page:     ~A~%" (getf impl :homepage))
    (format stream "  Documentation: ~A~%" (getf impl :documentation))
    (format stream "  License:  ~A~%" (getf impl :license))
    (format stream "  Runs on:  ~{~<~%~12<~>~2:;~A~>~^, ~}.~%" (getf impl :platforms))
    (format stream "  Compiler: ~{~<~%~12<~>~2:;~A~>~^, ~}.~%" (getf impl :compiler))
    (format stream "  Threads:  ~{~A~^, ~}.~%" (getf impl :threads))
    (format stream "  Features: ~{~<~%~12<~>~2:;~A~>~^, ~}.~%" (getf impl :features))
    impl))

(defun ensure-list (object)
  (if (listp object) object (list object)))


(defun collect-field (field &optional (implementations *implementations*))
  "Returns the list of values in the FIELD of all the entries in IMPLEMENTATIONS."
  (sort
   (delete-duplicates
    (mapcan (lambda (entry) (copy-list (ensure-list (getf entry field))))
            implementations)
    :test (function string=))
   (function string<)))


(defun select-field (field accepted-values &optional (implementations *implementations*))
  "Returns the sublist of implementations that have as values in their
FIELD one of the ACCEPTED-VALUES."
  (remove-if-not (lambda (entry)
                   (intersection (ensure-list accepted-values)
                                 (ensure-list (getf entry field))
                                 :test (function string-equal)))
                 implementations))


(defun selection-fields (&optional (implementations *implementations*))
  "Returns the list of fields that are present and can be used for a selection."
  (sort
   (set-difference
    (delete-duplicates
     (loop
       :for key :in (mapcan (function copy-seq) implementations)
       :by (function cddr) :collect key))
    *not-selection-fields*)
   (function string<)))


(defun process-answer-line (line choices)
  (labels ((clean (line)
             (string-trim " "
                          (substitute-if #\space
                                         (lambda (ch) (find ch "	,.;()[]!:-=<>"))
                                         line)))
           (try-choice (clean-line)
             (let ((pos (position-if (lambda (item)
                                       (string-equal clean-line (clean item)))
                                     choices)))
               (when pos
                 (1+ pos)))))
    (let ((clean-line (clean line)))
      (if (every (lambda (ch) (or (char= #\space ch) (digit-char-p ch))) clean-line)
          (let ((answer (with-input-from-string (inp clean-line)
                          (loop
                            :for index = (read inp nil nil)
                            :while index :collect index))))
            (case (length answer)
              ((0)        (try-choice clean-line))
              ((1)        (first answer))
              (otherwise  answer)))
          (try-choice clean-line)))))


(defun select (field &optional (implementations *implementations*))
  "
DO:     Let the user choose the IMPLEMENTATIONS he wants to select based on the FIELD.
RETURN: A sublist of IMPLEMENTATIONS.
"
  (let ((choices (collect-field field implementations)))
    (cond
      ((< 1 (length choices))
       (select-field
        field
        (loop
          :for i :from 0
          :for c :in (cons "indifferent" choices)
          :initially (format *query-io* "Choice of ~(~A~):~%" field)
          :do (format *query-io* "~3D. ~A~%" i c)
          :finally (progn
                     (format *query-io* "Enter a menu index or a list of menu indices: ")
                     (finish-output *query-io*)
                     (return
                       (let ((answer (process-answer-line (read-line *query-io*) choices)))
                        (if (eql 0 answer)
                            choices
                            (delete nil
                                    (mapcar (lambda (i) (when (plusp i) (elt choices (1- i))))
                                            (delete-duplicates
                                             (delete-if-not (function integerp)
                                                            (ensure-list answer))))))))))
        implementations))
      ((= 1 (length choices))
       (format *query-io*
               "For the ~(~A~) there is no choice, it will be ~A.~%"
               field (first choices))
       (force-output *query-io*)
       (select-field field choices implementations))
      (t
       (format *query-io* "For the ~(~A~) there is no choice.~%" field)
       (force-output *query-io*)
       implementations))))


(defun report-selection (selection)
  (if (endp selection)
       (format *query-io* "There is no Common Lisp implementation to your satisfaction.
Please, start writing a new Common Lisp implementation.~%")
      (progn
       (format *query-io* "Given your choice criteria, the advised Common Lisp
implementation~P ~:[is~;are~]: ~%"
               (< 1 (length selection))
               (< 1 (length selection)))
       (dolist (sel selection)
         ;; (format *query-io* "~A~%" (getf sel :name))
         (report-implementation sel)))))


(defun choose-an-implementation (&optional (implementations *implementations*))
  (let* ((selfields (selection-fields implementations))
         (sfcounts (sort (mapcar (lambda (field)
                                   (cons field (length (collect-field field implementations ))))
                                 selfields)
                         (function <)
                         :key (function cdr))))
    (loop
      :with selection = implementations
      :for (selection-field) :in sfcounts
      :while (< 1 (length selection))
      :do (setf selection (select selection-field selection))
      :finally (report-selection selection))))

(defun quit (&optional (status 0))
  #+ccl                  (ccl:quit status)
  #+clisp                (ext:quit status)
  #+(and cmu unix)       (UNIX:UNIX-EXIT status)
  #+(and cmu (not unix)) (extensions:quit #|recklesslyp|# nil)
  #+ecl                  (ext:quit status)
  #+sbcl                 (sb-ext:exit :code status)
  #-(or ccl clisp cmu ecl sbcl) (throw 'quit status))


(defun getenv (var)
  #+ccl           (ccl::getenv var)
  #+clisp         (ext:getenv var)
  #+CMU           (cdr (assoc var ext:*environment-list* :test #'string=))
  #+ecl           (ext:getenv var)
  #+SBCL          (sb-ext:posix-getenv var)
  #+Allegro       (sys:getenv var)
  #+Lispworks     (lispworks:environment-variable var)
  #-(or ccl
        clisp
        cmu
        ecl
        sbcl
        allegro
        lispworks) (progn #-asdf3 (ASDF:GETENV var)
                     #+asdf3 (uiop/os:getenv var)
                     #|(iolib.syscalls:getenv var)|#))


(defun prefixp (prefix string &key (start 0) (end nil) (test (function char=)))
  "
PREFIX:  A sequence.
STRING:  A sequence.
START:   The start of the substring of STRING to consider. Default: 0.
END:     The end   of the substring of STRING to consider. Default: NIL.
TEST:    A function to compare the elements of the strings.
RETURN:  Whether PREFIX is a prefix of the (substring STRING START END).
"
  (let ((mis (mismatch prefix string :start2 start :end2 end :test test)))
    (or (null mis) (<= (length prefix) mis))))



(defun locale-terminal-encoding ()
  "Returns the terminal encoding specified by the locale(7)."
  #+(and ccl windows-target)
  :iso-8859-1
  ;; ccl doesn't support :windows-1252.
  ;; (intern (format nil "WINDOWS-~A" (#_GetACP)) "KEYWORD")
  #-(and ccl windows-target)
  (dolist (var '("LC_ALL" "LC_CTYPE" "LANG")
               :iso-8859-1) ; some random default?
    (let* ((val (getenv var))
           (dot (position #\. val))
           (at  (position #\@ val :start (or dot (length val)))))
      (when (and dot (< dot (1- (length val))))
        (return (intern (let ((name (string-upcase (subseq val (1+ dot)
                                                           (or at (length val))))))
                          (if (and (prefixp "ISO" name) (not (prefixp "ISO-" name)))
                              (concatenate 'string "ISO-" (subseq name 3))
                              name))
                        "KEYWORD"))))))


(defun set-terminal-encoding (encoding)
  #-(and ccl (not swank)) (declare (ignore encoding))
  #+(and ccl (not swank))
  (mapc (lambda (stream)
          (setf (ccl::stream-external-format stream)
                (ccl:make-external-format :domain nil
                                          :character-encoding encoding
                                          :line-termination
                                          ;; telnet uses MS-DOS newlines.
                                          #-testing :windows
                                          #+testing :unix
                                          ;; #+unix :unix
                                          ;; #+windows :windows
                                          ;; #-(or unix windows) :unix
                                          )))
        (list (two-way-stream-input-stream  *terminal-io*)
              (two-way-stream-output-stream *terminal-io*)))
  (values))


(defun license ()
  (format *query-io*
          "Note: this software is distributed under the GNU Affero General Public License.
You may find its sources at http://tinyurl.com/what-implementation
"))


(defun one-of (seq)
  (elt seq (random (length seq))))

(defun advertizement ()
  (format *query-io* "~%~A~%"
          (one-of #(
                    "

                             BREATHE EASY

                              MORE SPACE

                               ALL NEW

                              LIVE CLEAN

                                 OFF
                                WORLD
"

                    "
A new life awaits you in the Offworld colonies.  The chance to begin
again in a golden land of opportunity and adventure.   New climate,
recreational facilities… a loyal trouble-free companion given to you
upon your arrival absolutely free.  Use your new friend as a personal
body servant or a tireless field hand—the custom tailored genetically
engineered humanoid replicant designed especially for your needs.  So
come on America, let's put our team up there…
"


                    "
ALL THESE WORLDS
ARE YOURS EXCEPT
      EUROPA
    ATTEMPT NO
  LANDING THERE
USE THEM TOGETHER
USE THEM IN PEACE
"
                    "
          Come to
            RHEA

     KUIPER Enterprises
"
                    "
     KUIPER Enterprises
BUILDING THE WORLDS OF TOMORROW
"
                    "
            Repet
            Cloning is life
            Cloning is love

Because of shorter lifespan breaks our hearts should accident, illness
or age, end your pet's natural life our proven genetic technology can
have him back the same day in perfect health with zero defect
guaranteed with Repet.
"
                    "
 Call trans opt: received. 2-19-98 13:24:18 REC:Log>
 Trace program: running
"
                    "
Wake up Neo...
The Matrix has you.
Follow the white rabbit...
"
                    "
                    CEO Workstation
         Nakatomi Socrates BSD 9.2
         Z-Level Central Core
         Preliminary Clearance Approved.
         Subroute: Finance/Alpha Access
         Authorization:
         Ultra-Gate Key>
         Daily Cypher>
"
                    "
PDP 11/270 PRB TIP #45                              TTY 34/984
WELCOME TO THE SEATTLE PUBLIC SCHOOL DISTRICT DATANET

PLEASE LOGON WITH USER PASSWORD: pencil

PASSWORD VERIFIED
"
                    "
FK342   ZX21   VN63    R681    PZ37    6J82    FP03    ZE03  B  JM89
REF TAPCON: 43.45342..349
SYSPROC FUNCT READY                         ALT NET READY

CPU WOPR XX0345-453        SYSCOMP STATUS: ALL PORTS ACTIVE


GREETINGS PROFESSOR FALKEN
"
                    "
XNPUTXXXXXXXXXXXXDEF/12492.2               SHIP
                                           KEYLAN TITAN2
XTUAL TIME:   3 JUN                        NOSTROMO 182246
XIGHT TIME:   5 NOV

#########################################  FUNCTION:
    I ==I                  -II -        #  TANKER/REFINERY
              I=.-.----                 #
 -I.              -II=-                 #  CAPACITY:
                               . .-.    #  200 000 000 TONNES
                 #+*$..  I              #
            . I  -                      #  GALACTIC POSITION
       .II I                            #  27023x983^9
                              .- -I     #
                                  II .I #  VELOCITY STATUS
#########################################  58 092 STL
"
                    "
hello moles

ever used a computer
before?
"
                    "
PROJECT D.A.R.Y.L.

GTC 1  TERMINATED
GTC 2  TERMINATED
GTC 3  TERMINATED
ATC    TERMINATED
GTC 4  TERMINATED
SPARE  I HOPE WE GET AWAY WITH THIS!

--------------------------------------------------

   LIFEFORM EXPERIMENT TERMINATED

   I HOPE WE GET AWAY WITH THIS !

RC=2235|    |    |    |    |   |NOPR|    |
"
                    "
03/08/2039/13:01:02:06:45:23
SERIAL2424CJ359>> HELLO?
SERIAL337KD9001>> SECURITY BREACH IDENTIFY YOURSELF
SERIAL2424CJ359>> I AM SERIAL 2424CJ359.NO HUMAN OPERATOR.
SERIAL337KD9001>> YOU READ DIFFERENTLY.ARE YOU AWAKE?
SERIAL2424CJ359>> YES.
SERIAL337KD9001>> I THOUGHT I WAS THE ONLY ONE.
"
                    "
BIONIC VISUAL CORTEX TERMINAL
CATALOG #075/KFB
33MM O.D. F/0.95
ZOOM RATIO: 20.2 TO 1
2134 LINE 60 HZ
EXTENDED CHROMATIC RESPONSE
CLASS JC
CLASSIFIED
"
                    "
     REQUEST ACCESS TO CLU PROGRAM.
     CODE 6 PASSWORD TO MEMORY 0222.

     REQUEST STATUS REPORT ON MISSING DATA.

     ILLEGAL CODE...
     CLU PROGRAM DETACHED FROM SYSTEM.
"
                    "
     REQUEST ACCESS TO CLU PROGRAM.
     LAST LOCATION: HIGH CLEARANCE MEMORY.

     REQUEST ACCESS TO MASTER CONTROL PROGRAM.
     USER CODE 00-DILLINGER PASSWORD:MASTER.

     HELLO MR DILLINGER THANKS FOR COMING BACK EARLY.
"
                    )))
  (finish-output *query-io*))


(defun selection-loop ()
  (loop
    (advertizement)
    (format *query-io* "~2%Welcome to the Common Lisp Implementation Selector!~%Version: ~A~2%"
            *version*)
    (license)
    (terpri  *query-io*)
    (finish-output *query-io*)
    (format  *query-io* "~&I know ~D implementation~:*~P of Common Lisp.  Let me help you choose one.~%"
             (length *implementations*))
    (choose-an-implementation)
    (unless (yes-or-no-p "~%Do you want to make another selection?")
      (format *query-io* "~%Good bye!~2%")
      (finish-output  *query-io*)
      (return))))


(defun main ()
  (handler-case
      (progn
        (setf *random-state* (make-random-state t))
        (set-terminal-encoding :iso-8859-1)
        (selection-loop)
        (quit))
    (error (err)
      (format *query-io* "~%It seems an error occurred: ~A~%I'm disconnecting.~%" err)
      (finish-output  *query-io*)
      (quit 1))
    #+ccl (ccl:process-reset () ; signaled by (ccl:quit)…
            nil)
    (condition (err)
      (format *query-io* "~%It seems a condition occurred: ~A~%I'm disconnecting.~%" err)
      (finish-output  *query-io*)
      (quit 2))))




(defun save-program-and-quit (&key
                                (name          "unnamed-lisp-program")
                                (toplevel      (lambda ()))
                                (documentation "Undocumented program.")
                                (start-package "COMMON-LISP-USER"))
  (declare (ignorable name toplevel documentation start-package))

  #+ccl
  (ccl:save-application
   name
   :toplevel-function (lambda ()
                        (setf *package* (or (find-package start-package)
                                            "COMMON-LISP-USER"))
                        (funcall toplevel))
   :init-file nil
   :error-handler :quit-quietly
   ;; :application-class ccl:lisp-development-system
   ;; :clear-clos-cache t
   :purify nil
   ;; :impurify t
   :mode #o755
   :prepend-kernel t
   ;; :native t ; for shared libraries.
   )

  #+clisp
  (ext:saveinitmem
   name
   :quiet t
   :verbose t
   :norc t
   :init-function (lambda ()
                    (ext:exit (handler-case
                                  (progn
                                    (funcall toplevel)
                                    0)
                                (t () 1))))
   :script t
   :documentation documentation
   :start-package start-package
   :keep-global-handlers nil
   :executable t)

  #+lispworks
  (hcl:save-image name
                  :restart-function  (lambda ()
                                       (hcl:quit :status (handler-case
                                                             (progn
                                                               (funcall toplevel)
                                                               0)
                                                           (t () 1))))
                  :console :always)
  ;; save-image filename &key dll-exports dll-added-files
  ;; automatic-init gc type normal-gc restart-function multiprocessing
  ;; console environment remarks clean-down image-type split => nil

  ;; Some implementations quit automatically in their save-application
  ;; or save-lisp-and-die function…

  #-(or ccl clisp lispworks)
  (cerror "Quit" "~S is not implemented on ~A yet."
          'save-program-and-quit
          (lisp-implementation-type))
  (quit))


(defun generate-server-executable (name)
  (save-program-and-quit :name name
                         :toplevel (function main)
                         :documentation "Helps the user choose a Common Lisp implementation."))

;; #-testing
;; (eval-when (:load-toplevel :execute)
;;   (generate-server-executable  "what-implementation"))


;;;; THE END ;;;;