write graph to dot in NetworkX:
nx.write_dot(G,'graph.dot')
than convert to svg (png doesn't work, don't know why)
dot -Tsvg graph.dot > graph.svg
tips (Software, Unix, Linux as desktop ...)
write graph to dot in NetworkX:
nx.write_dot(G,'graph.dot')
than convert to svg (png doesn't work, don't know why)
dot -Tsvg graph.dot > graph.svg
Posted by
Roman G.
at
1:25 AM
0
comments
Labels: Python
$ret .= "<node ID=\"Perl_GEN".$id."\" TEXT=\"".$listp."\" />\n";
<map version="0.9.0_Beta_8">and closing of the tag.
$al = [1, [2, [3], 4], 5];
I have already mentioned in my post on comparing numbers and strings in shell, about problems of simultaneous use of different programming languages.
To conclude, having reference cards with description one language to another differences can be useful.
Listed is set of resources, intended for migration from one language to another.
Recommended (short,self-descriptive, useful):
languages comparison:
http://merd.sourceforge.net/pixel/language-study/syntax-across-languages/
Recommended, but not short:
Wikipedia page:
http://en.wikipedia.org/wiki/Comparison_of_programming_languages
Open directory listing for comparisons:
http://www.dmoz.org/Computers/Programming/Languages/Comparison_and_Review/
PLEAC - Programming Language Examples Alike Cookbook
Comparison of productivity of writing in different programming languages:
page.mi.fu-berlin.de/~prechelt/Biblio/jccpprtTR.pdf
Useful:
Java for c++ Programmers:
http://pages.cs.wisc.edu/~hasti/cs368/JavaTutorial/
http://triton.towson.edu/~mzimand/os/Lect2-java-tutorial.html
Lisp to javascript converter, descriptive.
http://javascript.crockford.com/little.html
Another one Lisp to Javascript converter written in javascript.( You can look into source to look into the code)
http://www.joeganley.com/code/jslisp.html
Comparison Python with Java, Lisp i.t.c.
http://wiki.python.org/moin/LanguageComparisons
Three scripting concurrents:
http://mjtsai.com/blog/2002/11/25/perl_vs_python_vs_ruby/
Accumulator generator in different languages:
http://www.paulgraham.com/accgen.html
Tcl vs. Python, with nice short examples
http://homepages.cwi.nl/~sjoerd/PythonVsTcl-old.html
This thread describes differences between bash and perl.
http://www.perlmonks.org/?node_id=661859
And at the end resource with language comparison in action (memory, speed, size).
http://shootout.alioth.debian.org/
Posted by
Roman G.
at
8:40 PM
0
comments
Labels: C, C++, java, javascript, Language comparison, Lisp, perl, Python, Tcl
It is no nested lists in Perl. However, Python and Lisp have this ability.
Description of implementing in Perl equivalent structure to nested Python and Lisp lists given.
Used:
$ python --version
Python 2.5.1
$ perl -v | head -2
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
$ clisp --version | head -1
GNU CLISP 2.41 (2006-10-13) (built 3371977993) (memory 3401903509)
'(1 (2 (3) 4) 5)lisp list as the example of data structure we work with:
$ clisp
...
[1]> (setq alist `(1 (2 (3) 4) 5))
(1 (2 (3) 4) 5)
[2]> (elt alist 0)
1
[3]> (elt alist 2)
5
[4]> (elt alist 1)
(2 (3) 4)
[5]>
>>> a = [1, [2, [3], 4], 5]
>>> print a
[1, [2, [3], 4], 5]
>>> print a[0]
1
>>> print a[1]
[2, [3], 4]
>>> print a[2]
5
$ perl -e '@al = (1, (2, (3), 4), 5); \
print "\@al[0]=@al[0] , \@al[1]=@al[1] , \@al[2]=@al[2] ,\
\@al[3]=@al[3] , \@al[4]=@al[4] \n"; \
print @al; print "\n"; '
@al[0]=1 , @al[1]=2 , @al[2]=3 , @al[3]=4 , @al[4]=5
12345
$al = [1, [2, [3], 4], 5];
sub slistp($)
{
my ($listp) = @_;
my $i;
my $ret = "";
if (ref($listp) eq 'ARRAY')
{
$ret = "[";
$ret .= slistp(@$listp[0]);
for ($i=1;$i<(scalar @$listp);$i++)
{
$ret .= ",";
$ret .= slistp(@$listp[$i]);
};
$ret .= "]";
}
else
{
$ret .= $listp;
}
return($ret);
}
$al = [1, [2, [3], 4], 5];
print "\@al[0]=".@$al[0].", \@al[1]=@$al[1] , \@al[2]=@$al[2] \n";
print slistp($al);
print "\n";
print "\@al[0]=".slistp(@$al[0])."\n\@al[1]=".slistp(@$al[1]);
print "\n\@al[2]=".slistp(@$al[2])."\n";
$ perl nestlist.pl
@al[0]=1, @al[1]=ARRAY(0x8152b44) , @al[2]=5
[1,[2,[3],4],5]
@al[0]=1
@al[1]=[2,[3],4]
@al[2]=5
Posted by
Roman G.
at
3:31 PM
0
comments
Labels: Common Lisp, Language comparison, perl, Python
Done: Working version of program for python expressions parsing.
Source is available on my page.
Below is example of how it works, and tree generated/presented.
Good explanation of python's slowness.
Marked blue - is input in terminal
------------------%<-------------------------------
./parse_python.py
2 + 2
[257, [266, [267, [268, [269, [326, [303, [304, [305, [306, [307, [309, [310, [311, [312, [313, [314, [315, [316, [317, [2, '2']]]]], [14, '+'], [314, [315, [316, [317, [2, '2']]]]]]]]]]]]]]]]]], [4, '']]], [0, '']]
['symbol=file_input', ['symbol=stmt', ['symbol=simple_stmt', ['symbol=small_stmt', ['symbol=expr_stmt', ['symbol=testlist', ['symbol=test', ['symbol=or_test', ['symbol=and_test', ['symbol=not_test', ['symbol=comparison', ['symbol=expr', ['symbol=xor_expr', ['symbol=and_expr', ['symbol=shift_expr', ['symbol=arith_expr', ['symbol=term', ['symbol=factor', ['symbol=power', ['symbol=atom', ['token=NUMBER', 'value=2']]]]], ['token=PLUS', 'value=+'], ['symbol=term', ['symbol=factor', ['symbol=power', ['symbol=atom', ['token=NUMBER', 'value=2']]]]]]]]]]]]]]]]]], ['token=NEWLINE', 'value=']]], ['token=ENDMARKER', 'value=']]
------------------>%-------------------------------
Posted by
Roman G.
at
2:39 PM
0
comments
Labels: Python
Just joke :)
I know, it is not enough statistics for conclusions :)
We have compared reduce statement in Common lisp and python with one fellow.
I wrote in Common lisp, he in Python.
Resulting "code" sizes for same construct, just translated from one language to another:
$ echo "reduce(lambda x,y: (x,y,x), (1,2,3,4))" | wc
1 4 39
$ echo "(reduce (lambda(x y)(list x y x)) (list 1 2 3 4))" | wc
1 11 50
Python : 39 symbols long
Common Lisp : 50 symbols.
Posted by
Roman G.
at
7:04 PM
0
comments
Labels: Common Lisp, Language comparison, Python