Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling J from Python

22 views
Skip to first unread message

Gosi

unread,
Feb 5, 2007, 9:48:49 AM2/5/07
to

Diez B. Roggisch

unread,
Feb 5, 2007, 9:59:12 AM2/5/07
to
Gosi wrote:

What is J, and why should we care?

Diez

Gosi

unread,
Feb 5, 2007, 11:27:32 AM2/5/07
to
On Feb 5, 2:59 pm, "Diez B. Roggisch" <d...@nospam.web.de> 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.

http://www.jsoftware.com/

Bjoern Schliessmann

unread,
Feb 5, 2007, 11:52:27 AM2/5/07
to
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.

hg

unread,
Feb 5, 2007, 5:02:50 AM2/5/07
to
Bjoern Schliessmann wrote:


Be nice !

sk...@pobox.com

unread,
Feb 5, 2007, 12:03:24 PM2/5/07
to Gosi, pytho...@python.org

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

Diez B. Roggisch

unread,
Feb 5, 2007, 12:23:46 PM2/5/07
to
Gosi wrote:

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,{:@m);h;qu,ret@m) @ (f1m^:5)
f1h =: (z;z;(h,{:@v);(qu,ret@v)) @ (f5m^:12)
f12h =: (z;z;z;qu,ret@h,{:@h) @ (f1h^:12)
perm =: qu @ f12h @ init
ord =: *./ @ (#&>"_) @ C.
days =: -: @ ord @ perm


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


Diez

Message has been deleted

George Sakkis

unread,
Feb 5, 2007, 12:36:59 PM2/5/07
to
On Feb 5, 12:23 pm, "Diez B. Roggisch" <d...@nospam.web.de> wrote:

> Gosi wrote:
> > On Feb 5, 2:59 pm, "Diez B. Roggisch" <d...@nospam.web.de> 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

Message has been deleted

Alexander Schmolck

unread,
Feb 5, 2007, 12:47:54 PM2/5/07
to
sk...@pobox.com writes:

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

Larry Bates

unread,
Feb 5, 2007, 12:51:54 PM2/5/07
to
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

Robin Becker

unread,
Feb 5, 2007, 1:04:14 PM2/5/07
to pytho...@python.org
Dennis Lee Bieber wrote:
> On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
> <usenet-mail-03...@spamgourmet.com> 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

Alexander Schmolck

unread,
Feb 5, 2007, 1:13:15 PM2/5/07
to
Robin Becker <ro...@reportlab.com> writes:

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

unread,
Feb 5, 2007, 1:17:31 PM2/5/07
to
Larry Bates <larry...@websafe.com> 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

Laurent Pointal

unread,
Feb 5, 2007, 1:38:04 PM2/5/07
to
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,{:@m);h;qu,ret@m) @ (f1m^:5)
> f1h =: (z;z;(h,{:@v);(qu,ret@v)) @ (f5m^:12)
> f12h =: (z;z;z;qu,ret@h,{:@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: :-) :) :o) :-$ *<¦:O) XD -_- +_+ ^_^ *_* !_!
>_< =_= o_o X_X -_o ;) $_$ <_< >_> o_0
><_>< ?_? '_' O.O $.$ T.T ._. u.u >-<" =] {-_-}


(source: http://en.wikipedia.org/wiki/Smiley )


Bjoern Schliessmann

unread,
Feb 5, 2007, 1:41:40 PM2/5/07
to
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

Stef Mientki

unread,
Feb 5, 2007, 2:08:54 PM2/5/07
to
>
> 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

Bruno Desthuilliers

unread,
Feb 5, 2007, 3:18:49 PM2/5/07
to
Gosi a écrit :
Our policy on source for our binaries is between the extremes of
Microsoft proprietary source and Linux open source. You can have the
benefits of open source for J binaries, but under a license and a fee.
"""

Good bye J.

Bruno Desthuilliers

unread,
Feb 5, 2007, 3:19:40 PM2/5/07
to
Gosi a écrit :

> On Feb 5, 2:59 pm, "Diez B. Roggisch" <d...@nospam.web.de> 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.

So are Javascript and Ruby.

> J has very many advanced operations.

what's an "advanced operation" ?

Bruno Desthuilliers

unread,
Feb 5, 2007, 3:22:07 PM2/5/07
to
Larry Bates a écrit :

>
> def avg(l):
> return float(sum(l))/len(l)
>
>
>>>>avg([1,2,3,4])
>
> 2.5

def avg(*args):
return float(sum(args)) / len(args))

>
> Which can actually be read and debugged in the future!

in_my_arms(tm)

Bruno Desthuilliers

unread,
Feb 5, 2007, 3:25:10 PM2/5/07
to
Alexander Schmolck a écrit :

Would my beloved wife's life depend on it, I just couldn't say what all
this garbage is supposed to mean. If that's supposed to be "superior",
I'm quite happy with my inferior favorite languages...

Bruno Desthuilliers

unread,
Feb 5, 2007, 3:27:23 PM2/5/07
to
Diez B. Roggisch a écrit :

Yuck. I'd rather program in b**k.

Alexander Schmolck

unread,
Feb 5, 2007, 3:00:35 PM2/5/07
to
Bjoern Schliessmann <usenet-mail-03...@spamgourmet.com> 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).

John Salerno

unread,
Feb 5, 2007, 3:04:44 PM2/5/07
to
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.

Laurent Pointal

unread,
Feb 5, 2007, 3:25:40 PM2/5/07
to
Bruno Desthuilliers wrote:

An operation which dont stay in place.

Bruno Desthuilliers

unread,
Feb 5, 2007, 4:54:20 PM2/5/07
to
Alexander Schmolck a écrit :

> Bjoern Schliessmann <usenet-mail-03...@spamgourmet.com> 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?

No, thanks. But hopefully we have Python :

Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on
linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 + 4
7
>>>

!-)

Bruno Desthuilliers

unread,
Feb 5, 2007, 4:56:24 PM2/5/07
to
Laurent Pointal a écrit :

You meant something like a good camembert ?-)

Alexander Schmolck

unread,
Feb 5, 2007, 4:55:39 PM2/5/07
to
Bruno Desthuilliers <bdesth.qu...@free.quelquepart.fr> writes:

> No, thanks. But hopefully we have Python :
>
> Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
> [GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2
>
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 3 + 4
> 7
> >>>

My calculuator even gives a pretty good answer if I divide them (without
importing anything from the __future__).

'as

greg

unread,
Feb 5, 2007, 7:21:41 PM2/5/07
to
Alexander Schmolck wrote:
> 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,

Yes, but with Python you wouldn't have to spend a
couple of weeks sitting and thinking before starting
to type that line...

--
Greg

Eric_...@msn.com

unread,
Feb 5, 2007, 10:04:57 PM2/5/07
to
On Feb 5, 8:48 am, "Gosi" <gos...@gmail.com> wrote:
> It is quite easy to call J from Python
>
> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...

There are a couple of issue that should be adressed. Am I going to
jail if I write a program and then redistribute all the files required
to run the program I write?? The second is how do I use the j stuff
without learning all that much about j. I am just intrested in
stealing graphics libraries and using what I have already written in
python..

Paddy

unread,
Feb 5, 2007, 11:55:17 PM2/5/07
to
On Feb 5, 2:48 pm, "Gosi" <gos...@gmail.com> wrote:
> It is quite easy to call J from Python
>
> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...

Hii Gosi,
>From reading what has gone before, you seem to have got it in the neck
from some pythonistas.
I'd just like to say from some but not all.

It is *A GOOD THING* that Python has bridges to other languages. Some
may not care to program in the other language - which is a separate
concer;. but a link between the language - be it Haskell or befunge or
J, makes Python better in my view. If your expert J programmers have
need for something that is hard to do in J they might now be more
likely to use Python.

We should remember that Python is a great glue language too, and links
to other languages and tools is how we maintain that position.

- Paddy.

Message has been deleted

Gosi

unread,
Feb 6, 2007, 3:05:17 AM2/6/07
to
On Feb 6, 3:04 am, "Eric_Dex...@msn.com" <Eric_Dex...@msn.com> wrote:
> On Feb 5, 8:48 am, "Gosi" <gos...@gmail.com> wrote:
>
> > It is quite easy to call J from Python
>
> >http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
>
> There are a couple of issue that should be adressed. Am I going to
> jail if I write a program and then redistribute all the files required
> to run the program I write??

J is free for anyone to download and use.

If someone is interested in putting you in jail it will not because
you distribute J or redistribute the J utilities.

> The second is how do I use the j stuff
> without learning all that much about j.

Just like Python then how much time you spend is uo to you.

If you want to be good at it you may have to spend some time.

You may also be just a casual user and dip into it now and again.

There are lots of Demos, Labs and Help files besides all the
utilities.

You can freely use the utilities and examples to create your own
application.

You can write code in conventional style and not spend any time on the
advanced functionality.


> I am just intrested in
> stealing graphics libraries and using what I have already written in
> python..

There are a number of graphics examples, utilities and demos you can
use in J and combine it with Python.

The new grid classes in J are amazingly useful too.

I am just starting to learn Python and I find it interesting to
combine it with J.
I know a few people who are doing so successfully.

There are always some nicetise in any language that can be beneficial.
Combining them enhances both.

http://groups.google.com/group/j-programming
http://jsoftware.com/

Gerard Flanagan

unread,
Feb 6, 2007, 4:57:49 AM2/6/07
to
On Feb 5, 3:48 pm, "Gosi" <gos...@gmail.com> wrote:
> It is quite easy to call J from Python
>
> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...

As I understand it, the k language, which is similar to J, is used to
interact with streamed realtime financial data, where I imagine the
terseness of the language may make sense. I messed about with J for a
day or two, and found it interesting and in a way natural (given some
Higher Math background once upon a time).

Here's a link to a company who it looks like could value some
knowledge of J/K/APL type languages: http://www.kx.com/news/in-the-
news.php

All the best

Gerard

Bruno Desthuilliers

unread,
Feb 6, 2007, 1:46:34 PM2/6/07
to
Gosi a écrit :

> On Feb 6, 3:04 am, "Eric_Dex...@msn.com" <Eric_Dex...@msn.com> wrote:
>
>>On Feb 5, 8:48 am, "Gosi" <gos...@gmail.com> wrote:
>>
>>
>>>It is quite easy to call J from Python
>>
>>>http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
>>
>>There are a couple of issue that should be adressed. Am I going to
>>jail if I write a program and then redistribute all the files required
>>to run the program I write??
>
>
> J is free for anyone to download and use.

But not to inspect or modify. This is "free" as in "free beer", not as
in "free speech".

>
>>The second is how do I use the j stuff
>>without learning all that much about j.
>
>
> Just like Python then how much time you spend is uo to you.
>
> If you want to be good at it you may have to spend some time.
>
> You may also be just a casual user and dip into it now and again.

This is easy with Python, which emphasis readability. I doubt one can
say the same about j.

bearoph...@lycos.com

unread,
Feb 6, 2007, 4:08:23 PM2/6/07
to
Gosi:

> There are a number of graphics examples, utilities and demos you can
> use in J and combine it with Python.

Some of those graphic examples are very nice, I have seen a big site
filled with complex fractals, chaotic attractors, etc.
Python Zen seems somewhat opposed to part of the J spirit, that's why
it's not easy to advertise J in this newsgroup. Python is open source,
and it values readability, it belives that it's better to write more
and be more readable/debuggable, than to be able to express many
things with few symbols. APL was an interesting language, powerful
too, and J looks more keyboard-friendly and it's probably better for
other things too. K seems even less readable than J to me. Probably J
has to be compared more to scipy than to Python itself, because they
share some purposes, the vector/matrix processing. If you need to do
lot of array processing the syntax of scipy (with the help of
MatPlotLib too, that's partially copied from MatLab) isn't (may be
not) high-level enough, the system isn't able to simplify things by
itself, etc. So in that situation a more functional language may be
fitter (maybe even F#, but probably there are better languages around
for that purpose, some modern ones coming from ML family).

Bye,
bearophile

Gosi

unread,
Feb 7, 2007, 10:25:35 AM2/7/07
to

Ken Iverson created APL and it ran first time on a computer 1966.
Ken Iverson then corrected several things and made it so different
that he could no longer use the name and the results was J around
1990.

J can be very short and effective.

I like to use J for many things and I think that combining Python and
J is a hell of a good mixture.

Marc 'BlackJack' Rintsch

unread,
Feb 7, 2007, 10:46:24 AM2/7/07
to

> I like to use J for many things and I think that combining Python and
> J is a hell of a good mixture.

I was able to follow this sentence up to and including the word "hell"… :-)

Ciao,
Marc 'BlackJack' Rintsch

Gosi

unread,
Feb 7, 2007, 1:59:42 PM2/7/07
to
On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net> wrote:

> In <1170861935.779969.52...@v33g2000cwv.googlegroups.com>, Gosi wrote:
> > I like to use J for many things and I think that combining Python and
> > J is a hell of a good mixture.
>
> I was able to follow this sentence up to and including the word "hell"... :-)
>
> Ciao,
> Marc 'BlackJack' Rintsch


That is a start.

"Hell" is also what most example start with as in "Hello something"
Hell in northern countries is very cold.
Hell in middle east is very hot.
I do not know which is your Hell hot or cold.
Hell o veröld

Tina I

unread,
Feb 8, 2007, 2:53:16 AM2/8/07
to
It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway
:D

Robin Becker

unread,
Feb 8, 2007, 5:07:56 AM2/8/07
to pytho...@python.org
Tina I wrote:
......

> It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway

In German it's bright
--
Robin Becker

Eric_...@msn.com

unread,
Feb 8, 2007, 7:00:26 AM2/8/07
to
I may have mistook the source code licence for the use licence.. I
will look into a little further to see what it can do.. Looks like
you are not allowed to redistribute k for profit. Some day I will
look up letters a random in the search engine to see what I come up
with.

Gosi

unread,
Feb 8, 2007, 12:55:31 PM2/8/07
to

You can get older versions of the source code too for free.
The utility sources are also free.

Hendrik van Rooyen

unread,
Feb 8, 2007, 3:55:17 AM2/8/07
to pytho...@python.org
"Tina I" <tin...@bestemselv.com> wrote:

I am under the impression that Loki had a daughter called Hel ...

- Hendrik


Tina I

unread,
Feb 9, 2007, 1:01:57 AM2/9/07
to
Hendrik van Rooyen wrote:
>
> I am under the impression that Loki had a daughter called Hel ...
>
> - Hendrik
>
Yes. And Hel was the queen of the underworld which was also called 'Hel'
(Which of course is 'hell', in modern Norwegian : "helvete")

Message has been deleted

Ant

unread,
Feb 9, 2007, 5:29:53 AM2/9/07
to
On Feb 6, 12:21 am, greg <g...@cosc.canterbury.ac.nz> wrote:
...

> Yes, but with Python you wouldn't have to spend a
> couple of weeks sitting and thinking before starting
> to type that line...

This is a good point often overlooked. You often get these threads on
c.l.python about "How can I do this in one line", usually with some
example of how it is done in only 13 characters in Perl. Yes you may
spend less time typing - but unless you are a true expert in (J, Perl,
other terse language) the time you spend actually working out how to
type it, and in debugging it far outweighs the time you'd spend on all
of that typing in a clean but more verbose language such as Python.


Alexander Schmolck

unread,
Feb 9, 2007, 11:28:55 AM2/9/07
to
[restoring context]

"Ant" <ant...@gmail.com> writes:
> > On Feb 6, 12:21 am, greg <g...@cosc.canterbury.ac.nz> wrote:
> >
> > Alexander Schmolck wrote:
> > > 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,
> >
> > Yes, but with Python you wouldn't have to spend a
> > couple of weeks sitting and thinking before starting
> > to type that line...

(it's actually reasonably straightforward, if someone really cares I might
post a translation)

>
> This is a good point often overlooked.

There is of course some truth in Greg's statement -- J code will likely have a
higher thought/character ratio (even after adjusting for differences in
average token-length) -- but I don't think that is in itself terribly
interesting.

What is in my opinion of interest is how much of the additional thought you
need to put in in order to achieve higher terseness is spent

a) on more pentrating insight on the problem as such, encouraged by the
mind-set and abstractions associated with a language (let's call this
expressiveness)

and how much of it is spent

b) on perl-golf style geek masturbation that focuses on recalling and
exploiting the language's various behavioral oddities that are only of
coincidental or low-level relevance to the problem (let's call this
golf-syndrome)

I'm not claiming that the boundaries between the two are always unambigious,
but I think the distinction is pretty important when discussing pros and cons
of differences in terseness between languages.

Apart from scaling better, one reason that a), expressiveness, is much more
interesting than b), golf-syndrome, is that it translates to some extent even
to writing code in other languages as it enriches the programmer's reservoir
of metaphors and abstractions. Typically this also has a beneficial effect
for coding even in languages that offer no direct support for these
abstractions (I bet a programmer with, say extensive python, J and prolog
experience and just a little bit of C background is in many cases likely to
come up with a superior C solutions to challenging problems than someone who's
got the same amount of experience in C only).

Therefore...

> You often get these threads on c.l.python about "How can I do this in one
> line", usually with some example of how it is done in only 13 characters in
> Perl. Yes you may spend less time typing - but unless you are a true expert
> in (J, Perl, other terse language) the time you spend actually working out
> how to type it, and in debugging it far outweighs the time you'd spend on
> all of that typing in a clean but more verbose language such as Python.

... I also don't think your pairing of J and Perl is particularly helpful. As
long as no one can point me to some resonable examples demonstrating otherwise
I flattly deny that Perl is more concise than python in an *interesting* way,
i.e. by encouraging or enabling a)

(BTW "not interesting" != "not practically relevant"; harking back to my
previous posts, typing effort *does matter* in some contexts, such as
command-line one-liners; IMO the only thing perl is useful for.)

J, on the other hand, whilst also suffering somewhat from golf-syndrome, does
in my opinion also enable a)-style terseness. Let me give an example:

Before reading further, how would you code a program that gives the following
output ('skewed' sierpinski-triangle) in python? I'll give some remarkably
concise and IMO lucid J code and a python translation below.


*
**
* *
****
* *
** **
* * * *
********
* *
** **
* * * *
**** ****
* * * *
** ** ** **
* * * * * * * *
****************


SPOILERS AHEAD

J solution
----------

I can think of two nice ways in J, 13 and 16 characters long respectively and
each expressing something essential and non-trival about the problem in a way
that would be more cumbersome in python.

Here's the first one:

(,,.~)^:4,'*' NB. due to Cliff Reiter, slightly adapted


Possible Python translation
---------------------------

Here's a python transiteration attempt:

# ^: , ~ ,.
print rep(hook(vertcat, self(horzcat)),4)('*')

or slightly more idiomatic:

def sierpinski(x):
return vertcat(x,horzcat(x,x))

print rep(sierpinsky,4)('*')

With:

def identity(x): return x
def rep(f,n): # f^:n
if n < 0: return lambda *args: rep(inverse(f),-n)(*args)
elif n == 0: return identity
else: return lambda *args: rep(f,n-1)(f(*args))
# horzcat and vertcat are only string-based special purpose mockups for this
# problem since python doesn't have arrays
def horzcat(a,b): # a,.b
return "\n".join(a_i+b_i for (a_i,b_i) in zip(a.split('\n'),
b.split('\n')))
def vertcat(a,b): # a,b
# fill "rows" of b up with spaces if a's rows are longer and vice versa
dif = len(a.split('\n')[0]) - len(b.split('\n')[0])
if dif < 0:
a = a.replace('\n', ' '*-dif + '\n') + ' '*-dif
elif dif > 0:
b = b.replace('\n', ' '*dif + '\n') + ' '*dif
return a + '\n' + b
def self(f): # f~
return lambda x: f(x,x)
def hook(f,g): # (f g)
return lambda x: f(x,g(x))
print rep(hook(vertcat, self(horzcat)),4)('*')

I find above J solution is quite neat conceptually because it directly
captures the self-similarity.

The other J solution is

' *'{~2|!~/~i.*:2^4

Can you figure out how it works? (Hint: k!n = choose(k,n), 2|x = x%2)

'as

Martin Lüthi

unread,
Feb 9, 2007, 6:24:32 PM2/9/07
to
Alexander

Alexander Schmolck <a.sch...@gmail.com> writes:
> I can think of two nice ways in J, 13 and 16 characters long respectively and
> each expressing something essential and non-trival about the problem in a way
> that would be more cumbersome in python.
>
> Here's the first one:
>
> (,,.~)^:4,'*' NB. due to Cliff Reiter, slightly adapted

Well, not as interesting as your solution, but definitively less mind-boggling
and much more flexible/extendible

====================================================
l = [True]
pr = {True: '*', False: ' '}

for k in range(15):
print ''.join([pr[x] for x in l])
l = [True] + [l[i+1]^l[i] for i in range(len(l)-1)] + [True]
====================================================

more elegant solutions sought!

tnoo

bearoph...@lycos.com

unread,
Feb 9, 2007, 9:20:36 PM2/9/07
to
ant:

> and in debugging it far outweighs the time you'd spend on all
> of that typing in a clean but more verbose language such as Python.

Typing time counts a bit too. A language like Java is even more
verbose than Python, and that probably slows down the actual
programming, compared to less verbose languages. I think there is some
verbosity sweet spot between J and Java, and for me that's called
Python ;-)


Martin Lüthi:
> more elegant solutions sought!

This is a bit simpler, but probably there are simpler solutions using
modular arithmetic:

l = [1]
for _ in range(15):
print ''.join(" *"[x] for x in l)
l = [1] + [l[i+1]^l[i] for i in range(len(l)-1)] + [1]


Bye,
bearophile

George Sakkis

unread,
Feb 9, 2007, 11:31:28 PM2/9/07
to

Here's another one, adapted from the example (in Java) in Wikipedia's
entry (http://en.wikipedia.org/wiki/Sierpinski_triangle):

N=15
for x in xrange(N,0,-1):
print ''.join('* '[x&y!=0] for y in xrange(N+1-x))


George

Hendrik van Rooyen

unread,
Feb 10, 2007, 12:12:53 AM2/10/07
to pytho...@python.org
"Dennis Lee Bieber" <wlf...@ix.netcom.com> wrote:

> On Thu, 8 Feb 2007 10:55:17 +0200, "Hendrik van Rooyen"
> <ma...@microcorp.co.za> declaimed the following in comp.lang.python:


>
> > I am under the impression that Loki had a daughter called Hel ...
> >

> One of his few "normal" offspring... After all, Loki also was
> Sleipnir's* /mother/! And probably related to Fenrir (aka, the Fenris
> Wolf) as well.
>
>
> * Odin's eight-legged horse

We should both be more careful - using the past tense like that is
disrespectful, and there are no guarantees that the Norse gods are dead.

Vindictive lot, they were.. ....uuhhh are, I mean.

- Hendrik

greg

unread,
Feb 10, 2007, 4:23:14 AM2/10/07
to
Alexander Schmolck wrote:
> how would you code a program that gives the following
> output ('skewed' sierpinski-triangle) in python?
>
>
> *
> **
> * *
> ****
> * *
> ** **
> * * * *
> ********
> * *
> ** **
> * * * *
> **** ****
> * * * *
> ** ** ** **
> * * * * * * * *
> ****************

###############################################################

def print_sierpinski(order):
size = 4 * 2 ** order
buffer = [size * [" "] for i in range(size)]
put_sierpinski(buffer, size, 0, 0)
for line in buffer:
print "".join(line)

def put_sierpinski(buffer, size, x, y):
if size == 4:
put_triangle(buffer, size, x, y)
else:
size2 = size / 2
put_sierpinski(buffer, size2, x, y)
put_sierpinski(buffer, size2, x, y + size2)
put_sierpinski(buffer, size2, x + size2, y + size2)

def put_triangle(buffer, size, x, y):
for i in range(3):
buffer[y + i][x] = buffer[y + i][x + i] = "*"
for i in range(4):
buffer[y + 3][x + i] = "*"

print_sierpinski(2)

###############################################################

By making the recursion explicit, I think this brings out the
self-similarity better than any of the other solutions posted,
which are very clever but not what I would call "lucid".

--
Greg

Nick Craig-Wood

unread,
Feb 10, 2007, 5:30:11 AM2/10/07
to

This is my solution after a few minutes thought.

It uses a different algorithm for generating the triangle. If python
could output binary numbers it would be more elegant...

>>> n = 1
>>> for i in range(16):
... print ("%X" % n).replace('0', ' ').replace('1', '*')
... n = n ^ (n << 4)
...

*
**
* *
****
* *
** **
* * * *
********
* *
** **
* * * *
**** ****
* * * *
** ** ** **
* * * * * * * *
****************


--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick

gos...@gmail.com

unread,
Mar 9, 2013, 1:49:22 PM3/9/13
to
Den måndagen den 5:e februari 2007 kl. 14:48:49 UTC skrev Gosi:
> It is quite easy to call J from Python
>
> http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e

http://www.jsoftware.com/jwiki/Scripts/qjide

Mark Lawrence

unread,
Mar 9, 2013, 2:34:09 PM3/9/13
to pytho...@python.org
Got a right slagging six years ago when first posted, what's changed to
make it worth evaluating?

--
Cheers.

Mark Lawrence

gos...@gmail.com

unread,
Mar 10, 2013, 4:30:26 AM3/10/13
to pytho...@python.org
A lot has changed these last six years.

By the way Python 2.5 and Python 3.3 will not work with the example.

Python 2.7 does not work in Vista unchanged (neither does Python 3.3) but after change will run the demo and some examples.

J is now open source and has more platforms and guis.

gos...@gmail.com

unread,
Mar 10, 2013, 4:30:26 AM3/10/13
to comp.lan...@googlegroups.com, pytho...@python.org
Den lördagen den 9:e mars 2013 kl. 19:34:09 UTC skrev Mark Lawrence:
0 new messages