Python syntax in Lisp and Scheme

Edi Weitz edi at
Thu Oct 16 23:08:43 CEST 2003

On Thu, 16 Oct 2003 11:43:06 -0700, David Eppstein <eppstein at> wrote:

> For simple use of built-in libraries,
> looks like a good test case.

Quick hack follows.

  edi at bird:/tmp > cat troll.lisp
  (asdf:oos 'asdf:load-op :aserve)
  (asdf:oos 'asdf:load-op :cl-ppcre)

  (defparameter *scanner*
     "<a href=\"AuthorThreads.asp[^\"]*\">([^<]+)</a></td>\\s*
  <td align=\"center\">[^<]+</td>\\s*
  <td align=\"center\">[^<]+</td>\\s*
  <td align=\"center\">\\d+</td>\\s*
  <td align=\"center\">(\\d+)</td>\\s*
  <td align=\"center\">(\\d+)</td>\\s*
  <td align=\"center\">\\d+</td>\\s*
  <td align=\"center\">(\\d+)</td>\\s*"))

  (defun troll-checker (name)
    (let ((target
             (format nil "" name)
             :protocol :http/1.0)))
      (cl-ppcre:do-scans (match-start match-end reg-starts reg-ends *scanner* target)
        (flet ((nth-group (n)
                 (subseq target (aref reg-starts n) (aref reg-ends n))))
          (let* ((group (nth-group 0))
                 (posts (parse-integer (nth-group 1)))
                 (replies (parse-integer (nth-group 2)))
                 (threads-touched (parse-integer (nth-group 3)))
                 (reply-to-post-ratio (/ replies posts))
                 (threads-to-post-ratio (/ threads-touched posts)))
            (unless (< posts 10)
              (format t "~55A R~,2F T~,2F ~:[~;TROLL~:[?~;!~]~]~%"
                      (subseq group 0 (min 55 (length group)))
                      (and (> reply-to-post-ratio .8)
                           (< threads-to-post-ratio .4))
                      (< threads-to-post-ratio .2))))))))

  (compile 'troll-checker)

  edi at bird:/tmp > cmucl
  ; Loading #p"/home/edi/.cmucl-init".
  CMU Common Lisp 18e, running on
  With core: /usr/local/lib/cmucl/lib/lisp.core
  Dumped on: Thu, 2003-04-03 15:47:12+02:00 on orion
  Send questions and bug reports to your local CMUCL maintainer,
  or see <>.
  Loaded subsystems:
      Python 1.1, target Intel x86
      CLOS 18e (based on PCL September 16 92 PCL (f))
  * (load "troll")

  ; loading system definition from /usr/local/lisp/Registry/aserve.asd into
  ; #<The ASDF1017 package, 0/9 internal, 0/9 external>
  ; registering #<SYSTEM ASERVE {4854AEF5}> as ASERVE
  ; loading system definition from /usr/local/lisp/Registry/acl-compat.asd into
  ; #<The ASDF1059 package, 0/9 internal, 0/9 external>
  ; registering #<SYSTEM ACL-COMPAT {4869AD35}> as ACL-COMPAT
  ; loading system definition from /usr/local/lisp/Registry/htmlgen.asd into
  ; #<The ASDF1145 package, 0/9 internal, 0/9 external>
  ; registering #<SYSTEM HTMLGEN {487E64C5}> as HTMLGEN
  ; loading system definition from /usr/local/lisp/Registry/cl-ppcre.asd into
  ; #<The ASDF1813 package, 0/9 internal, 0/9 external>
  ; registering #<SYSTEM #:CL-PPCRE {48F32835}> as CL-PPCRE
  ; Compiling LAMBDA (NAME):
  ; Compiling Top-Level Form:
  * (troll-checker "edi at")
  comp.lang.lisp                                          R0.93 T0.63
  * (troll-checker "eppstein at")                                       R1.00 T0.76
  rec.arts.sf.written                                     R0.99 T0.57
  comp.lang.python                                        R0.98 T0.64                                R1.00 T0.73
  sci.math                                                R1.00 T0.77
  rec.puzzles                                             R1.00 T0.75
  comp.theory                                             R1.00 T0.56                                R1.00 T0.87
  comp.sys.mac.apps                                       R1.00 T0.69
  * (troll-checker "spam at")
  comp.lang.lisp                                          R0.91 T0.44
  fr.comp.os.unix                                         R1.00 T0.70
  es.comp.os.linux.programacion                           R1.00 T0.67
  fr.comp.lang.lisp                                       R1.00 T0.40 TROLL?
  comp.unix.programmer                                    R1.00 T0.92                                     R1.00 T0.43                                          R0.95 T0.84                                        R1.00 T0.33 TROLL?
  alt.folklore.computers                                  R1.00 T0.43
  comp.lang.scheme                                        R0.83 T0.58
  fr.comp.os.mac-os.x                                     R0.92 T0.83

Granted, Portable AllegroServe[1] and CL-PPCRE[2] aren't "built-in"
(but freely available, compatible with various CL compilers, and easy
to install) and Python might have a bit more syntactic sugar but it
wasn't _too_ hard to do that in Lisp.


[1] <>
[2] <>

More information about the Python-list mailing list