Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69502

Re: unicode as valid naming symbols

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'static': 0.04; 'tree': 0.05; 'debugging': 0.07; 'element': 0.07; 'see.': 0.07; 'string': 0.09; 'counting': 0.09; 'lst': 0.09; 'lst)': 0.09; 'main()': 0.09; 'newline': 0.09; 'separating': 0.09; 'translator': 0.09; 'cc:addr :python-list': 0.11; 'assume': 0.14; 'already,': 0.16; 'attempt.': 0.16; 'braces,': 0.16; 'exclamation': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'non-trivial': 0.16; 'notation': 0.16; 'pairs': 0.16; 'pairs,': 0.16; 'programmer,': 0.16; 'semicolon': 0.16; 'subject:unicode': 0.16; 'unfair': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'version.': 0.19; 'written': 0.21; 'code,': 0.22; 'input': 0.22; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'alternate': 0.24; 'char': 0.24; 'lets': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'that.': 0.31; 'anonymous': 0.31; 'another.': 0.31; 'assumes': 0.31; 'easy,': 0.31; 'piece': 0.31; 'trivial': 0.31; 'txt': 0.31; 'void': 0.31; 'anyone': 0.31; 'figure': 0.32; 'supposed': 0.32; 'interface': 0.32; 'another': 0.32; 'agree': 0.35; 'display': 0.35; 'knows': 0.35; 'something': 0.35; 'case,': 0.35; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'doubt': 0.36; 'scheme': 0.36; 'doing': 0.36; "i'll": 0.36; 'example,': 0.37; 'bringing': 0.38; 'fact': 0.38; 'pm,': 0.38; 'little': 0.38; 'short': 0.38; 'explain': 0.39; 'aside': 0.39; 'structure': 0.39; 'how': 0.40; 'ian': 0.60; 'course': 0.61; "you'll": 0.62; "you've": 0.63; 'more': 0.64; 'total': 0.65; 'here': 0.66; 'line,': 0.68; 'lose': 0.68; 'cut': 0.74; '(let': 0.84; 'can:': 0.84; 'client-side': 0.84; 'score:': 0.84; 'ratio': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=pyQPNvmu06lVgBtf0xB0QlImS94eiSA3xi7yo2/ZCCM=; b=c+ZVGc5GCpEDgod/Ka7rtq7OpqCRPF81SE6yQ2hPDC4e9AnAF9EzujsVIcpcC9pC8L 4kfOZd1s013Ie2fMi4whvBLId2jXc6UM/xgGHKKBuCA6kNrJWV29bY71IbRV6lJtatfo XfLm2cp5U4c5jtac0yMZq6MhY96xC01u2/Ed64R88NQfmkWhxyJvny9zOdu7EG8+o63H iP7ljVXDaJOdflYeQ8wfJiF6Nph+fxVojQUP9FmXfQop/6iS+eURv5WZn1GIpmyGUdyG Hl6ikvz2lW3Bmg5wJkcnKl2JZCAI6ytf4Y/HTcrDpEQf9/pI4pkTRVX6siDcvpxhyhc0 uOLQ==
MIME-Version 1.0
X-Received by 10.66.129.133 with SMTP id nw5mr30261814pab.98.1396348747105; Tue, 01 Apr 2014 03:39:07 -0700 (PDT)
In-Reply-To <CALwzidkr8Def8-dgKU-qfbcc+7ueX8xSA5a8M7x2Sif7P81mOQ@mail.gmail.com>
References <lgsi07$k1p$1@speranza.aioe.org> <mailman.8531.1395775491.18130.python-list@python.org> <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <lh1g3h$meg$1@speranza.aioe.org> <CALwzidk+4diadosJ0bDFTj-OjU9ib712iPMBVxvqZfxAsY2cJg@mail.gmail.com> <53393BA4.2080305@rece.vub.ac.be> <CALwzidkWc+jQtyN7-nFd4wZCryqLNfNc2okVL_kSbCBkE6nuQQ@mail.gmail.com> <5339C281.7080300@rece.vub.ac.be> <CALwzidkTRYbpeBCY7gxSXa=ZNimaAe69mGbT0d9sbehHfHgvOw@mail.gmail.com> <533A768F.5080102@rece.vub.ac.be> <mailman.8790.1396344274.18130.python-list@python.org> <87txadtmwq.fsf@elektro.pacujo.net> <CALwzidkr8Def8-dgKU-qfbcc+7ueX8xSA5a8M7x2Sif7P81mOQ@mail.gmail.com>
Date Tue, 1 Apr 2014 21:39:06 +1100
Subject Re: unicode as valid naming symbols
From Chris Angelico <rosuav@gmail.com>
Cc Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8793.1396348750.18130.python-list@python.org> (permalink)
Lines 95
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396348750 news.xs4all.nl 2910 [2001:888:2000:d::a6]:54854
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69502

Show key headers only | View raw


On Tue, Apr 1, 2014 at 8:58 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> Setting aside the fact that C doesn't have anonymous functions, I'll
> approximate it as best I can:
>
> static int n = 3;
>
> int f()
> {
>     return n;
> }
>
> int main()
> {
>     n = 7;
>     return f();
> }
>
> C: 10
> Scheme: 20

And the less trivial the example, the more difference you'll see. This
is Scheme inside LilyPond, a little translator that lets me input
lyrics in a tidy way that can then be turned into something that works
well with both MIDI Karaoke and printed score:

#(define (bang2slashn lst) (
    cond ((null? lst) 0)
    (else (begin
        (if (equal? (ly:music-property (car lst) 'name) 'LyricEvent)
(let ((txt (ly:music-property (car lst) 'text)))
            (if (equal? (string-ref txt 0) #\!) (begin
            ; Debugging display
            ; (display (ly:music-property (car lst) 'name)) (display "
- ") (display txt) (newline)
            ; Prepend a newline instead of the exclamation mark -
works for both MIDI Karaoke and page layout
            (ly:music-set-property! (car lst) 'text (string-append
"\n" (substring txt 1 (string-length txt))))
        ))))
        (bang2slashn (ly:music-property (car lst) 'elements))
        (bang2slashn (cdr lst))
    ))
))
% Call the above recursive function
lyr=#(define-music-function (parser location lyrics) (ly:music?)
    (bang2slashn (ly:music-property lyrics 'elements))
    lyrics
)

Now, this was written by a non-Scheme programmer, so it's not going to
be optimal code, but I doubt it's going to lose a huge number of
parentheses. Not counting the commented-out debugging line, that's 41
pairs of them in a short but non-trivial piece of code. Translating it
to C isn't easy, in the same way that it's hard to explain how to do
client-side web form validation in Lua; but here's an attempt. It
assumes a broadly C-like structure to LilyPond (eg that the elements
are passed as a structure; they are a tree already, as you can see by
the double-recursive function above), which is of course not the case,
but here goes:

void bang2slashn(struct element *lst)
{
    while (lst)
    {
        if (!strcmp(lst->name, "LyricEvent"))
        {
            char *text = music_property(lst, "text");
            /* Okay, C doesn't have string manipulation, so I cheat here */
            /* If this were C++ or Pike, some notation nearer to the
original would work */
            if (*text == '!') music_set_property(lst, "text", "\n" + text[1..]);
        }
        bang2slashn(lst->elements);
        lst = lst->next;
    }
}

DEFINE_MUSIC_FUNCTION(PARSER_LOCATION_LYRICS, bang2slashn);


That's nine pair parens, three braces, and one square. I assume a lot
about the supposed C-like interface to LilyPond, but I think anyone
who knows both C and Scheme would agree that I haven't been
horrendously unfair in the translation. (Though I will accept an
alternate implementation of the Scheme version. If you can cut it down
to just 26 pair parens, you'll achieve the 2:1 ratio that Ian
mentioned. And if you can cut it down to 13 pairs, you've equalled my
count.) The only way to have the C figure come up approximately equal
is to count a semicolon as if it were a pair of parens - Scheme has an
extra set of parens doing the job of separating one function call from
another. But that adds only another 5, bringing C up to a total of 18
(plus a few more if I used functions to do my string manipulation, so
let's say about 20-25) where Scheme is still at roughly twice that.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-25 13:30 -0500
  Re: unicode as valid naming symbols wxjmfauth@gmail.com - 2014-03-25 11:52 -0700
    Re: unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-25 14:24 -0500
    Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-25 19:16 -0700
  Re: unicode as valid naming symbols MRAB <python@mrabarnett.plus.com> - 2014-03-25 19:24 +0000
    Re: unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-25 14:29 -0500
      Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-03-25 21:48 +0200
        Re: unicode as valid naming symbols Skip Montanaro <skip@pobox.com> - 2014-03-25 14:54 -0500
        Re: unicode as valid naming symbols Cameron Simpson <cs@zip.com.au> - 2014-03-26 09:16 +1100
      Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-25 13:49 -0600
      Re: unicode as valid naming symbols Tim Chase <python.list@tim.thechases.com> - 2014-03-25 15:29 -0500
      Re: unicode as valid naming symbols Ethan Furman <ethan@stoneleaf.us> - 2014-03-25 15:47 -0700
      Re: unicode as valid naming symbols Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-25 23:58 +0000
        Re: unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-27 10:28 -0500
          Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-27 08:51 -0700
            Re: unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-27 11:03 -0500
              Re: unicode as valid naming symbols Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-28 12:45 +1300
            Re: unicode as valid naming symbols MRAB <python@mrabarnett.plus.com> - 2014-03-27 17:17 +0000
              Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-27 10:53 -0700
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-27 10:22 -0600
            Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-27 10:41 -0700
          Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-03-28 03:23 +1100
          Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-31 11:55 +0200
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-31 11:40 -0600
          Re: unicode as valid naming symbols Tim Chase <python.list@tim.thechases.com> - 2014-03-31 13:02 -0500
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-31 12:10 -0600
          Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-31 21:31 +0200
          Re: unicode as valid naming symbols Terry Reedy <tjreedy@udel.edu> - 2014-03-31 16:12 -0400
          Re: unicode as valid naming symbols Terry Reedy <tjreedy@udel.edu> - 2014-03-31 16:15 -0400
            Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-03-31 23:34 +0300
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-31 18:47 -0600
          Re: unicode as valid naming symbols David Hutto <dwightdhutto@gmail.com> - 2014-03-31 23:58 -0400
          Re: unicode as valid naming symbols David Hutto <dwightdhutto@gmail.com> - 2014-04-01 00:11 -0400
          Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-04-01 10:19 +0200
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 03:18 -0600
            Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-04-01 12:32 +0300
              Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 03:58 -0600
                Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-04-01 15:02 +0300
                Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-01 23:54 +1100
                Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-04-01 16:16 +0300
                Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-02 00:32 +1100
                Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-04-01 18:59 +0300
                Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-04-01 19:58 -0700
                Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-04-01 20:16 -0700
                Re: unicode as valid naming symbols Marko Rauhamaa <marko@pacujo.net> - 2014-04-02 08:55 +0300
              Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-01 21:39 +1100
          Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-04-01 12:37 +0200
          Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-01 21:58 +1100
          Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-04-01 13:59 +0200
            Re: unicode as valid naming symbols Roy Smith <roy@panix.com> - 2014-04-01 08:29 -0400
              Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-02 00:08 +1100
                Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-04-01 06:34 -0700
          Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-02 00:00 +1100
          Re: unicode as valid naming symbols Ned Batchelder <ned@nedbatchelder.com> - 2014-04-01 09:33 -0400
          Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-04-02 00:44 +1100
            Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-04-01 06:58 -0700
          Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 09:53 -0600
      Re: unicode as valid naming symbols MRAB <python@mrabarnett.plus.com> - 2014-03-26 02:56 +0000
      Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-03-26 14:09 +1100
      Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-26 09:25 +0100
      Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-26 09:52 +0100
      Re: unicode as valid naming symbols Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-26 10:37 -0600
      Re: unicode as valid naming symbols Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-27 10:36 +0100
        Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-27 08:10 -0700
          Re: unicode as valid naming symbols Tim Chase <python.list@tim.thechases.com> - 2014-03-27 10:34 -0500
          Re: unicode as valid naming symbols random832@fastmail.us - 2014-03-28 14:55 -0400
            Re: unicode as valid naming symbols Rustom Mody <rustompmody@gmail.com> - 2014-03-28 22:00 -0700
              Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-03-29 16:12 +1100
              Re: unicode as valid naming symbols Ben Finney <ben+python@benfinney.id.au> - 2014-03-29 16:32 +1100
              Re: unicode as valid naming symbols Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-03-29 14:11 -0400
              Re: unicode as valid naming symbols Chris Angelico <rosuav@gmail.com> - 2014-03-30 09:01 +1100
                Re: unicode as valid naming symbols Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-30 19:16 +1300
    Re: unicode as valid naming symbols Mark H Harris <harrismh777@gmail.com> - 2014-03-25 14:29 -0500
  Re:unicode as valid naming symbols Dave Angel <davea@davea.name> - 2014-03-25 15:45 -0400
  Re: unicode as valid naming symbols Terry Reedy <tjreedy@udel.edu> - 2014-03-25 22:26 -0400

csiph-web