Calling J from Python

Discussion in 'Python' started by hg, Feb 5, 2007.

  1. hg

    hg Guest

    Bjoern Schliessmann wrote:

    > Gosi wrote:
    >
    >> J is in many ways similar to Python.

    >
    > The only one I see at the moment is that they're both some kind of
    > programming languages.
    >
    >> J has very many advanced operations.

    >
    > Sure.
    >
    > Mh, just looking at some "advanced" J source taken from
    > wikipedia.org makes me feel sick:
    >
    > | Here's a J program to calculate the average of a list of numbers:
    > | avg=: +/ % #
    > | avg 1 2 3 4
    > | 2.5
    >
    > In the meantime, do you now have an answer to why we should care?
    >
    > Regards,
    >
    >
    > Björn
    >
    > --
    > BOFH excuse #314:
    >
    > You need to upgrade your VESA local bus to a MasterCard local bus.



    Be nice !
     
    hg, Feb 5, 2007
    #1
    1. Advertising

  2. hg

    Gosi Guest

    Gosi, Feb 5, 2007
    #2
    1. Advertising

  3. Diez B. Roggisch, Feb 5, 2007
    #3
  4. hg

    Gosi Guest

    Gosi, Feb 5, 2007
    #4
  5. Gosi wrote:

    > J is in many ways similar to Python.


    The only one I see at the moment is that they're both some kind of
    programming languages.

    > J has very many advanced operations.


    Sure.

    Mh, just looking at some "advanced" J source taken from
    wikipedia.org makes me feel sick:

    | Here's a J program to calculate the average of a list of numbers:
    | avg=: +/ % #
    | avg 1 2 3 4
    | 2.5

    In the meantime, do you now have an answer to why we should care?

    Regards,


    Björn

    --
    BOFH excuse #314:

    You need to upgrade your VESA local bus to a MasterCard local bus.
     
    Bjoern Schliessmann, Feb 5, 2007
    #5
  6. hg

    Guest

    Gosi> J is in many ways similar to Python.

    Gosi> J has very many advanced operations.

    Gosi> http://www.jsoftware.com/

    Doesn't look like open source of any variety. If a person uses Python with
    various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
    to a closed source product?

    Skip
     
    , Feb 5, 2007
    #6
  7. Gosi wrote:

    > On Feb 5, 2:59 pm, "Diez B. Roggisch" <> wrote:
    >> Gosi wrote:
    >> > It is quite easy to call J from Python

    >>
    >> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
    >>
    >> What is J, and why should we care?
    >>
    >> Diez

    >
    > J is in many ways similar to Python.
    >
    > J has very many advanced operations.


    What exactly do you call "similar to python" when the following is a program
    written in it? Compared to that, even Perl is a wonder of readability...

    m =: >@(0&{)
    v =: >@(1&{)
    h =: >@(2&{)
    qu =: >@(3&{)
    z =: i.@0:
    ret =: |.@}:
    init =: z;z;z;i.
    f1m =: (m,{.@qu);v;h;}.@qu
    f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
    f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
    f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
    perm =: qu @ f12h @ init
    ord =: *./ @ (#&>"_) @ C.
    days =: -: @ ord @ perm


    http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem


    Diez
     
    Diez B. Roggisch, Feb 5, 2007
    #7
  8. On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
    <> declaimed the following
    in comp.lang.python:

    > Mh, just looking at some "advanced" J source taken from
    > wikipedia.org makes me feel sick:
    >
    > | Here's a J program to calculate the average of a list of numbers:
    > | avg=: +/ % #
    > | avg 1 2 3 4
    > | 2.5
    >

    That looks like some variation of APL
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Feb 5, 2007
    #8
  9. On Feb 5, 12:23 pm, "Diez B. Roggisch" <> wrote:

    > Gosi wrote:
    > > On Feb 5, 2:59 pm, "Diez B. Roggisch" <> wrote:
    > >> Gosi wrote:
    > >> > It is quite easy to call J from Python

    >
    > >>http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...

    >
    > >> What is J, and why should we care?

    >
    > >> Diez

    >
    > > J is in many ways similar to Python.

    >
    > > J has very many advanced operations.

    >
    > What exactly do you call "similar to python" when the following is a program
    > written in it? Compared to that, even Perl is a wonder of readability...
    >
    > (cryptic gibberish snipped)
    >
    > http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem
    >
    > Diez


    Please avoid posting code looking like garbled profanities in c.l.py.
    This was outright offensive.

    George
     
    George Sakkis, Feb 5, 2007
    #9
  10. On Mon, 05 Feb 2007 18:23:46 +0100, "Diez B. Roggisch"
    <> declaimed the following in comp.lang.python:

    >
    > What exactly do you call "similar to python" when the following is a program
    > written in it? Compared to that, even Perl is a wonder of readability...
    >
    > m =: >@(0&{)
    > v =: >@(1&{)
    > h =: >@(2&{)
    > qu =: >@(3&{)
    > z =: i.@0:
    > ret =: |.@}:
    > init =: z;z;z;i.
    > f1m =: (m,{.@qu);v;h;}.@qu
    > f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
    > f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
    > f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
    > perm =: qu @ f12h @ init
    > ord =: *./ @ (#&>"_) @ C.
    > days =: -: @ ord @ perm
    >

    I retract my APL comment... APL is clean compared to that...

    Are there /any/ keywords in that language? Apparently {, } are
    operators and delimiter pairs.
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Feb 5, 2007
    #10
  11. writes:

    > Gosi> J is in many ways similar to Python.
    >
    > Gosi> J has very many advanced operations.
    >
    > Gosi> http://www.jsoftware.com/
    >
    > Doesn't look like open source of any variety. If a person uses Python with
    > various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
    > to a closed source product?


    You wouldn't, if for nothing else because python has far better scientific
    libraries. If you've got an interest in programming languages as such J (or
    some other APL) is worth a look though; it's also handy for quick mathematical
    experimentation (J's array primitives are more expressive than what numpy
    offers and python doesn't support rationals, so it's not just concise due to
    perl-style crypticness). For example I once wrote this (slow) code to display
    part of a mandelbrot fractal:

    load'viewmat'
    viewmat+/2&>:|((j.~/~(%~i:)99)&+@:*:)^:(i.32)0

    It'll likely require you more typing in python, but then you'd need to do such
    things quite a lot for seeing an amortization in terms of less time spent with
    your PC; I think most people will find they need a seizable learning
    investment to get anywhere with J and python already is very expressive for
    the kind of things J is good at.

    'as
     
    Alexander Schmolck, Feb 5, 2007
    #11
  12. hg

    Larry Bates Guest

    Bjoern Schliessmann wrote:
    > Gosi wrote:
    >
    >> J is in many ways similar to Python.

    >
    > The only one I see at the moment is that they're both some kind of
    > programming languages.
    >
    >> J has very many advanced operations.

    >
    > Sure.
    >
    > Mh, just looking at some "advanced" J source taken from
    > wikipedia.org makes me feel sick:
    >
    > | Here's a J program to calculate the average of a list of numbers:
    > | avg=: +/ % #
    > | avg 1 2 3 4
    > | 2.5
    >
    > In the meantime, do you now have an answer to why we should care?
    >
    > Regards,
    >
    >
    > Björn
    >

    And why is that superior to this:

    def avg(l):
    return float(sum(l))/len(l)

    >>>avg([1,2,3,4])

    2.5


    Which can actually be read and debugged in the future!

    -Larry
     
    Larry Bates, Feb 5, 2007
    #12
  13. hg

    Robin Becker Guest

    Dennis Lee Bieber wrote:
    > On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
    > <> declaimed the following
    > in comp.lang.python:
    >
    >> Mh, just looking at some "advanced" J source taken from
    >> wikipedia.org makes me feel sick:
    >>
    >> | Here's a J program to calculate the average of a list of numbers:
    >> | avg=: +/ % #
    >> | avg 1 2 3 4
    >> | 2.5
    >>

    > That looks like some variation of APL


    my colleague informs me that it is indeed associated with some of the same
    people if not with Mr Iverson.
    --
    Robin Becker
     
    Robin Becker, Feb 5, 2007
    #13
  14. Robin Becker <> writes:

    > Dennis Lee Bieber wrote:
    > > On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
    > > <> declaimed the following
    > > in comp.lang.python:
    > >

    >
    > >> Mh, just looking at some "advanced" J source taken from
    > >> wikipedia.org makes me feel sick:
    > >>
    > >> | Here's a J program to calculate the average of a list of numbers:
    > >> | avg=: +/ % #
    > >> | avg 1 2 3 4
    > >> | 2.5
    > >>

    > > That looks like some variation of APL

    >
    > my colleague informs me that it is indeed associated with some of the same
    > people if not with Mr Iverson.


    The late Ken Iverson designed both J and APL (he has also written an number of
    freely downloadable math books using J, see jsoftware.com).

    'as
     
    Alexander Schmolck, Feb 5, 2007
    #14
  15. Larry Bates <> writes:

    > And why is that superior to this:
    >
    > def avg(l):
    > return float(sum(l))/len(l)
    >
    > >>>avg([1,2,3,4])

    > 2.5


    Apart from being less to type and it is superior in that it's generalizes much
    better, e.g:

    avg&.^. NB. geomtric mean
    avg&.% NB. harmonic mean
    avg M NB. column mean of matrix M
    avg"1 M NB. row mean of matrix M

    'as
     
    Alexander Schmolck, Feb 5, 2007
    #15
  16. Diez B. Roggisch wrote:

    > m =: >@(0&{)
    > v =: >@(1&{)
    > h =: >@(2&{)
    > qu =: >@(3&{)
    > z =: i.@0:
    > ret =: |.@}:
    > init =: z;z;z;i.
    > f1m =: (m,{.@qu);v;h;}.@qu
    > f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
    > f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
    > f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
    > perm =: qu @ f12h @ init
    > ord =: *./ @ (#&>"_) @ C.
    > days =: -: @ ord @ perm
    >
    >
    > http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem
    >
    >
    > Diez


    Why dont they call it "smiley" ?

    Operators: :) :) :eek:) :-$ *<¦:O) XD -_- +_+ ^_^ *_* !_!
    >_< =_= o_o X_X -_o ;) $_$ <_< >_> o_0
    ><_>< ?_? '_' O.O $.$ T.T ._. u.u >-<" =] {-_-}



    (source: http://en.wikipedia.org/wiki/Smiley )
     
    Laurent Pointal, Feb 5, 2007
    #16
  17. Alexander Schmolck wrote:

    > Apart from being less to type


    Cool. Less to type.

    > and it is superior in that it's
    > generalizes much better, e.g:
    >
    > avg&.^. NB. geomtric mean
    > avg&.% NB. harmonic mean
    > avg M NB. column mean of matrix M
    > avg"1 M NB. row mean of matrix M


    Is there any regularity in this? If it is, it's not obvious at all.

    Regards,


    Björn

    --
    BOFH excuse #78:

    Yes, yes, its called a design limitation
     
    Bjoern Schliessmann, Feb 5, 2007
    #17
  18. hg

    Stef Mientki Guest

    >
    > Mh, just looking at some "advanced" J source taken from
    > wikipedia.org makes me feel sick:
    >
    > | Here's a J program to calculate the average of a list of numbers:
    > | avg=: +/ % #
    > | avg 1 2 3 4
    > | 2.5
    >

    And here is the Python way of calculating the average
    >>> mean([1,2,3,4])

    2.5

    sorry, I don't see any advantage.

    cheers,
    Stef Mientki
     
    Stef Mientki, Feb 5, 2007
    #18
  19. Bjoern Schliessmann <> writes:

    > Alexander Schmolck wrote:
    >
    > > Apart from being less to type

    >
    > Cool. Less to type.


    Yes. Readability is more important in many context, but for something designed
    for interactive experimentation and exploration little typing is absolutely
    essential. Would you use a calculator that would require Java-style
    boilerplate to add two numbers?

    I'd also venture that readability and typing ease are typically closely
    positively correlated (compare python to C++) and although I would not claim
    that J is particularly readable I'm also not an expert user (I doubt I would
    even then, but I'm sure it *does* make a difference).

    > > and it is superior in that it's
    > > generalizes much better, e.g:
    > >
    > > avg&.^. NB. geomtric mean
    > > avg&.% NB. harmonic mean
    > > avg M NB. column mean of matrix M
    > > avg"1 M NB. row mean of matrix M

    >
    > Is there any regularity in this? If it is, it's not obvious at all.


    Sure. ``f&.g`` is like ``(f o g) o g^-1`` in common mathemetical notation.
    ``^.`` is log and ``%`` is inversion/division. Making ``&.`` (it's called
    "under") available as a convenient abstraction is IMO one really useful
    innovation of J.

    As for the remaing two: it's similar to numpy in that one and the same
    function can normally operate on arrays of different dimensions (including
    scalars). In numpy you'd also write stuff like ``mean(M, axis=1)``, it's not
    exactly the same, although the axis abstraction comes from APL (another cool
    idea), J introduces a slightly different approach. The ``"1`` means "operate
    on cells of rank 1" (i.e. vectors), rather than "operate along a certain
    axis". For dyadic (2-argument) functions you can also specify different left
    and right rank, so you could write the outerproduct v'w thus: ``v *"0 1 w``
    (multiply each 0-cell (i.e scalar) of v with each 1-cell (i.e. vector, there
    is only one) of w). Unlike the linear algebra notation this readily
    generalizes to more than 1 dimensional objects.

    BTW I don't think J is an ideal language, not even for numerical computing --
    there are plenty of things I'd do differently and that includes measures that
    would IMO greatly aid readability (like getting rid of "ambivalence"[1]). But
    I have little doubt that, no matter what its flaws may be, APL (and J is
    really just an updated, ASCII-based APL) is one of the most innovative and
    important programming languages ever conceived. Anyone interested in the
    design of programming language for scientific computing ought to take a look
    at at least a look at it or one of its descendants.

    'as

    Footnotes:
    [1] Basically almost every J function has a completely different meaning
    depending on whether you use it as a unary or binary function (just as
    conventionally "-" is abusively used for both substraction and negation).
     
    Alexander Schmolck, Feb 5, 2007
    #19
  20. hg

    John Salerno Guest

    Alexander Schmolck wrote:

    > Would you use a calculator that would require Java-style
    > boilerplate to add two numbers?


    This isn't a Java newsgroup, so your metaphor is irrelevant. People use
    Python because it *isn't* Java and does not succumb to the problem you
    seem to be accusing it of.
     
    John Salerno, Feb 5, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    4
    Views:
    4,016
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  2. =?Utf-8?B?TWFydGluIExlZQ==?=

    Calling FormsAuthentication.SignOut() after calling Response.Flush

    =?Utf-8?B?TWFydGluIExlZQ==?=, Sep 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    736
    =?Utf-8?B?RXRoZW0gQXp1bg==?=
    Sep 28, 2004
  3. Andreas Lagemann
    Replies:
    8
    Views:
    503
    Mike Wahler
    Jan 10, 2005
  4. tiwy
    Replies:
    0
    Views:
    454
  5. Klaus Friese

    c++ calling java calling c++ ...

    Klaus Friese, Aug 12, 2005, in forum: C++
    Replies:
    7
    Views:
    590
    Roland Pibinger
    Aug 15, 2005
Loading...

Share This Page