Loading ...
Sorry, an error occurred while loading the content.

Re: [Cheetahtemplate-discuss] feature request

Expand Messages
  • Mike Orr
    ... This is definitely a bug, according to the rules we ve laid out in the User s Guide. range($i) should be a syntax error, and range alone would either
    Message 1 of 17 , Oct 23, 2001
    • 0 Attachment
      On Tue, Oct 23, 2001 at 03:59:37AM -0700, Chuck Esterbrook wrote:
      > Note that I said "range" instead of "$range". I'm taking advantage of
      > something I noticed in Cheetah a while back: if you say "foo" rather than
      > "$foo" you can access ordinary Python names including self, range, etc.

      This is definitely a bug, according to the rules we've laid out in the
      User's Guide. 'range($i)' should be a syntax error, and 'range'
      alone would either be a syntax error or an unknown directive attribute.
      Perhaps we can add to the error message, "Did you forget to prefix '$'?"

      --
      -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
      http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Mike Orr
      ... Simple features that help to bring the intended document structure to the surface = good. If it s also a unique feature, or unusual among template systems
      Message 2 of 17 , Oct 23, 2001
      • 0 Attachment
        On Tue, Oct 23, 2001 at 10:15:42AM -0700, Tavis Rudd wrote:
        > I'm ambivalent about #repeat. What do other people think??
        > It is easier for non-programmers to grasp.

        Simple features that help to bring the intended document structure
        to the surface
        => good.
        If it's also a unique feature, or unusual among template systems or
        programming languages
        => very good, a selling point for Cheetah.

        Complex features that are hard to explain or prone to bugs
        => bad.

        Features that expand Cheetah's scope into domains it shouldn't be,
        encouraging users to build spaghetti code in Cheetah rather than
        modular Python
        => bad.
        But obviously, Cheetah's developers disagree on where the boundary
        lies.

        #repeat does not expand Cheetah's scope into Python-land, it merely
        provides a more convenient alternative for $range(i).

        Although, there's another difference.
        #for $i in $range($n)
        provides a zero-based index variable, useful for numbering your rows.
        #repeat doesn't provide an index variable, so it can't be used in
        such situations, which account for a signinficant %age of repeat loops.

        How about:
        #repeat $i EXPR

        Then the question is whether to be zero-based or one-based. One-based
        would be more convenient for many applications, but it would be
        inconsistent with Python and other Cheetah usage.

        --
        -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
        http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Mike Orr
        ... Make sure the User s Guide says that Python builtins are available. -- -Mike (Iron) Orr, iron@mso.oz.net (if mail problems: mso@jimpick.com)
        Message 3 of 17 , Oct 23, 2001
        • 0 Attachment
          On Tue, Oct 23, 2001 at 10:15:42AM -0700, Tavis Rudd wrote:
          > Cheetah knows that self, the Python builtins, local vars,
          > and names imported from other modules using #import and
          > #from should be treated differently from names in the
          > searchList.

          Make sure the User's Guide says that Python builtins are
          available.

          --
          -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
          http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Ian Bicking
          ... That just reminded me about the nice variables DTML sets in dtml-in statements. Ummm... can t remember them all. sequence-index, even/odd, first/last...
          Message 4 of 17 , Oct 23, 2001
          • 0 Attachment
            iron@... (Mike Orr) wrote:
            > Although, there's another difference.
            > #for $i in $range($n)
            > provides a zero-based index variable, useful for numbering your rows.
            > #repeat doesn't provide an index variable, so it can't be used in
            > such situations, which account for a signinficant %age of repeat loops.

            That just reminded me about the nice variables DTML sets in dtml-in
            statements. Ummm... can't remember them all. sequence-index,
            even/odd, first/last... maybe some others.

            I thought those were good ideas. I'm not sure how to do them in
            Cheetah. We could set default variables, maybe like $loop.index,
            $loop.even, etc. We could do something like:

            #for $a in $b loop $c
            $c.index
            #end for

            I don't like DTML's automatic setting of some variables, but then it
            does keep things brief -- sequence-item is dumb, since there's way too
            much clashing, but that might not be as much of a problem with the
            other variables.


            To me, #repeat and #unless both seem like good statements. They are
            just syntactic sugar, not really feature creap, and they are
            intuitive. #until fits in too.

            Ian

            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Mike Orr
            ... Search for dtml-in in the cheetah-discuss archives and you should find my two researches into it, based on the DTML source. I ve been a fan of this, and
            Message 5 of 17 , Oct 23, 2001
            • 0 Attachment
              On Tue, Oct 23, 2001 at 01:35:38PM -0500, Ian Bicking wrote:
              > iron@... (Mike Orr) wrote:
              > > Although, there's another difference.
              > > #for $i in $range($n)
              > > provides a zero-based index variable, useful for numbering your rows.
              > > #repeat doesn't provide an index variable, so it can't be used in
              > > such situations, which account for a signinficant %age of repeat loops.
              >
              > That just reminded me about the nice variables DTML sets in dtml-in
              > statements. Ummm... can't remember them all. sequence-index,
              > even/odd, first/last... maybe some others.

              Search for "dtml-in" in the cheetah-discuss archives and you should
              find my two researches into it, based on the DTML source. I've been
              a fan of this, and Tavis asked me to make an implementation proposal,
              but it's been sitting on the back burner. Partly, I'm not sure what
              kind of user interface would be best.

              > I thought those were good ideas. I'm not sure how to do them in
              > Cheetah. We could set default variables, maybe like $loop.index,
              > $loop.even, etc. We could do something like:
              >
              > #for $a in $b loop $c
              > $c.index
              > #end for

              I was thinking of some kind of object, like
              #for $o in $batch($sequenceObject, size=5, page=2)
              (If sequenceObject contains subscripts [0..30], this batch would
              be [5..9].)

              I hadn't thought of using a separate object for the metadata.
              I was thinking of the metadata being available as methods, with
              an option to insert them as attributes into the target element.
              Of course, with autocalling now, the concept of leaving them as
              methods isn't as bad as it was.

              Zope also has some features I'm not sure how to implement.
              For instance, the metadata allows you to build URLs that point
              to the same page but with different starting/ending subscripts.
              But that assumes an entire Zope framework with special handling
              of those CGI parameters. For Cheetah/Webware, we'd have to
              provide that part of the structure somehow.

              > I don't like DTML's automatic setting of some variables, but then it
              > does keep things brief -- sequence-item is dumb, since there's way too
              > much clashing, but that might not be as much of a problem with the
              > other variables.

              sequence-item is dumb and should be abolished.

              Some things will be a bit different. If $o[0] contains attributes
              'name' and 'phone', in DTML you'd write:
              <dtml-in myList>
              <dtml-var name>: <dtml-var phone>
              My object myList[n] is : <dtml-var sequence-item>
              </dtml-in>

              In Cheetah you'd write:

              #for $o in $myList:
              $o.name: $o.phone
              My object myList[n] is: $o
              #end for

              I do think this batch behavior should be encapsulated by a
              separate object if possible. We should extend #for only if we're
              sure it wouldn't impact performance when the batch feature isn't
              used. There's also been talk of a separate #batch directive,
              although the syntax and usage is completely undetermined.

              > #until fits in too.

              OK. #until =
              #while not (EXPR)

              --
              -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
              http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • Ian Bicking
              ... Yeah, I thought we d discussed that, and then forgotten it again :) ... I think batching is a little different than this, though it could be something as
              Message 6 of 17 , Oct 23, 2001
              • 0 Attachment
                iron@... (Mike Orr) wrote:
                > > That just reminded me about the nice variables DTML sets in dtml-in
                > > statements. Ummm... can't remember them all. sequence-index,
                > > even/odd, first/last... maybe some others.
                >
                > Search for "dtml-in" in the cheetah-discuss archives and you should
                > find my two researches into it, based on the DTML source. I've been
                > a fan of this, and Tavis asked me to make an implementation proposal,
                > but it's been sitting on the back burner. Partly, I'm not sure what
                > kind of user interface would be best.

                Yeah, I thought we'd discussed that, and then forgotten it again :)

                > > I thought those were good ideas. I'm not sure how to do them in
                > > Cheetah. We could set default variables, maybe like $loop.index,
                > > $loop.even, etc. We could do something like:
                > >
                > > #for $a in $b loop $c
                > > $c.index
                > > #end for
                >
                > I was thinking of some kind of object, like
                > #for $o in $batch($sequenceObject, size=5, page=2)
                > (If sequenceObject contains subscripts [0..30], this batch would
                > be [5..9].)
                >
                > I hadn't thought of using a separate object for the metadata.
                > I was thinking of the metadata being available as methods, with
                > an option to insert them as attributes into the target element.
                > Of course, with autocalling now, the concept of leaving them as
                > methods isn't as bad as it was.

                I think batching is a little different than this, though it could be
                something as simple as:

                #for $o, $loop in $batch($sequence)
                #if $loop.even
                etc...

                Or just for metadata, you could do something as simple as:

                def metaZipper(s):
                newS = []
                i = 0
                for o in s:
                i = i + 1
                newS.append((o, {"index": i, "odd": i%2, "even": (i+1)%2,
                "first": i == 1, "last": i == len(s)}))
                return newS

                Then you can do:

                #for $o, $loop in $metaZipper($sequence)
                $loop.index: $o
                #end for

                (with a better name than metaZipper)

                Anyway, that's pretty darn easy to do with the current syntax. It
                makes me think this really doesn't need to be a builtin Cheetah
                feature, though potentially this function could be available by
                default.

                > Zope also has some features I'm not sure how to implement.
                > For instance, the metadata allows you to build URLs that point
                > to the same page but with different starting/ending subscripts.
                > But that assumes an entire Zope framework with special handling
                > of those CGI parameters. For Cheetah/Webware, we'd have to
                > provide that part of the structure somehow.

                Yeah, it'll be a little more complicated, and definitely tied to
                Webware. It's really a servlet-wide issue, not something that can be
                encapsulated in one loop (at least the link-creation part). That's
                part of what always confused me about DTML batching -- to really
                understand how it worked I felt I'd have to do a lot of experimenting
                (what happens if you have two batches on the same page, for instance).

                An aspect of it can be encapsulated without Webware. Implementing
                that should be quite easy, the interface is more important -- it
                should be easily extensible (probably be subclassing) for the more
                complete implementation. If it was going to be really cool, it should
                include (or allow extensions to include) table generation, sorting,
                etc.

                Ian

                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Mike Orr
                ... Cheetah.Tools is an excellent place for standalone classes/functions that enhance the Cheetah experience, but can also be taken up independently. It s our
                Message 7 of 17 , Oct 23, 2001
                • 0 Attachment
                  On Tue, Oct 23, 2001 at 02:58:38PM -0500, Ian Bicking wrote:
                  > Anyway, that's pretty darn easy to do with the current syntax. It
                  > makes me think this really doesn't need to be a builtin Cheetah
                  > feature, though potentially this function could be available by
                  > default.

                  Cheetah.Tools is an excellent place for standalone classes/functions
                  that enhance the Cheetah experience, but can also be taken up
                  independently. It's our sandbox, our bag o'tricks. Then later we
                  can create an independent library out of some of them if we want.

                  --
                  -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                  http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

                  _______________________________________________
                  Cheetahtemplate-discuss mailing list
                  Cheetahtemplate-discuss@...
                  https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                • Chuck Esterbrook
                  ... As long as I don t *have* to provide the index variable. I think it s strange to require one when I don t want or need it. That starts to feel like
                  Message 8 of 17 , Oct 23, 2001
                  • 0 Attachment
                    At 11:00 AM 10/23/2001 -0700, Mike Orr wrote:
                    >How about:
                    > #repeat $i EXPR
                    >
                    >Then the question is whether to be zero-based or one-based. One-based
                    >would be more convenient for many applications, but it would be
                    >inconsistent with Python and other Cheetah usage.

                    As long as I don't *have* to provide the index variable. I think it's
                    strange to require one when I don't want or need it. That starts to feel
                    like traditional programming again.

                    I'm also wondering if there is a more readable syntax like:

                    #repeat $x times in $i
                    blah
                    #end repeat

                    Or something.

                    -Chuck


                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  • Chuck Esterbrook
                    ... What about: #repeat #until EXPR Which is like the Pascal statement by the same name and do {} while() in C. The point here isn t syntactic sure to get rid
                    Message 9 of 17 , Oct 23, 2001
                    • 0 Attachment
                      At 12:01 PM 10/23/2001 -0700, Mike Orr wrote:
                      > > #until fits in too.
                      >
                      >OK. #until =
                      > #while not (EXPR)

                      What about:

                      #repeat
                      #until EXPR


                      Which is like the Pascal statement by the same name and do {} while() in C.
                      The point here isn't syntactic sure to get rid of a "not", but instead not
                      to test an expression that doesn't logically need testing until the after
                      the first iteration of the loop.

                      Some tout C's do...while over Pascal's repeat...until because you don't
                      have to negate the boolean condition when switching your loop from pre-test
                      to post-test or vice versa. I certainly agree. That would give us:

                      #do
                      blah
                      #while EXPR

                      But then how do you know when a #while is ending a #do vs starting a new
                      #while loop? I never figured out how C knew, but it always did. And I
                      certainly appreciate the idea of having the post-test loop in addition to
                      the pre-test.


                      -Chuck


                      _______________________________________________
                      Cheetahtemplate-discuss mailing list
                      Cheetahtemplate-discuss@...
                      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                    • Ian Bicking
                      ... I think there s also an issue of symmetry -- do...while is symmetric with the normal while, but while isn t symmetric with repeat...until. #do ... #repeat
                      Message 10 of 17 , Oct 23, 2001
                      • 0 Attachment
                        Chuck Esterbrook <ChuckEsterbrook@...> wrote:
                        > At 12:01 PM 10/23/2001 -0700, Mike Orr wrote:
                        > > > #until fits in too.
                        > >
                        > >OK. #until =
                        > > #while not (EXPR)
                        >
                        > What about:
                        >
                        > #repeat
                        > #until EXPR
                        >
                        >
                        > Which is like the Pascal statement by the same name and do {} while() in C.
                        > The point here isn't syntactic sure to get rid of a "not", but instead not
                        > to test an expression that doesn't logically need testing until the after
                        > the first iteration of the loop.

                        I think there's also an issue of symmetry -- do...while is symmetric
                        with the normal while, but while isn't symmetric with repeat...until.

                        #do
                        ...
                        #repeat while EXPR

                        It's unambiguous, reads reasonably well, and allows symmetry with
                        #while and potentially #until. It's a little odd that it is
                        substantially different from a normal #repeat, while using the same
                        directive. There must be another alternative out there too.

                        > But then how do you know when a #while is ending a #do vs starting a new
                        > #while loop? I never figured out how C knew, but it always did. And I
                        > certainly appreciate the idea of having the post-test loop in addition to
                        > the pre-test.

                        Well:

                        #do
                        ...
                        #while EXPR

                        in C is:

                        do {
                        ...
                        } while (EXPR);

                        But the other alternative is:

                        #do
                        #while EXPR1
                        ...
                        #end while
                        #while EXPR2

                        in C is:

                        do {
                        while (EXPR1) {
                        ...
                        }
                        } while (EXPR2);

                        In #do...#while, #while is equivalent to "}" in C (which isn't
                        ambiguous there).

                        Ian

                        _______________________________________________
                        Cheetahtemplate-discuss mailing list
                        Cheetahtemplate-discuss@...
                        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                      • Mike Orr
                        ... Too wordy. If we can have a variable number of comma-separated attributes: #repeat $n = no counter variable #repeat $i, $n = counter variable $i
                        Message 11 of 17 , Oct 23, 2001
                        • 0 Attachment
                          On Tue, Oct 23, 2001 at 01:16:20PM -0700, Chuck Esterbrook wrote:
                          > #repeat $x times in $i
                          > blah
                          > #end repeat

                          Too wordy.

                          If we can have a variable number of comma-separated attributes:
                          #repeat $n => no counter variable
                          #repeat $i, $n => counter variable $i

                          If we can't do that, maybe we should just live without the
                          counter variable, and have #repeat be an obscure feature that just
                          saves typing rather than allowing printed index numbers inside the
                          loop.

                          Regarding "#do ... #while" and variants, I almost suggested them,
                          but then decided Python's strategy is better: use
                          "#if ... #break ... #end if" inside the loop, which is more
                          flexible.

                          (Then I realized Tavis was right to add #break to the language, and I
                          was wrong to oppose it. :)

                          --
                          -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                          http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

                          _______________________________________________
                          Cheetahtemplate-discuss mailing list
                          Cheetahtemplate-discuss@...
                          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                        • Chuck Esterbrook
                          ... Great, then we can axe #for as well. ;-) Everything can be done with #while. All other loops, including #for, are conveniences. But then I like my
                          Message 12 of 17 , Oct 23, 2001
                          • 0 Attachment
                            At 01:42 PM 10/23/2001 -0700, Mike Orr wrote:
                            >Regarding "#do ... #while" and variants, I almost suggested them,
                            >but then decided Python's strategy is better: use
                            >"#if ... #break ... #end if" inside the loop, which is more
                            >flexible.

                            Great, then we can axe #for as well. ;-)

                            Everything can be done with #while. All other loops, including #for, are
                            conveniences.

                            But then I like my conveniences.


                            -Chuck


                            _______________________________________________
                            Cheetahtemplate-discuss mailing list
                            Cheetahtemplate-discuss@...
                            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                          • Mike Orr
                            ... We also have the precedent of Python, which has for and while but not do . Also, #for offers a major benefit over #while for for-loops. #do...#while
                            Message 13 of 17 , Oct 23, 2001
                            • 0 Attachment
                              On Tue, Oct 23, 2001 at 02:29:41PM -0700, Chuck Esterbrook wrote:
                              > At 01:42 PM 10/23/2001 -0700, Mike Orr wrote:
                              > >Regarding "#do ... #while" and variants, I almost suggested them,
                              > >but then decided Python's strategy is better: use
                              > >"#if ... #break ... #end if" inside the loop, which is more
                              > >flexible.
                              >
                              > Great, then we can axe #for as well. ;-)
                              >
                              > Everything can be done with #while. All other loops, including #for, are
                              > conveniences.
                              >
                              > But then I like my conveniences.

                              We also have the precedent of Python, which has 'for' and 'while' but
                              not 'do'.

                              Also, #for offers a major benefit over #while for for-loops.
                              #do...#while offers only a marginal benefit over #while...#break.

                              #repeat offers a marginal benefit, but it's very clean and
                              self-contained.

                              #do offers a marginal benefit, but it requires #while to be two
                              different directives depending on context, and violates the
                              "#DIRECTIVE...#end DIRECTIVE" tradition.

                              --
                              -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
                              http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

                              _______________________________________________
                              Cheetahtemplate-discuss mailing list
                              Cheetahtemplate-discuss@...
                              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                            Your message has been successfully submitted and would be delivered to recipients shortly.