Python syntax in Lisp and Scheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Martelli

    Re: Code block literals

    Dave Benjamin wrote:
    [color=blue]
    > Alex Martelli wrote:[color=green]
    >> The only annoyance here is that there is no good 'literal' form for
    >> a code block (Python's lambda is too puny to count as such), so you
    >> do have to *name* the 'thefunc' argument (with a 'def' statement --
    >> Python firmly separates statements from expressions).[/color]
    >
    > Here's my non-PEP for such a feature:
    >
    > return { |x, y|
    > print x
    > print y
    > }
    >
    > Which would be the equivalent of:
    >
    > def anonymous_funct ion(x, y):
    > print x
    > print y
    > return anonymous_funct ion[/color]

    Oh, and what should:

    return {
    }

    MEAN? An empty dictionary, like today, or the equivalent of

    return lambda: None

    i.e. an empty argument-less function?

    This is just reason #1 why this syntax is not satisfactory (I
    guess it could be forced by mandating || to mean "takes no
    args" -- deviating from Ruby in that sub-issue, though). The
    second point is the use of punctuation in a way that no other
    Python syntactic context allows -- it really feels alien.

    Further, something that is more often than not desired by
    people who desire code blocks is that they *don't* start a
    new scope. Ruby fudges it with an ad-hoc rule -- use of
    variables already existing outside is "as if" you were in
    the same scope, use of new variables isn't (creates a new
    variable on each re-entry into the block via yield, right?).
    Clearly we can't use that fudge in Python. So, this is a
    semantic problem to solve for whatever syntax. Can we find
    any approach that solves ALL use cases? I don't know, but my
    personal inclination would be to try saying that such a block
    NEVER define a new lexical scope, just like list comprehensions
    don't -- i.e. in this sense such blocks would NOT be at all
    equivalent to the functions produced by a def statement (lots
    of implementation work, of course) -- all variables that might
    look like locals of such a block would instead be considered
    locals of the "enclosing" scope (which isn't enclosing, in a
    sense, as there's no other new scope to enclose...;-).

    SOME explicit termination is no doubt necessary if we want to
    allow returning e.g. a tuple of two or more such functions --
    which is why we can't try taking another (and less repellent
    to Pythonic syntax) leaf from Ruby's book (using do instead
    of { -- requires making do a keyword -- and leaving out the
    end that Ruby always requires, of course):

    return do(x, y):
    print x
    print y

    there would be no way to write something more after this
    block but within the same expression if the only termination
    was dedenting; perhaps:

    return ( do(x, y):
    print x
    print y
    ), ( do(x, y):
    print y
    print x
    )

    i.e. with parentheses around the do-expression (if you need
    to put anything more after it) might help here.
    [color=blue]
    > Then, merge map, filter, and reduce into the list type, so we can play[/color]

    Why? So you can't e.g. reduce an arbitrary iterator (e.g., genererator),
    tuple, array.array, ..., any more? We'd be better off without them, IMHO.
    I see no advantage, over e.g. itertools, in associating these syntactically
    to sequences (any kind or all kinds) or even iterators.


    Alex

    Comment

    • james anderson

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



      Andreas Rossberg wrote:[color=blue]
      >
      > Raymond Wiker wrote:[color=green][color=darkred]
      > >>
      > >>I'm not terribly familiar with the details of Lisp macros but since
      > >>recursion can easily lead to non-termination you certainly need tight
      > >>restriction s on recursion among macros in order to ensure termination
      > >>of macro substitution, don't you? Or at least some ad-hoc depth
      > >>limitation.[/color]
      > >
      > > Same as with function calls, you mean?[/color]
      >
      > In functional languages you at least have no limitation whatsoever on
      > the depth of tail calls. Is the same true for macros?[/color]

      any macro which cannot be implemented as a single quasiquoted form is likely
      to be implemented by calling a function which computes the expansion. the only
      difference between a macro function and any "normal" defined function is that
      the former is not necessarily any symbol's function value. an auxiliary
      function will be a function like any other function: anonymous, defined,
      available in some given lexical context only. whatever. there are no intrinsic
      restrictions on the computation which it performs. it need only admit to the
      reality, that the environment is that of the compiler. eg, definitions which
      are being compiled in the given unit "exist" if so specified only.

      i am curious whether the availability of tail call elimination can have any
      effect on the space performance of a function which is, in general, being
      called to compute expressions for inclusion in a larger form. my intuition
      says it would not matter.
      [color=blue]
      >
      > Apart from that, can one have higher-order macros? With mutual recursion
      > between a macro and its argument?[/color]

      what would that mean? a macro-proper's argument is generally an s-expression,
      and the macro function proper is not bound to a symbol and not necessarily
      directly funcallable, but i suppose one could come up with use cases for
      mutual recursion among the auxiliary functions.

      the generated expressions, on the other hand, often exhibit mutual references.
      in this regard, one might want, for example to look at j.schmidt's meta
      implementation.[1] perhaps, in some sense, the mutual references which it
      generates could be considered "higher-order", but that doesn't feel right.

      there's also the issue, that there is nothing which prevents a macro function
      from interpreting some aspects of the argument expression as instructions for
      operations to be performed at compile-time. eg. constant folding. depending on
      how the macro might establish constancy, i'm not sure what "order" that is.
      [color=blue]
      > That is, can you write a fixpoint
      > operator on macros?[/color]

      why one would ever think of doing that is beyond me, but given the standard y
      operator definition [0],

      ? (DEFUN Y (F)
      ( (LAMBDA (G) #'(LAMBDA (H) (FUNCALL (FUNCALL F (FUNCALL G G)) H)))
      #'(LAMBDA (G) #'(LAMBDA (H) (FUNCALL (FUNCALL F (FUNCALL G G))
      H)))))

      Y

      should one feel compelled to do so, one might resort to something like

      ? (defmacro print* (&rest forms)
      `(progn ,@(funcall (y #'(lambda (fn)
      #'(lambda (forms)
      (unless (null forms)
      (cons `(print ,(first forms))
      (funcall fn (rest forms)))))))
      forms)))

      PRINT*
      ? (macroexpand '(print* (list 1 2) "asdf" 'q))
      (PROGN (PRINT (LIST 1 2)) (PRINT "asdf") (PRINT 'Q))
      T
      ? (print* (list 1 2) "asdf" 'q)

      (1 2)
      "asdf"
      Q
      Q
      ?
      [color=blue]
      >
      > I'm not saying that any of this would be overly useful. Just trying to
      > refute Dirk's rather general statement about macros subsuming HOF's.
      >[/color]

      hmm... i never thought of it that way.


      [0] http://www.nhplace.com/kent/Papers/T...al-Issues.html
      [1] http://www.cliki.net/Meta

      Comment

      • Alex Martelli

        Re: Python syntax in Lisp and Scheme

        Doug Tolton wrote:
        [color=blue]
        > David Mertz wrote:
        >[color=green]
        >> There's something pathological in my posting untested code. One more
        >> try:
        >>
        >> def categorize_join tly(preds, it):
        >> results = [[] for _ in preds]
        >> for x in it:
        >> results[all(preds)(x)].append(x)
        >> return results
        >>
        >> |Come on. Haskell has a nice type system. Python is an application of
        >> |Greespun's Tenth Rule of programming.
        >>
        >> Btw. This is more nonsense. HOFs are not a special Lisp thing. Haskell
        >> does them much better, for example... and so does Python.
        >>[/color]
        > What is your basis for that statement? I personally like the way Lisp
        > does it much better, and I program in both Lisp and Python. With Python
        > it's not immediately apparent if you are passing in a simple variable
        > or a HOF. Whereas in lisp with #' it's immediately obvious that you are
        > receiving or sending a HOF that will potentially alter how the call
        > operates.
        >
        > IMO, that syntax is far clearner.[/color]

        I think it's about a single namespace (Scheme, Python, Haskell, ...) vs
        CLisp's dual namespaces. People get used pretty fast to having every
        object (whether callable or not) "first-class" -- e.g. sendable as an
        argument without any need for stropping or the like. To you, HOFs may
        feel like special cases needing special syntax that toots horns and
        rings bells; to people used to passing functions as arguments as a way
        of living, that's as syntactically obtrusive as, say, O'CAML's mandate
        that you use +. and not plain + when summing floats rather than ints
        (it's been a couple years since I last studied O'CAML's, so for all I
        know they may have changed that now, but, it IS in the book;-).

        No doubt they could make a case that float arithmetic has potentially
        weird and surprising characteristics and it's a great idea to make it
        "immediatel y obvious" that's it in use -- and/or the case that this
        allows stronger type inference and checking than SML's or Haskell's
        use of plain + here allows. Rationalization is among the main uses
        for the human brain, after all -- whatever feature one likes because
        of habit, one can make SOME case or other for;-).


        Alex

        Comment

        • Pascal Bourguignon

          Re: Python syntax in Lisp and Scheme


          "Andrew Dalke" <adalke@mindspr ing.com> writes:[color=blue]
          > That to me is a solid case of post hoc ergo proper. The
          > words "1st" and "rst" are equally as short and easier to
          > memorize. And if terseness were very important, then
          > what about using "." for car and ">" for cdr? No, the reason
          > is that that's the way it started and it will stay that way
          > because of network effects -- is that a solid engineering
          > reason? Well, it depends, but my guess is that he wouldn't
          > weight strongly the impact of social behaviours as part of
          > good engineering. I do.[/color]

          Right, network effect. And attachment to historic heritage. C has B
          and "Hello World!". COBOL has real bugs pined in log books. Lisp has
          704' CAR and CDR.


          --
          __Pascal_Bourgu ignon__

          Do not adjust your mind, there is a fault in reality.

          Comment

          • Pascal Bourguignon

            Re: Python syntax in Lisp and Scheme

            "Andrew Dalke" <adalke@mindspr ing.com> writes:[color=blue]
            > Or is there a requirement that it be constrained to display
            > systems which can only show ASCII? (Just like a good
            > Lisp editor almost requires the ability to reposition a
            > cursor to blink on matching open parens. Granted, that
            > technology is a few decades old now while Unicode isn't,
            > but why restrict a new language to the display systems
            > of the past instead of the present?)[/color]

            Because the present is composed of the past. You have to be
            compatible, otherwise you could not debug a Deep Space 1 probe
            160 million km away, (and this one was only two or three years old).



            [color=blue]
            > Indeed. It looks easier to understand to my untrained eye.
            > I disagree that "+" shouldn't work on strings because that
            > operation isn't commutative -- commutativity isn't a feature
            > of + it's a feature of + on a certain type of set.[/color]

            Mathematicians indeed overload operators with taking into account
            their precise properties. But mathematicians are naturally
            intelligent. Computers and our programs are not. So it's easier if
            you classify operators per properties; if you map the semantics to the
            syntax, this allow you to apply transformations on your programs based
            on the syntax without having to recover the meaning.


            --
            __Pascal_Bourgu ignon__

            Do not adjust your mind, there is a fault in reality.

            Comment

            • Edi Weitz

              Re: Python syntax in Lisp and Scheme

              [Followup-To ignored because I don't read comp.lang.pytho n]

              On Thu, 09 Oct 2003 16:13:54 GMT, Alex Martelli <aleax@aleax.it > wrote:
              [color=blue]
              > I think it's about a single namespace (Scheme, Python, Haskell, ...)
              > vs CLisp's dual namespaces. People get used pretty fast to having
              > every object (whether callable or not) "first-class" --
              > e.g. sendable as an argument without any need for stropping or the
              > like. To you, HOFs may feel like special cases needing special
              > syntax that toots horns and rings bells; to people used to passing
              > functions as arguments as a way of living, that's as syntactically
              > obtrusive as, say, O'CAML's mandate that you use +. and not plain +
              > when summing floats rather than ints[/color]

              In Common Lisp (not "CLisp", that's an implementation) functions /are/
              first-class and sendable as an argument "without any need for
              stropping or the like." What exactly are you talking about?

              Edi.

              Comment

              • james anderson

                stropping [Re: Python syntax in Lisp and Scheme



                Alex Martelli wrote:[color=blue]
                >
                > Doug Tolton wrote:
                >
                > ...[color=green][color=darkred]
                > >> Btw. This is more nonsense. HOFs are not a special Lisp thing. Haskell
                > >> does them much better, for example... and so does Python.
                > >>[/color]
                > > What is your basis for that statement? I personally like the way Lisp
                > > does it much better, and I program in both Lisp and Python. With Python
                > > it's not immediately apparent if you are passing in a simple variable
                > > or a HOF. Whereas in lisp with #' it's immediately obvious that you are
                > > receiving or sending a HOF that will potentially alter how the call
                > > operates.
                > >
                > > IMO, that syntax is far clearner.[/color]
                >
                > I think it's about a single namespace (Scheme, Python, Haskell, ...) vs
                > CLisp's dual namespaces. People get used pretty fast to having every
                > object (whether callable or not) "first-class" -- e.g. sendable as an
                > argument without any need for stropping or the like. To you, HOFs may
                > feel like special cases needing special syntax that toots horns and
                > rings bells; to people used to passing functions as arguments as a way
                > of living, that's as syntactically obtrusive as, say, O'CAML's mandate
                > that you use +. and not plain + when summing floats rather than ints
                > (it's been a couple years since I last studied O'CAML's, so for all I
                > know they may have changed that now, but, it IS in the book;-).
                >[/color]

                it can't really be the #' which is so troubling.

                ? (defmacro define (name parameters &rest body)
                `(set (defun ,name ,parameters ,@body)
                (function ,name)))
                DEFINE
                ? (define lof (a b) (cons a b))
                #<Compiled-function LOF #x78467E6>
                ? (mapcar lof '(1 2 3) '(a s d))
                ((1 . A) (2 . S) (3 . D))
                ?

                what is the real issue?

                ....

                Comment

                • Kenny Tilton

                  Re: Python syntax in Lisp and Scheme



                  Pascal Costanza wrote:[color=blue]
                  > Kenny Tilton wrote:
                  >[color=green]
                  >> Speaking of non-pros:
                  >>
                  >> "Lisp is easy to learn
                  >>
                  >> Lisp's syntax is simple, compact and spare. Only a handful of “rules”
                  >> are needed. This is why Lisp is sometimes taught as the first
                  >> programming language in university-level computer science courses. For
                  >> the composer it means that useful work can begin almost immediately,
                  >> before the composer understands much about the underlying mechanics of
                  >> Lisp or the art of programming in general. In Lisp one learns by doing
                  >> and experimenting, just as in music composition. "
                  >>
                  >> From: http://pinhead.music.uiuc.edu/~hkt/nm/02/lisp.html
                  >>
                  >> No studies, tho.[/color]
                  >
                  >
                  > Here they are: http://home.adelphi.edu/sbloch/class/hs/testimonials/
                  >[/color]

                  Oh, please:

                  "My point is... before I started teaching Scheme, weak students would
                  get overwhelmed by it all and would start a downward spiral. With
                  Scheme, if they just keep plugging along, weak students will have a
                  strong finish. And that's a great feeling for both of us!"

                  That kind of anecdotal crap is meaningless. We need statistics!
                  Preferably with lots of decimal places so we know they are accurate.

                  :)

                  --

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


                  Comment

                  • Alex Martelli

                    Re: Python syntax in Lisp and Scheme

                    Doug Tolton wrote:
                    ...[color=blue]
                    > don't know me or my background. Alex has stated on many occasions that
                    > he has not worked with Macros, but that he is relying on second hand
                    > information.[/color]

                    I never used Common Lisp in production: in the period of my life when I
                    was hired (by Texas Instruments) specifically for my knowledge of "Lisp",
                    that meant Scheme and a host of other dialects (mostly but not entirely now
                    forgotten). I did use things that "passed for" macros in those dialects:
                    I had no choice, since each TI lab or faction within the lab was using a
                    different divergent mutant thing, all named "lisp" (save a few were named
                    "scheme" -- hmmm, I do believe that some were using Prolog, too, but I
                    did not happen to use it in TI), with some of the divergence hinging on
                    locally developed sets of macros (and some on different vendors/versions).

                    For all I know, CLisp's macros are SO head and shoulders above any of a
                    quarter century ago that any vaguely remembered technical problem from
                    back then may be of purely historical interest. I do believe that the
                    divergence problem has more to do with human nature and sociology, and
                    that putting in a language features that encourage groups and subgroups
                    of users to diverge that language cannot be compensated by technical
                    enhancements -- 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. (Remedies must of course
                    be sociological and lato sensu political first and foremost, but the way
                    the language & tools are designed CAN help or hinder).

                    So, I'm nowhere near an _expert_ -- over 20 years' hiatus ensures I
                    just can't be. But neither is it totally 2nd hand information, and if
                    I gave the mistaken impression of never having used macros in a
                    production setting I must have expressed myself badly. I do know I
                    jumped on the occasion of moving to IBM Research, and the fact that
                    this would mean going back to APL instead of "lisp" (in the above
                    vague sense) did matter somewhat in my glee, even though I still
                    primarily thought of myself as a hardware person then (the programming
                    was needed to try out algorithms, simulate possible hardware
                    implementations thereof, etc -- it was never an end in itself).

                    [color=blue]
                    > I don't claim to be a guru on Lisp, however I believe I understand it
                    > far better than Alex does. If the people who actually know and use
                    > Common Lisp think I am mis-speaking and mis-representing Lisp, please
                    > let me know and I will be quiet.[/color]

                    Give that I've heard "everything and its opposite" (within two constant
                    parameters only: S-expressions are an unalloyed good -- macros are good,
                    some say unconditionally , others admit they can be prone to abuse) from
                    posters on this thread from "people who actually know and use" Lisp, I
                    don't know how you could "mis-speak and mis-represent" as long as you
                    stick to the two tenets of party doctrine;-).

                    [color=blue]
                    > Like I said, I'm not an expert at Lisp, but I think I understand the
                    > spirit and semantics of Lisp far better than Alex, and from what I've[/color]

                    If by Lisp you mean Common Lisp and exclude Scheme, I'm sure you do; if
                    Scheme is to be included, then I'm not sure (but it's quite possible,
                    nevertheless) -- at least the "spirit" of the small core and widespread
                    HOFs w/single-namespace seem to be things I understand more (but the
                    "spirit" of why it's so wonderful to have extensible syntax isn't:-).


                    Alex

                    Comment

                    • Dave Benjamin

                      Re: Code block literals

                      In article <840592e1.03100 90454.4d95a170@ posting.google. com>, Hannu Kankaanp?? wrote:[color=blue]
                      > Dave Benjamin <dave@3dex.co m> wrote in message news:<u%0hb.113 $_f.1@news1.cen tral.cox.net>.. .[color=green]
                      >> For instance, I always thought this was a cooler alternative to the
                      >> try/finally block to ensure that a file gets closed (I'll try not to
                      >> mess up this time... ;) :
                      >>
                      >> open('input.txt ', { |f|
                      >> do_something_wi th(f)
                      >> do_something_el se_with(f)
                      >> })[/color]
                      >
                      > But being a function, it'd have the nasty property of a
                      > separate scope (yes, that can be nasty sometimes). I'd perhaps
                      > want to do
                      >
                      > open('input.txt ', { |f| data = f.read() })
                      >
                      > But alas, 'data' would be local to the anonymous function and
                      > not usable outside.[/color]

                      Well, that's the same problem that lambda's got. I don't really have a
                      solution for that, other than the usual advice: "Use a namespace". =)

                      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

                      • Rainer Deyke

                        Re: Python syntax in Lisp and Scheme

                        Pascal Costanza wrote:[color=blue]
                        > 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.[/color]

                        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?


                        --
                        Rainer Deyke - rainerd@eldwood .com - http://eldwood.com


                        Comment

                        • Dave Benjamin

                          Re: Code block literals

                          In article <mxehb.190229$h E5.6409803@news 1.tin.it>, Alex Martelli wrote:[color=blue]
                          > Dave Benjamin wrote (answering Mike Rovner):
                          > ...[color=green][color=darkred]
                          >>> "Explicit is better than implicit"[/color]
                          >>
                          >> In that case, why do we eschew code blocks, yet have no problem with the
                          >> implicit invocation of an iterator, as in:
                          >>
                          >> for line in file('input.txt '):
                          >> do_something_wi th(line)[/color]
                          >
                          > I don't see that there's anything "implicit" in the concept that a
                          > special operation works as indicated by its syntax. I.e., I do not
                          > find this construct any more "implicit" in the first line than in
                          > its second one, which is the juxtaposition of a name and a pair of
                          > parentheses to indicate calling-with-arguments -- and alternatives...[/color]

                          What's implicit to me is that the use of an iterator is never specified.
                          For instance, we could (and I'm *not* suggesting this) do this:

                          iterator = file('input.txt ')
                          while iterator.has_ne xt():
                          line = iterator.next()
                          do_something_wi th(line)
                          [color=blue]
                          > This has nothing to do with "eschewing code blocks", btw; code blocks
                          > are not "eschewed" -- they are simply syntactically allowed, as
                          > "suites", only im specific positions. If Python's syntax defined
                          > other forms of suites, e.g. hypothetically:
                          >
                          > with <object>:
                          > <suite>
                          >
                          > meaning to call the object (or some given method[s] in it, whatever)
                          > with the suite as its argument, it would be just as explicit as, e.g.:
                          >
                          > for <name> in <object>:
                          > <suite>
                          >
                          > or
                          >
                          ><object>(<obje ct>)[/color]

                          This would be an interesting alternative, but it's back to being a special
                          case, like Ruby has. I think it'd be more flexible as a literal that returns
                          a callable.
                          [color=blue][color=green]
                          >> This is not to say that I dislike that behavior; in fact, I find it
                          >> *beneficial* that the manner of looping is *implicit* because you can
                          >> substitute a generator for a sequence without changing the usage. But[/color]
                          >
                          > You could do so even if you HAD to say iter(<object>) instead of
                          > just <object> after every "for <name> in" -- it wouldn't be any
                          > more "explicit", just more verbose (redundant, boiler-platey). So
                          > I do not agree with your motivation for liking "for x in y:" either;-).[/color]

                          Well, let's just say I've been on the Java side of the fence for a little
                          while, and it has redefined my personal definition of explicit. One of the
                          reasons Python code is so much smaller than Java code is that a lot of
                          things are implicit that are required to be explicit in Java. I see this as
                          a good thing.
                          [color=blue][color=green]
                          >> there's little readability difference, IMHO, between that and:
                          >>
                          >> file('input.txt ').each_line({ |line|
                          >> do_something_wi th(line)
                          >> })[/color]
                          >
                          > Not huge, but the abundance of ({ | &c here hurts a little bit.[/color]

                          Well, we all __pick__ our __poisons__...
                          [color=blue][color=green]
                          >> Plus, the first example is only obvious because I called my iteration
                          >> variable "line", and because this behavior is already widely known. What
                          >> if I wrote:
                          >>
                          >> for byte in file('input.dat '):
                          >> do_something_wi th(byte)
                          >>
                          >> That would be a bit misleading, no? But the mistake isn't obvious. OTOH,
                          >> in the more explicit (in this case) Ruby language, it would look silly:
                          >>
                          >> open('input.txt ').each_line { |byte|
                          >> # huh? why a byte? we said each_line!
                          >> }[/color]
                          >
                          > Here, you're arguing for redundance, not for explicitness: you are claiming
                          > that IF you had to say the same thing more than once, redundantly, then
                          > mistakes might be more easily caught. I.e., the analogy is with:
                          >
                          > file('foo.txt') .write('wot?')
                          >
                          > where the error is not at all obvious (until runtime when you get an
                          > exception): file(name) returns an object *open for reading only* -- so
                          > if you could not call file directly but rather than do say, e.g.:
                          >
                          > file.open_for_r eading_only('fo o.txt').write(' wot?')[/color]

                          Nah, I'm not arguing for redundancy at all. I'm saying that there is some
                          voodoo going on here. When the *constructor* for a file object behaves like
                          a generator that loops over newline-delimited lines of a text field, doesn't
                          that seem like it's been specialized for a particular domain in an unobvious
                          way? Why lines? Why not bytes, words, unicode characters? I mean, it's more
                          convenient for people that do a lot of text processing, but I don't see
                          anything specific to text or lines in the phrase "file('foo.txt' )". That's
                          all I'm saying.
                          [color=blue][color=green]
                          >> I think this is important to point out, because the implicit/explicit
                          >> rule comes up all the time, yet Python is implicit about lots of things!
                          >> To name a few:
                          >>
                          >> - for loops and iterators[/color]
                          >
                          > Already addressed above: nothing implicit there.[/color]

                          Likewise, and I still disagre... =)
                          [color=blue][color=green]
                          >> - types of variables[/color]
                          >
                          > There are none, so how could such a nonexisting thing be EITHER implicit
                          > OR explicit? Variables don't HAVE types -- OBJECTS do.[/color]

                          The very fact that variables to not have types, and following that, that
                          variables do not have manifest types, is an example of implicit being
                          chosen over explicit. I know your argument, and I understand that Python
                          variables are Post-It sticky notes and all of that, but please, just try to
                          look at it from a non-Python-centric perspective. Other languages (like C++,
                          which I hear you are vaguely familiar with ;) require you to be explicit
                          about what type of thing you're defining and sending where. Python does not.
                          This is one of its strengths, because it allows for ad-hoc interfaces and
                          polymorphism without a lot of boilerplate.
                          [color=blue]
                          > Etc, etc -- can't spend another 1000 lines to explain why your "lots of
                          > things" do not indicate violations of "explicit is better than implicit".[/color]

                          They're not *violations*. Correct me if I'm wrong, but the Zen of Python is
                          not the LAW! It's a poem! It's very beautiful, very concise, inspiring, and
                          thoughtful, but it's not the 10 commandments! I just get very tired of every
                          idea getting shot down because of some rule from Tim Peters. I really don't
                          think he intended for it to be used to prove the validity of ideas.

                          The implicit/explicit thing is one of the most abused, in my opinion,
                          because it can quite frankly be used to shut down any attempt at creating
                          abstraction. In fact, for that reason alone, I'm tempted to say "Implicit is
                          better than explicit". Say what you want, not how you want it. Be abstract,
                          not concrete.
                          [color=blue][color=green]
                          >> If all you're saying is that naming something is better than not naming
                          >> something because explicit is better than implicit, I'd have to ask why:[/color]
                          >
                          > Sometimes it is (to avoid perilous nesting), sometimes it isn't (to
                          > avoid wanton naming). I generally don't mind naming things, but it IS
                          > surely possible to overdo it -- without going to the extreme below,
                          > just imagine a language where ONLY named argument passing, and no use
                          > of positional arguments, was allowed (instead of naming arguments being
                          > optional, as it is today in Python).[/color]

                          I don't have to imagine. It's called Smalltalk, and also (to some extent)
                          Tcl/Tk. Even Tkinter seems to be named-argument only. It's not that bad.
                          I still like positional parameters, though.
                          [color=blue]
                          > If a Pythonic syntax can't be found to solve ALL use cases you've
                          > raised, then the "balance" may be considered not nice enough to
                          > compensate for the obvious problem -- a serious case of MTOWTDI.[/color]

                          That's another argument for another day. ;)
                          [color=blue][color=green][color=darkred]
                          >>> Python prioritize things diferently than other languages.
                          >>> It's not an APL. "Readabilit y counts"[/color]
                          >>
                          >> This is nothing like APL... if anything, it's like Smalltalk, a language
                          >> designed to be readable by children![/color]
                          >
                          > Cite pls? I knew that Logo and ABC had been specifically designed
                          > with children in mind, but didn't know that of Smalltalk.[/color]




                          [color=blue][color=green]
                          >> I realize that APL sacrificed
                          >> readability for expressiveness to an uncomfortable extreme, but I really
                          >> think you're comparing apples and oranges here. List comprehensions are
                          >> closer to APL than code blocks.[/color]
                          >
                          > As an ex-user of APL (and APL2) from way back when, I think you're
                          > both talking through your respective hats: neither list comprehensions
                          > (particularly in the Python variation on a Haskell theme, with
                          > keywords rather than punctuation) nor code blocks resemble APL in the least.[/color]

                          Well, it was a rough analogy, and I've never done any APL myself, but here's
                          my justification, FWIW:

                          - APL provides syntactical constructs for high-level array processing
                          - List comprehensions do this also
                          - Code blocks have nothing inherently to do with array processing

                          But I agree that neither resemble APL as I've seen. I guess it's like saying
                          a carrot is more like APL than a rutabega.

                          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

                          • james anderson

                            Re: Python syntax in Lisp and Scheme



                            Rainer Deyke wrote:[color=blue]
                            >
                            > Pascal Costanza wrote:[color=green]
                            > > 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.[/color]
                            >
                            > 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]

                            there are some things which the standard does not cover.

                            ....

                            Comment

                            • Kenny Tilton

                              Re: Python syntax in Lisp and Scheme



                              Alex Martelli wrote:[color=blue]
                              > ... I do believe that the
                              > divergence problem has more to do with human nature and sociology, and
                              > that putting in a language features that encourage groups and subgroups
                              > of users to diverge that language ....[/color]

                              Can someone write a nifty Python hack to figure out how many times
                              Lispniks have tried to get Alex to explain how macros are any different
                              than high-order functions or new classes when it comes to The Divergence
                              Problem? I love that we have given it a name, by the way.

                              One popular macro is WITH-OUTPUT-TO-FILE. My budding RoboCup starter kit
                              was a vital WITH-STD-ATTEMPT macro. Oh god, no! I need to see the ANSI
                              Lisp commands for these things so I can really understand them. Better
                              yet...

                              why not the disassembly? preferably without meaningful symbols from the
                              HLL source. I think we are finally getting somewhere with TDP. Those
                              high order classes, functions, and macros keep me from seeing what is
                              really going on. Now if I could only see the microcode....

                              :)

                              kenny

                              --

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


                              Comment

                              • Thomas F. Burdick

                                Re: Python syntax in Lisp and Scheme

                                Andreas Rossberg <rossberg@ps.un i-sb.de> writes:
                                [color=blue]
                                > Dirk Thierbach wrote:[color=green]
                                > >[color=darkred]
                                > >>>you can use macros to do everything one could use HOFs for (if you
                                > >>>really want).[/color]
                                > >
                                > > I should have added: As long as it should execute at compile time, of
                                > > course.
                                > >[color=darkred]
                                > >>Really? What about arbitrary recursion?[/color]
                                > >
                                > > I don't see the problem. Maybe you have an example? I am sure the
                                > > Lisp'ers here can come up with a macro solution for it.[/color]
                                >
                                > I'm not terribly familiar with the details of Lisp macros but since
                                > recursion can easily lead to non-termination you certainly need tight
                                > restrictions on recursion among macros in order to ensure termination of
                                > macro substitution, don't you? Or at least some ad-hoc depth limitation.[/color]

                                I'm not terribly familiar with the details of Python's iteration constructs
                                but since iteration can easily lead to non-termination you certainly need tight
                                restrictions on ...

                                In some cases, recursive macros and functions are easier to get right
                                (avoid infinite recursion) than their iterative counterparts.
                                Careless coders will always find a way to code themselves into
                                infinite loops. The easy way to avoid infinite recursion is:

                                (cond
                                ((===> base case <===) ...)
                                ((===> another base case? <===) ...)
                                ((...) recursive call)
                                ((...) recursive call)
                                ...
                                (t recursive call))

                                Most of the time, it's easy to ensure that all recursive calls "move
                                up" the cond tree. Times when you can't do that (or not easily), you
                                should be writing iterative code, or you're just doing something
                                inherently difficult.
                                [color=blue]
                                > "Computer games don't affect kids; I mean if Pac Man affected us
                                > as kids, we would all be running around in darkened rooms, munching
                                > magic pills, and listening to repetitive electronic music."
                                > - Kristian Wilson, Nintendo Inc.[/color]

                                (That's a great sig!)

                                --
                                /|_ .-----------------------.
                                ,' .\ / | No to Imperialist war |
                                ,--' _,' | Wage class war! |
                                / / `-----------------------'
                                ( -. |
                                | ) |
                                (`-. '--.)
                                `. )----'

                                Comment

                                Working...