Python syntax in Lisp and Scheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Dalke

    Re: Python syntax in Lisp and Scheme

    (I really am trying to stop posting to this thread. Really I am.)

    Erann Gat:[color=blue]
    > If you have no ambitions beyond writing
    > yet-another-standard-web-app then macros are not for you. But if your
    > goals run grander than that then the extra leverage that you get from
    > things like macros becomes very precious indeed.[/color]

    Fiddlesticks. My ambitions are to help people understand biology
    and chemistry by making tools to assist in managing the huge amount
    of data and algorithms available in the computational life sciences.
    Potentially helping find-cures-for-cancer type research. The fact
    that the algorithms involved in doing so are in almost all cases
    easily solved with functions instead of macros doesn't make them
    nor me ambitionless.

    And in those very rare cases where I need code generation,
    I can emit the code and compile it into C, or built my own parse
    tree in Python and generate byte code, or exec a string. They
    are almost invariably part of a compute kernel which can be
    treated a black box.

    Andrew
    dalke@dalkescie ntific.com


    Comment

    • Albert Lai

      Re: Python syntax in Lisp and Scheme

      corey.coughlin@ attbi.com (Corey Coughlin) writes:
      [color=blue]
      > (Not to mention car, cdr, cadr, and
      > so on vs. index notation, sheesh.)[/color]

      Yes, that is a real regret. It should have been useful to support
      a kind of (nth 10 mylist) straight from the Scheme standard library.
      [color=blue]
      > Using parentheses and rpn everywhere makes lisp very easy
      > to parse, but I'd rather have something easy for me to understand and
      > That's why I prefer python, you
      > get a nice algebraic syntax with infix and equal signs, and it's easy
      > understand.
      > Python is
      > intuitive to me out of the box, and it just keeps getting better, so I
      > think I'll stick with it.[/color]

      First, a minor correction: Lisp/Scheme is like (* 1 2) and that is
      Polish Notation or prefix; Reverse Polish Notation or postfix would be
      like (1 2 *).

      From what I heard about the Japanese language I have formed the
      possibly oversimplified impression that it is largely postfix.
      Whereas in English we say "I beat you", they may say something like "I
      you beat". So I suppose all of the existing programming notations -
      Lisp's and Cobol's (* 1 2) and MULTIPLY 1 BY 2, Fortran's "intuitive"
      1+2, and OO's one.add(two) - are very counterintuitiv e to them, and
      they would really like the way of HP calculators, no?

      And I suppose the ancient Romans (and even the modern Vaticans) would
      laugh at this entire dilemma (or trilemma?) between ___fixes.

      Intuition is acquired. It is purely a product of education or
      brainwashing. There is nothing natural about it. And since it is
      acquired, you may as well keep acquiring new intuitions and see more
      horizons, rather than keep reinforcing old intuitions and stagnate.
      Appreciating a foreign language such as Japanese some day is not a bad
      idea.

      Comment

      • Andrew Dalke

        Re: Python syntax in Lisp and Scheme

        Alex:[color=blue][color=green]
        > > it _will_, in my opinion, cause co-workers in any middle-
        > > or large-sized organization to risk ending up standing on each others'
        > > feet, rather than on each others' shoulders.[/color][/color]

        Pascal Costanza:[color=blue]
        > That's not an opinion, that's a fear.[/color]

        It is my opinion that covering oneself in blood then running naked
        in the African veldt through a pride of hungry lions is dangerous.

        You may disagree with me and label it a fear, but it's still my
        opinion and I'm not going to face that fear. You're free to try, ...
        so long as there's no way to sue me for liability.

        Andrew
        dalke2Da


        Comment

        • Daniel P. M. Silva

          Re: Python syntax in Lisp and Scheme

          Pascal Bourguignon wrote:[color=blue]
          > "Andrew Dalke" <adalke@mindspr ing.com> writes:[color=green][color=darkred]
          >> > It's
          >> > just a reaction to Python (a perfectly nice little scripting language)
          >> > trying to morph into a language with the sophistication of Lisp.[/color]
          >>
          >> Python isn't doing that. It's lives in a perfectly good niche wherein
          >> Lisp is not the most appropriate language. At least not until there's a
          >> macro which works like
          >>
          >> (#python '
          >> for i in range(100):
          >> print "Spam, ",
          >> print
          >> )[/color]
          >
          > This is trivial:
          >
          > (DEFUN SPLIT-ARGUMENTS (STRING)
          > (DO ((CHUNKS '()) (START 0) (POS 0))
          > ((<= (LENGTH STRING) POS)
          > (PROGN (WHEN (< START POS) (PUSH (SUBSEQ STRING START POS) CHUNKS))
          > (NREVERSE CHUNKS)))
          > (IF (CHAR= (CHAR STRING POS) (CHARACTER " "))
          > (PROGN (WHEN (< START POS) (PUSH (SUBSEQ STRING START POS) CHUNKS))
          > (INCF POS) (SETQ START POS))
          > (INCF POS)))
          > );;SPLIT-ARGUMENTS
          >
          >
          > (SET-DISPATCH-MACRO-CHARACTER
          > (CHARACTER "#") (CHARACTER "!")
          > (LAMBDA (STREAM CHAR ARG)
          > (DECLARE (IGNORE CHAR ARG))
          > ;; first read the interpreter path and arguments.
          > ;; next read the script up to a line beginning with "!#".
          > ;; then generate statements to the interpreter and feed it the script.
          > (DO ((INTERPRETER (SPLIT-ARGUMENTS (READ-LINE STREAM NIL NIL T)))
          > (SCRIPT '())
          > (LINE (READ-LINE STREAM NIL NIL T)
          > (READ-LINE STREAM NIL NIL T)))
          > ((AND (<= 2 (LENGTH LINE)) (STRING= "!#" LINE :END2 2))
          > `(LET ((INTERP-INPUT (EXT:RUN-PROGRAM ,(CAR INTERPRETER)
          > :ARGUMENTS ',(CDR INTERPRETER)
          > :INPUT :STREAM :OUTPUT :TERMINAL)))
          > ;; Sorry, clisp specific. Please replace ext:run-program by
          > ;; your favorite hook.
          > (DOLIST (LINE ',(NREVERSE SCRIPT))
          > (FORMAT INTERP-INPUT "~A~%" LINE))
          > (CLOSE INTERP-INPUT)))
          > (PUSH LINE SCRIPT))))
          >
          >
          >
          > [27]> #!/usr/bin/python
          > for i in range(100):
          > print "Spam, ",
          > print ""
          > !#
          >
          >
          > T
          > [28]> Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [ Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          > [Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam, Spam,
          >[/color]

          I think Andrew probably meant something more complicated, like this:

          (define add-n (#python ' lambda x: x + LISP.top.n.pyth on_value() '))

          (define n 1)

          (python-number->LISP-number (add-n 1)) ; 2


          Comment

          • Kenny Tilton

            Re: Python syntax in Lisp and Scheme



            Andrew Dalke wrote:[color=blue]
            > Me:
            >[color=green][color=darkred]
            >>>2 of 6 is better than random, so Jones' work can't be
            >>>complete bunkum.[/color][/color]
            >
            >
            > Jon S. Anthony:
            >[color=green]
            >>2 of 6 is worse than flipping a coin.[/color]
            >
            >
            > Since I said "Of the 6 languages there are two major misorderings"
            > I suspect this discussion has reached the point of weariness.
            >
            > Nevertheless, the ordering is 1 3 5 6 2 4
            >
            > Assume a cost metric based on simple transpositions, where
            > neighbors can be exchanged. This is the familiar interchange
            > (or Shell, or bubble, or ..) sort. The degree of disorder is
            > the number of exchanges needed to sort the list. For the
            > above it is ||{2-6, 2-5, 2-3, 4-6, 4-5}|| = 5
            >
            > The average number of exchanges needed to sort a randomly
            > arranged list with the Shell sort is N*(N-1)/4 == 7.5 for
            > this list of size 6, so it's already better than average.
            >
            > From Knuth, Searching and Sorting, 5.1.1, Table 1, the
            > distribution of the number of permutations with k inversions
            > of a list of length 6 is
            > 1 way to be ordered
            > 5 to have one transpositions to be ordered
            > 14 to be off by 2 transpositions
            > 29
            > 49
            > 71
            > 90
            > 101
            > 101
            > 90
            > 71
            > 49
            > 29
            > 14
            > 5
            > 1 to be completely reversed
            >
            > Thus there are 720 possible random orderings of a list of
            > size 6 and only 169 ways to be off by 5 or fewer transpositions.
            > meaning that there is only a 24% chance of being this good
            > randomly.
            >
            > If I understand 5.1.1(13) well enough, the variance is
            > sqrt(6*(2*6+5)* (6-1)/72) == 2.66 which means we're
            > right on the 1 sigma threshold, or about a 75% chance
            > that his table was not randomly generated.
            >
            > Again, this suggests Jones' work can't be complete
            > bunkum.[/color]

            I can see why you like studies. They are so much more malleable than
            peoples' reports of their experience. With numbers you can say things
            like "there is only a 25% chance I got this off a ouija (sp?) board" and
            it sounds good! I think the tobacco companies can use you, they're
            losing ground fast. Your research bureau can have the tag line "Our Data
            Guaranteed Not /Completely/ Random!"


            --

            What?! You are a newbie and you haven't answered my:


            Comment

            • Lulu of the Lotus-Eaters

              Re: Python syntax in Lisp and Scheme

              Kenny Tilton <ktilton@nyc.rr .com> wrote previously:
              |> It's only been out, what, twenty years? And another twenty before that
              |> for other lisps... How much time do you think you need?

              |Hey, we've been dead for thirty years, give us a break.
              |The bad news for other languages is that the evolution of programming
              |languages, like baseball, is a game played without a clock.

              I would think Lisp is more like cricket: wickets bracket both ends, no
              one can actually understand the rules, but at least the players wear
              white.

              --
              Keeping medicines from the bloodstreams of the sick; food from the bellies
              of the hungry; books from the hands of the uneducated; technology from the
              underdeveloped; and putting advocates of freedom in prisons. Intellectual
              property is to the 21st century what the slave trade was to the 16th.

              Comment

              • Erann Gat

                Re: Python syntax in Lisp and Scheme

                In article <tLphb.4805$dn6 .3423@newsread4 .news.pas.earth link.net>, "Andrew
                Dalke" <adalke@mindspr ing.com> wrote:
                [color=blue]
                > (I really am trying to stop posting to this thread. Really I am.)
                >
                > Erann Gat:[color=green]
                > > If you have no ambitions beyond writing
                > > yet-another-standard-web-app then macros are not for you. But if your
                > > goals run grander than that then the extra leverage that you get from
                > > things like macros becomes very precious indeed.[/color]
                >
                > Fiddlesticks.[/color]

                I should have said "can become" instead of "becomes". Obviously some
                things, even some grandly ambitious things, are best done without macros.
                But not all of them. (Also, I thought I was posting to comp.lang.lisp,
                not comp.lang.pytho n, when I wrote the preceding post. Forgot to pay
                attention to the followup-to header. It was not my intention to start a
                flamewar.)

                E.

                Comment

                • Christophe Rhodes

                  Re: Python syntax in Lisp and Scheme

                  "Andrew Dalke" <adalke@mindspr ing.com> writes:
                  [color=blue]
                  > Pascal Costanza:[color=green]
                  >> Furthermore note that this is not an implementation difference. The ANSI
                  >> standard defines the function COMPILE.[/color]
                  >
                  > Is the implementation free to *not* compile the code when the
                  > COMPILE function is called? That is, to leave it as is? How
                  > would a user tell the difference without running a timing test?[/color]

                  Somewhat ironically given the context, within the standard a user can
                  only tell whether code has been compiled by whether redefinitions of
                  macros affect the execution or not. (If they do, it hasn't been
                  compiled; if they don't, it has).

                  Christophe
                  --
                  http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
                  (set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
                  (defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusColleg eCambridge)

                  Comment

                  • james anderson

                    Re: higher-order macros [Re: Python syntax in Lisp and Scheme



                    "oleg@pobox.com " wrote:[color=blue]
                    >
                    > Macros generating macros and macros that take other macros as
                    > arguments are quite common in Scheme
                    > ...
                    >
                    > Syntax-rule-level ??!lambda and ??!apply:
                    > http://pobox.com/~oleg/ftp/Scheme/macros.html
                    >[/color]

                    interesting, but to contrast that with the referenced meta implementation, the
                    form of the macro argument matters:

                    hof hom
                    apply op form macro-expand (cons op form) or form
                    (either immediately or relegated to the compiler)

                    fixed-point functions fixed-point forms


                    are there examples where these little beasties are used in production?

                    ....

                    Comment

                    • james anderson

                      unicode / osx / atsui


                      hello;

                      i'm trying to understand how best to approach unicode representations .
                      i am told the pep-0261 is the standard for python.
                      it was not clear what mechanism it entails for access to os-level text
                      management facilities on the order of osx's "apple type services for unicode
                      imaging"[0]. i looked through the mac extensions, but did not discern anything
                      relevant. can anyone point me to code in wide and narrow builds which uses
                      such os-level facilities. i was given a reference which appeared to concern
                      windows' file names, but that, as is the case with direct stream codecs, is
                      primarly a static situation.

                      i would also be interested to hear if there have been any data collected on
                      preponderance of wide builds, and on the consequences in those installations
                      for storage and algorithm efficiency.

                      ....


                      [0] http://developer.apple.com/intl/atsui.html

                      Comment

                      • Edi Weitz

                        Re: Python syntax in Lisp and Scheme

                        On Thu, 09 Oct 2003 23:15:17 GMT, "Andrew Dalke" <adalke@mindspr ing.com> wrote:
                        [color=blue]
                        > My primary machine is Mac OS X. I always got frustrated getting
                        > fonts, sound, and movies working under the various Linux-based
                        > distributions, and I suspect there are the same problems with
                        > BSD-based distributions.[/color]

                        Although I've been using Linux and/or FreeBSD since about 1999 I
                        understand what you mean. It's still much too hard to set up a machine
                        if you just want to get your work done and don't like fiddling with
                        the OS internals.

                        But there are a couple of free Common Lisps available for Mac OS X -
                        OpenMCL, CLISP, SBCL, ECL, maybe more. (Plus the trial versions of
                        MCL, AllegroCL and LispWorks the latter of which has a fantastic
                        cross-platform GUI toolkit.) What's missing is someone who integrates
                        these Lisps and the available packages with something like Fink to
                        make OS X as convenient as Debian as far as Lisp is concerned. I think
                        this wouldn't be too hard - AFAIK Fink uses the same package format -
                        but somebody's gotta do the work. (If someone's willing to donate an
                        iBook or PowerBook to me I'll do it... :)

                        Just to show you that the situation isn't as bleak as you might think
                        here's the list of Debian packages maintained by Kevin Rosenberg:

                        <http://qa.debian.org/developer.php/developer.php?g pg_key=C4A3823E >

                        That's more than 110 and almost all of them are for Common Lisp. Plus,
                        there are Common Lisp packages maintained by other people, of
                        course. Still far less than what can be found on CPAN but a very good
                        base to start with. (And who needs Lingua::Romana: :Perligata anyway?
                        Pardon me that all my examples are for Perl but I'm much more familiar
                        with Perl than with Python.)
                        [color=blue]
                        > No one has told me they would hire me for contract work "if only you
                        > were a Lisp programmer."[/color]

                        No one has told me either. But I've had a lot of contract work in
                        Common Lisp since I started with it in 2000. If I were always waiting
                        for someone to tell me which language to use I'd probably be stuck
                        with Java, PHP, and Visual Basic forever. Yuck!
                        [color=blue][color=green]
                        > > 3. Run around complaining that you can't use Lisp because a certain
                        > > combination of features is not available for free. We have far too
                        > > many of these guys on c.l.l.[/color]
                        >
                        > Technically I'm cross-posting from c.l.py. And I actually complain
                        > for other reasons. ;)[/color]

                        Yes, I wasn't talking about you in particular.
                        [color=blue]
                        > So far I've made ... 4(?) half-hearted attempts at learning Lisp.[/color]

                        Next time try it wholeheartedly. .. :)
                        [color=blue]
                        > *sigh*. Another package that doesn't (err, won't) work on my Mac.[/color]

                        Same answer as above. The CD is based on SBCL so it should be possible
                        to do something similar for OS X (should even be easier in theory
                        because you don't need the Knoppix stuff for HW detection). It's just
                        that someone has to do it...

                        Cheers,
                        Edi.

                        Comment

                        • Edi Weitz

                          Re: Python syntax in Lisp and Scheme

                          On Thu, 09 Oct 2003 23:31:46 GMT, "Andrew Dalke" <adalke@mindspr ing.com> wrote:
                          [color=blue]
                          > Conjecture: Is it that the commericial versions of Lisp pull away
                          > some of the people who would otherwise help raise the default
                          > functionality of the free version? I don't think so... but then
                          > why?[/color]

                          I'm pretty sure this is the case. If you lurk in c.l.l for a while
                          you'll see that a large part of the regular contributors aren't what
                          you'd call Open Source zealots. Maybe that's for historical reasons, I
                          don't know. But of course that's different from languages which have
                          always been "free" like Perl or Python.

                          To give one example: One of the oldest dynamic HTTP servers out there
                          is CL-HTTP.[1] I think it is very impressive but it has a somewhat
                          dubious license which doesn't allow for commercial deployment - it's
                          not "free." Maybe, I dunno, it would have a much higher market share
                          if it had been licensed like Apache when it was released. I'm sure
                          there's much more high-quality Lisp software out there that hasn't
                          even been released.

                          Edi.

                          [1] <http://www.ai.mit.edu/projects/iiip/doc/cl-http/home-page.html>

                          Don't be fooled by the "Last updated" line. There's still active
                          development - see

                          <ftp://ftp.ai.mit.edu/pub/users/jcma/cl-http/devo>.

                          Comment

                          • Paul Foley

                            Re: Python syntax in Lisp and Scheme

                            On Fri, 10 Oct 2003 00:34:10 -0400, Lulu of the Lotus-Eaters wrote:
                            [color=blue]
                            > Kenny Tilton <ktilton@nyc.rr .com> wrote previously:
                            > |> It's only been out, what, twenty years? And another twenty before that
                            > |> for other lisps... How much time do you think you need?[/color]
                            [color=blue]
                            > |Hey, we've been dead for thirty years, give us a break.
                            > |The bad news for other languages is that the evolution of programming
                            > |languages, like baseball, is a game played without a clock.[/color]
                            [color=blue]
                            > I would think Lisp is more like cricket: wickets bracket both ends, no
                            > one can actually understand the rules, but at least the players wear
                            > white.[/color]

                            Oh, come on! Anyone can understand cricket! There are two teams.
                            The team that's in sits out, except for two batsmen, and the other
                            team come out and try to get the men that are in out. When a man goes
                            out, he goes in and another man comes out. When the team that's in
                            are all out, except for the one who's not out, the other team goes in,
                            until they're all out, too; and then a second innings is played.
                            That's more or less all there is to it!

                            --
                            Cogito ergo I'm right and you're wrong. -- Blair Houghton

                            (setq reply-to
                            (concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz> "))

                            Comment

                            • Dave Benjamin

                              Re: Python syntax in Lisp and Scheme

                              In article <bm57q3$ic9cp$1 @ID-169208.news.uni-berlin.de>, Greg Ewing (using news.cis.dfn.de ) wrote:[color=blue]
                              > That's true, although you don't really need macros for that,
                              > just something like Smalltalk-style code blocks -- if anyone
                              > can come up with a way of grafting them into the Python
                              > syntax...[/color]

                              Well, you'll have to do a better job than I did, because my proposal made
                              a distinct "thud" when I dropped it here. ;)

                              Dave

                              --
                              ..:[ dave benjamin (ramenboy) -:- www.ramenfest.com -:- www.3dex.com ]:.
                              : d r i n k i n g l i f e o u t o f t h e c o n t a i n e r :

                              Comment

                              • Alex Martelli

                                Re: Python syntax in Lisp and Scheme

                                On Friday 10 October 2003 05:52 am, Daniel Berlin wrote:[color=blue]
                                > On Oct 9, 2003, at 5:33 PM, Alex Martelli wrote:[color=green]
                                > > Rainer Deyke wrote:[color=darkred]
                                > >> Pascal Costanza wrote:
                                > >>> Pick the one Common Lisp implementation that provides the stuff you
                                > >>> need. If no Common Lisp implementation provides all the stuff you
                                > >>> need, write your own libraries or pick a different language. It's as
                                > >>> simple as that.
                                > >>
                                > >> Coming from a C/C++ background, I'm surprised by this attitude. Is
                                > >> portability of code across different language implementations not a
                                > >> priority for LISP programmers?[/color]
                                > >
                                > > Libraries distributed as binaries are not portable across different C++
                                > > implementations on the same machine (as a rule).[/color]
                                >
                                > This isn't true anymore (IE for newer compilers).[/color]

                                Wow, that IS great news! Does it apply to 32-bit Intel-oid machines (the
                                most widespread architecture) and the newest releases of MS VC++ (7.1)
                                and gcc, the most widespread compilers for it? I can't find any docs on what
                                switches or whatever I should give the two compilers to get seamless interop.

                                Specifically, the standard Python on Windows has long been built with MSVC++
                                and this has given problems to C-coded extension writers who don't own that
                                product -- it IS possible to use other compilers to build the extensions, but
                                only with much pain and some limitations (e.g on FILE* arguments). If this
                                has now gone away there would be much rejoicing -- with proper docs on the
                                Python side of things and/or use of whatever switches are needed to enable
                                this, if any, when we do the standard Python build on Windows.

                                [color=blue]
                                > Mangling, exception handling, etc, is all covered by the ABI.
                                >
                                > IBM's XLC 6.0 for OSX also follows this C++ ABI, and is thus compatible
                                > with G++ 3.x on OSX.[/color]

                                I'm not very familiar with Python on the Mac but I think it uses another
                                commercial compiler (perhaps Metrowerks?), so I suspect the same question
                                may apply here. It's not as crucial on other architectures where Python is
                                more normally built with free compilers, but it sure WOULD still be nice to
                                think of possible use of costly commercial compilers with hypothetically
                                great optimizations for the distribution of some "hotspot" object files, if
                                that sped the interpreter up without giving any interoperabilit y problems.


                                Alex


                                Comment

                                Working...