Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Calling J from Python

Reply
Thread Tools

Calling J from Python

 
 
Tina I
Guest
Posts: n/a
 
      02-08-2007
Gosi wrote:
> On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch <(E-Mail Removed)> wrote:
>> In <(E-Mail Removed). 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
>

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

 
Reply With Quote
 
 
 
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      02-08-2007
"Tina I" <(E-Mail Removed)> wrote:


Gosi wrote:
> On Feb 7, 3:46 pm, Marc 'BlackJack' Rintsch <(E-Mail Removed)> wrote:
>> In <(E-Mail Removed). 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
>

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


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

- Hendrik


 
Reply With Quote
 
 
 
 
Robin Becker
Guest
Posts: n/a
 
      02-08-2007
Tina I wrote:
.......
> It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway


In German it's bright
--
Robin Becker

 
Reply With Quote
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      02-08-2007
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.


On Feb 6, 2:05 am, "Gosi" <(E-Mail Removed)> wrote:
> On Feb 6, 3:04 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
> > On Feb 5, 8:48 am, "Gosi" <(E-Mail Removed)> wrote:

>
> > > It is quite easy to call J from Python

>
> > >http://groups.google.com/group/J-Pro...ead/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-pro...jsoftware.com/



 
Reply With Quote
 
Gosi
Guest
Posts: n/a
 
      02-08-2007
On Feb 8, 12:00 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> 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.
>
> On Feb 6, 2:05 am, "Gosi" <(E-Mail Removed)> wrote:
>
> > On Feb 6, 3:04 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:

>
> > > On Feb 5, 8:48 am, "Gosi" <(E-Mail Removed)> wrote:

>
> > > > It is quite easy to call J from Python

>
> > > >http://groups.google.com/group/J-Pro...ead/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-pro...jsoftware.com/


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

 
Reply With Quote
 
Tina I
Guest
Posts: n/a
 
      02-09-2007
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")

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      02-09-2007
On Thu, 8 Feb 2007 10:55:17 +0200, "Hendrik van Rooyen"
<(E-Mail Removed)> 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
--
Wulfraed Dennis Lee Bieber KD6MOG
http://www.velocityreviews.com/forums/(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
Ant
Guest
Posts: n/a
 
      02-09-2007
On Feb 6, 12:21 am, greg <(E-Mail Removed)> 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.


 
Reply With Quote
 
Alexander Schmolck
Guest
Posts: n/a
 
      02-09-2007
[restoring context]
"Ant" <(E-Mail Removed)> writes:
> > On Feb 6, 12:21 am, greg <(E-Mail Removed)> wrote:
> >
> > Alexander Schmolck wrote:
> > > For example I once wrote this (slow) code to display
> > > part of a mandelbrot fractal:
> > > load'viewmat'
> > > viewmat+/2&>((j.~/~(%~i99)&+@:*^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
 
Reply With Quote
 
Martin =?iso-8859-1?Q?L=FCthi?=
Guest
Posts: n/a
 
      02-09-2007
Alexander

Alexander Schmolck <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ calling java calling c++ ... Klaus Friese C++ 7 08-15-2005 09:23 PM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= ASP .Net 1 09-28-2004 12:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM



Advertisments