[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Perl Moral Support



Michael "MORONS!" Schwern writes:
> On Fri, Mar 17, 2000 at 07:58:34PM +0000, Adam Sampson wrote:
> > This is starting to sound like an increasingly interesting idea to me, so
> > I'll have a look into implementing it. "import perl" and "use python;" sound
> > very nice indeed.
> 
> Well, Python uses SWIG... you should be able to embed a perl
> interpretor into Python via SWIG relatively easily.  Somebody has to
> have already done this.  I'm sure Python has an equally "simple"
> embedding library that could be used with XS (or SWIG even).

I've been reading the embedding and extending docs for Python.  Even
without SWIG, writing a minimal Python extension is not hard.  Here's
my first:

begin 664 judith.tar.gz
M'XL(`(VTT3@``^U66V_3,!3N:_,K#IE$DRYT:7J3-A`:`L$D!M.X/2"83.*N
M'JE=;&>C0OWO'-OI96+37C;0A+^'QC[7+^<<QSVK"J8G.XV[1)KVL]%H@,^T
M.QJDF\\E&NDH'?9[O2Q+1XVTVQT.TP8,[I15C4II(@$:WR4YI?QZNYOT]Q1G
MKO_N,15%5=).?LLYTFZ:#H?]Z_J?]7J]9?^Q\3@GW?X@ZS<@O64>5^(_[_].
M&PB,*PXET[JD<#37$\&!_M24*X:K]DX0;#&>EU5!(73JSB0,`JR;9CDZO/UV
M1G,-[<`-T<E/(966C)^J:*U4M!PG&\9$GJHX^!4T\PF6O^T<NLERE>TM-:+2
M3H02QC64E*,9_F8)H`X7"3#4K4/+<W@";SZ\?KT7H,L8H@='\WUY>G)$I*+O
MJUE)(Y,]@5!MJ:U=Q[JS9ATF$#01#U>D'KJDM2!S@BR.`?DW)=65Y'7"YB)H
M.E;((3)N\-B2C>&II0Z[=HN6UM!%1-LI*4N11\YWNQL;[M@;+C3H"84?%<N_
M4Z7A@LQ!"R@$,)W`M\JI%9OB:Z$:N]4<"PD1PYCI'C!X\*0N$VZVMQWE5>+/
M[`O:U>]I-E_K388;^S:6Q0'DA+<TC!DO;#["U065RC#!K3+\,#N.BP+&K44A
M<KL.FM"&%HY3"Y!6B\Q8"\923)>#UNT,.MFNM7J$3E2AXN19Q<KB(RDK"KF8
MS6'%-S%!K!73D$M*-'*I*=L8`,)-02ZX)HR;XA*0=$PEY3DUA)E^6J?#V3!4
M2Z(UE0E,Q`6HB:C*`E_8ML.$7^5V7@>M*1"EJJF)O%D*(O%X&%9BQJ@*45[8
MO6%K:C>U6=#7ABF%(:9@+BHL!Z7(JA,:#?;/SN^E*D0XJ6%RJ0RVI79*4,3S
MV3S:T(:?CM^^>1ENF#5-DK5)O#H:\OSJ*0Z6$GF^%RPV3OLAQ;X5S^D8ZN,^
MM0+UV4P21OH57CI)?WP3$CA\\?[5R<?]X_WCE^\6"7J8I(E-O0@6R.Q<L`)G
MAVGG',5@/A21$<=8EP/4'-J;*@J=Q3I/328VG/_UI_5>H+[_WV&S9W>5XX;[
M/TU[H]7]WQ^9_W\9[OS]_S?05GC+TF)Y></E/X+^#'EX>'AX>'AX>'AX>'AX
8>'AX>'AX>'AX>'AXW"?\!H-X74<`*```
`
end

(instructions: 
ln -s /usr/lib/python1.5-or-whatever/config/Makefile.pre.in .
make -f Makefile.pre.in boot; make; 
python -c 'import judith; print judith.xorstrings("PPPP", "4516")'
)

For some reason, writing Perl extensions appears to require that I
learn a third language called XS, run code-generators to generate files
full of boilerplate stuff that I later edit, etc.  So the result is not
directly comparable.  I'd be most obliged if somebody could show me how
to translate the above into a Perl extension.

In a slightly more "fun" vein, consider this paragraph from perlxs.pod:
       Note: For many extensions, Dave Beazley's SWIG system
       provides a significantly more convenient mechanism for
       creating the XS glue code. See the section on
       /www.cs.utah.edu/~beazley/SWIG in the http: manpage for
       more information.

Embedding Python is apparently a bit more difficult, but I haven't done
that either.

> Imagine the memory costs, though.  (Python is a memory pig, too, yes?)

As a rule, it's not as frugal as C or as profligate as Java, just like
Perl.

To tell the truth, though, I'd be very happy to be able to easily call
routines back and forth between the two.  I'm very fond of both languages.

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe