<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {mso-style-builtin:yes;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        mso-style-builtin:yes;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        mso-style-builtin:yes;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-style-builtin:yes;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>It sounds like you want the PythonEngine.CreateMethod API.&nbsp; This
allows you to create a delegate that you can call from C# repeatedly w/o any recompilation
happening.&nbsp; If you want to swap this out w/ a different delegate you can just call
CreateMethod again and update your table of delegates.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The way this works is you give it a delegate type (via the
generic parameter) and then you give it a body of code (minus the function
declaration) and optionally argument names &#8211; incase you&#8217;re not happy w/ the
names the delegate has.&nbsp; It&#8217;ll return an instance of the delegate type to you,
and you can call it from your try block.&nbsp; The 1.0 release includes a .chm which
includes full documentation on the API as well.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>From there it&#8217;s just up to you to decide how to invalidate your
delegates that you hold a reference to and request a new delegate.&nbsp; When you
release the reference to the delegate the memory associated w/ the code will be
released as well.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Segoe UI","sans-serif"'>From:</span></b><span
style='font-size:9.0pt;font-family:"Segoe UI","sans-serif"'>
users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On
Behalf Of </b>David C<br>
<b>Sent:</b> Monday, September 18, 2006 3:10 PM<br>
<b>To:</b> users@lists.ironpython.com<br>
<b>Subject:</b> [IronPython] Performance concerns with mail merge<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'>Hi,<br>
&nbsp;<br>
We have a mail merge engine. We wish to have the option of blessing mail merge
fields (say &lt;##FirstName##&gt;) with the ability to do string formatting,
such as proper casing, all caps, date formatting, and such. And the idea is while
the mail merge engine is compiled C# code, we are hoping to leverage the
dynamic nature of ironpython to allow business analysts and other staff to
bless these mail merge fields with dynamic behaviors at a later date--through
scripting. We imagine the signature of such a &quot;filter&quot; would go
something like:<br>
&nbsp;<br>
protected string Filter_SomeBase32GibberishThatsSafeAlphaNumeric(string
dirtyText, Xml filterContext)<br>
{<br>
&nbsp;&nbsp;&nbsp; string cleanText = &quot;&quot;;<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the dynamic part that do
something with cleanText, given additional information provided by
filterContext xml dom<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // as an aside, this source code is
checked into the db in raw source code form, until the time it need be used<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; finally<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cleanText;<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
&nbsp;<br>
So far what I have learned is that I can do this in C#, using something like
this example:<br>
&nbsp;<br>
<a
href="http://www.codeproject.com/dotnet/evaluator.asp?df=100&amp;forumid=13971&amp;exp=0&amp;fr=26&amp;select=394822">http://www.codeproject.com/dotnet/evaluator.asp?df=100&amp;forumid=13971&amp;exp=0&amp;fr=26&amp;select=394822</a><br>
&nbsp;<br>
But we want a ton of performance out of this merge intelligence. We hope
whatever was compiled (bytecode), is kepted in a hash tree so that
recompilation is not a tax levied on each invocation. There will be many such functions,
and we need to invoke it by reference/delegate (storing them in a lookup
table).<br>
&nbsp;<br>
If we are really really greedy, we would make further requests like it be
possible to update a function. To recompile an updated source code to one such
instance and call the new updated bytecode.<br>
&nbsp;<br>
I have no experience with IronPython in terms of embedding it, and making use
of it in such a scenario, and wish to consult the list for any suggestions or
feasibility comments you may have. Thank you for your time and big kudos ahead
of time for any participation on this.<br>
&nbsp;<br>
Best regards,<br>
-- Li-fan chen<br>
&nbsp;<br>
&nbsp;<br>
&nbsp;<br>
&nbsp;<o:p></o:p></span></p>

<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>

<hr size=2 width="100%" align=center>

</span></div>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>Be
one of the first to try <a
href="http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d"
target="_new">Windows Live Mail.</a><o:p></o:p></span></p>

</div>

</body>

</html>