RE: Sympl Language Sample and Walkthrough Document

Coordinator
May 14, 2009 at 4:34 PM

One of the really cool things about Sympl that I think is worth emphasizing is the version that’s implemented in IronPython. Not only is it the 1st language I know if implemented in IronPython but it’s able to do cool stuff like create IDynamicMetaObjectProvider implementation from Pythons objects which are already dynamic objects! Now we just need to get some interested in writing IpyIpy J

From: users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] On Behalf Of Bill Chiles
Sent: Wednesday, May 13, 2009 5:00 PM
To: dlr@discussions.codeplex.com
Cc: users@lists.ironpython.com
Subject: [IronPython] Sympl Language Sample and Walkthrough Document

There’s a new DLR sample to which I wanted to draw folks’ attentions. There is a small language implementation sample, implemented in both IronPython and C#, with an accompanying walkthrough document. The code is now on the DLR Codeplex site under ...\Languages\Sympl, and the document is on the “Documents and Specs” page which you can get to from the list of links on the home page. Under the Sympl directory is also an examples directory with some code written in Sympl, which all runs when you execute Main in program.cs. The code and document will be in zip files we will produce to go along with the VS Beta1 release coming soon.

Sympl demonstrates how to implement a very simple language using the Dynamic Language Runtime (DLR) as it ships in .NET 4.0. The goal is to make you aware of how to get started building a language on the DLR. Sympl does not show production quality rich .NET interoperability and binding logic. It does walk you through the following:

  • Using DLR Expression Trees (which include LINQ Expression Trees v1) for code generation
  • Using DLR dynamic dispatch caching
  • Building runtime binders
  • Building dynamic objects and dynamic meta-objects
  • Supporting dynamic language/object interoperability
  • Very simple hosting with application supplied global objects
  • Basic arithmetic and comparison operators with fast DLR dispatch caching
  • Control flow
  • Name binding within Sympl
  • Method and top-level function invocation with fast DLR dispatch caching
  • Very simple .NET interoperability for runtime method and operation binding
  • Using the DLR’s built-in COM binding
  • Closures
  • Assignment with various left-hand-side expressions

Sympl does not yet demonstrate using any Codeplex-only DLR code such as the DefaultBinder, the faster and nicer .NET reflection trackers (Sympl’s is painfully slow and simple), or the common DLR hosting (yet).

A few caveats on the documentation. First, the walk through document still needs some polishing, but I wanted to get it out to people. Feel free to send me comments or ask questions. Second, the document refers to a couple of other documents on our Codeplex site, but we haven’t updated some of them since DEC 08. Those will be updated in the next couple of weeks. I think the sympl.doc walkthrough is very readable on its own and has all the relevant code snippets included in it as well. Lastly, while the example is overall reasonably simple, it does demonstrate all the basic concepts of building a language on the DLR with explanations, and therefore, is quite long. However, the document unfolds in the same way the Sympl language implementation evolved, so it progresses well for incrementally increasing your awareness of how to build a language on the DLR.

Hope you enjoy and find this code and doc helpful!

Cheers,

Bill

May 28, 2009 at 12:41 AM

The sample of the Lisp-like language Sympl is indeed great! I see that the csharp version has some 3.5/4.0 IFDEFs, and I had to change the location of Linq to get the Python version to load. But there is at least one last issue in running the Python sympl under .NET 3.5:

>>> import sympl
>>> import test
warning: DeprecationWarning: Assembly.LoadWithPartialName has been obsoleted.  T
his method has been deprecated. Please use Assembly.Load() instead. http://go.mi
crosoft.com/fwlink/?linkid=14202
warning: DeprecationWarning: Assembly.LoadWithPartialName has been obsoleted.  T
his method has been deprecated. Please use Assembly.Load() instead. http://go.mi
crosoft.com/fwlink/?linkid=14202
Traceback (most recent call last):
  File "", line unknown, in __init__
  File "", line unknown, in _addNamespacesAndTypes
  File "", line unknown, in SetMember
  File "mscorlib", line unknown, in MakeGenericType
  File "mscorlib", line unknown, in SanityCheckGenericArguments
  File "<stdin>", line 1, in <module>
  File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\test.py", line 2, in test
  File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\sympl.py", line 33, in __init_
_
  File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\sympl.py", line 71, in _addNam
espacesAndTypes
  File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\runtime.py", line 646, in SetM
ember
  File "mscorlib", line unknown, in MakeGenericType
  File "mscorlib", line unknown, in SanityCheckGenericArguments
ValueError: The type or method has 1 generic parameter(s), but 3 generic argumen
t(s) were provided. A generic argument must be provided for each generic paramet
er.
>>>

Is there an easy work-around to try this in 3.5 in Python?

Coordinator
May 28, 2009 at 5:22 PM

Oops, that’s odd since we were testing our daily source pushes and the zips.  Though IPy’s Beta1 push is supposed to be from the same tree, I’m curious which IPy binaries you’re using to run it.  We need to look into this, but I’m guessing IPy made some changes that either introduced an issue or fixed one for which my code is inconsistent.

Thanks for the email, will try to get back to you today.

Bill

From: dsblank [mailto:notifications@codeplex.com]
Sent: Wednesday, May 27, 2009 5:42 PM
To: Bill Chiles
Subject: Re: RE: Sympl Language Sample and Walkthrough Document [dlr:56338]

From: dsblank

The sample of the Lisp-like language Sympl is indeed great! I see that the csharp version has some 3.5/4.0 IFDEFs, and I had to change the location of Linq to get the Python version to load. But there is at least one last issue in running the Python sympl under .NET 3.5:

>>> import sympl
>>> import test
warning: DeprecationWarning: Assembly.LoadWithPartialName has been obsoleted. T
his method has been deprecated. Please use Assembly.Load() instead. http://go.mi
crosoft.com/fwlink/?linkid=14202
warning: DeprecationWarning: Assembly.LoadWithPartialName has been obsoleted. T
his method has been deprecated. Please use Assembly.Load() instead. http://go.mi
crosoft.com/fwlink/?linkid=14202
Traceback (most recent call last):
File "", line unknown, in __init__
File "", line unknown, in _addNamespacesAndTypes
File "", line unknown, in SetMember
File "mscorlib", line unknown, in MakeGenericType
File "mscorlib", line unknown, in SanityCheckGenericArguments
File "<stdin>", line 1, in <module>
File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\test.py", line 2, in test
File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\sympl.py", line 33, in __init_
_
File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\sympl.py", line 71, in _addNam
espacesAndTypes
File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\runtime.py", line 646, in SetM
ember
File "mscorlib", line unknown, in MakeGenericType
File "mscorlib", line unknown, in SanityCheckGenericArguments
ValueError: The type or method has 1 generic parameter(s), but 3 generic argumen
t(s) were provided. A generic argument must be provided for each generic paramet
er.
>>>

Is there an easy work-around to try this in 3.5 in Python?

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

May 28, 2009 at 9:12 PM
Edited May 28, 2009 at 9:29 PM

I think that I am using IronPython from DLR 0.91 and sympl from the same. The only thing that I changed, I think, is that I built and ran them under .NET 3.5. Thanks for looking into this!

UPDATE: yes, just now downloaded 0.91 and rebuilt in 3.5. This Python code has the Linq coming from the wrong place, and the above-mentioned error.

May 29, 2009 at 6:48 PM

My apologies for the issue in the Python version of sympl.  As you saw in the C# version, we have a bunch of conditionals around whether we’re building for 3.5 or 4.0 because we use different namespaces in the DLR for each version.  Those conditionals are actually injected into the released code via a “packaging” script.  They don’t exist in our internal version.

Similar packaging fixes were supposed to happen in the Python version but were incomplete.  L

I’ll be updating the release zip a little later today.  But I believe the fix you’re looking for is to change line 20 in runtime.py from:

from System import (Action, Func, MissingMemberException, #ArgumentException,

                    InvalidOperationException, Boolean, MissingMemberException,

                    Type, Array, Delegate, Void)

To:

from System import (MissingMemberException, #ArgumentException,

                    InvalidOperationException, Boolean, MissingMemberException,

                    Type, Array, Delegate, Void)

from Microsoft import (Action, Func)

I’ll send another mail when the release zip has been fixed.  Thanks for pointing this out!

                -Ryan

From: dsblank [mailto:notifications@codeplex.com]
Sent: Thursday, May 28, 2009 2:13 PM
To: Ryan Dawson
Subject: Re: RE: Sympl Language Sample and Walkthrough Document [dlr:56338]

From: dsblank

I think that I am using IronPython from DLR 0.91 and sympl from the same. The only thing that I changed, I think, is that I built and ran them under .NET 3.5. Thanks for looking into this!

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

May 29, 2009 at 7:46 PM
Thanks, but think that I had worked through the import errors. Where it
is crashing is:

File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\runtime.py", line 646,
in SetM
ember
File "mscorlib", line unknown, in MakeGenericType
File "mscorlib", line unknown, in SanityCheckGenericArguments
ValueError: The type or method has 1 generic parameter(s), but 3 generic
argumen
t(s) were provided. A generic argument must be provided for each generic
paramet
er.
>>>

But perhaps your fixes will address that too...

rdawson wrote:
>
>
> From: rdawson
>
> My apologies for the issue in the Python version of sympl. As you saw
> in the C# version, we have a bunch of conditionals around whether we’re
> building for 3.5 or 4.0 because we use different namespaces in the DLR
> for each version. Those conditionals are actually injected into the
> released code via a “packaging” script. They don’t exist in our
> internal version.
>
> Similar packaging fixes were supposed to happen in the Python version
> but were incomplete. L
>
> I’ll be updating the release zip a little later today. But I believe
> the fix you’re looking for is to change line 20 in runtime.py from:
>
> from System import (Action, Func, MissingMemberException,
> #ArgumentException,
>
> InvalidOperationException, Boolean,
> MissingMemberException,
>
> Type, Array, Delegate, Void)
>
> To:
>
> from System import (MissingMemberException, #ArgumentException,
>
> InvalidOperationException, Boolean,
> MissingMemberException,
>
> Type, Array, Delegate, Void)
>
> from Microsoft import (Action, Func)
>
> I’ll send another mail when the release zip has been fixed. Thanks for
> pointing this out!
>
> -Ryan
>
> *From:* dsblank [mailto:[email removed]
> *Sent:* Thursday, May 28, 2009 2:13 PM
> *To:* Ryan Dawson
> *Subject:* Re: RE: Sympl Language Sample and Walkthrough Document
> [dlr:56338]
>
> From: dsblank
>
> I think that I am using IronPython from DLR 0.91 and sympl from the
> same. The only thing that I changed, I think, is that I built and ran
> them under .NET 3.5. Thanks for looking into this!
>
> Read the full discussion online
> <http://dlr.codeplex.com/Thread/View.aspx?ThreadId=56338&ANCHOR#Post195430>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[dlr:56338]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe or change your settings
> <http://www.codeplex.com/site/discussions/project/unsubscribe/dlr> on
> codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>
> Read the full discussion online
> <http://dlr.codeplex.com/Thread/View.aspx?ThreadId=56338&ANCHOR#Post195787>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[dlr:56338]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe or change your settings
> <http://www.codeplex.com/site/discussions/project/unsubscribe/dlr> on
> codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>


--
Douglas S. Blank
Director, Institute for Personal Robots in Education (IPRE)
http://www.roboteducation.org
Chair, and Associate Professor, Computer Science, Bryn Mawr College
http://cs.brynmawr.edu/~dblank (610)526-6501
Coordinator
May 30, 2009 at 12:43 AM

We’re guessing the generic issue is that you don’t have all the Func types, notice in Ryan’s post that he got those from Microsoft.Scripting.DLL, not System.Dll (mscorlib).  We took the zip file and just make a couple of changes from System to from Microsoft, and “ipy test.py” in the sympl\python subdir worked fine.  Worse case, Ryan will push a new zip and push new sources to the source tap with the changes, then you should just be able to run exactly what’s there.

Thanks,

Bill

From: dsblank [mailto:notifications@codeplex.com]
Sent: Friday, May 29, 2009 12:46 PM
To: Bill Chiles
Subject: Re: RE: Sympl Language Sample and Walkthrough Document [dlr:56338]

From: dsblank

Thanks, but think that I had worked through the import errors. Where it
is crashing is:

File "C:\Users\dblank\Desktop\Myro\Pyjama\simpl\runtime.py", line 646,
in SetM
ember
File "mscorlib", line unknown, in MakeGenericType
File "mscorlib", line unknown, in SanityCheckGenericArguments
ValueError: The type or method has 1 generic parameter(s), but 3 generic
argumen
t(s) were provided. A generic argument must be provided for each generic
paramet
er.
>>>

But perhaps your fixes will address that too...

rdawson wrote:
>
>
> From: rdawson
>
> My apologies for the issue in the Python version of sympl. As you saw
> in the C# version, we have a bunch of conditionals around whether we’re
> building for 3.5 or 4.0 because we use different namespaces in the DLR
> for each version. Those conditionals are actually injected into the
> released code via a “packaging” script. They don’t exist in our
> internal version.
>
> Similar packaging fixes were supposed to happen in the Python version
> but were incomplete. L
>
> I’ll be updating the release zip a little later today. But I believe
> the fix you’re looking for is to change line 20 in runtime.py from:
>
> from System import (Action, Func, MissingMemberException,
> #ArgumentException,
>
> InvalidOperationException, Boolean,
> MissingMemberException,
>
> Type, Array, Delegate, Void)
>
> To:
>
> from System import (MissingMemberException, #ArgumentException,
>
> InvalidOperationException, Boolean,
> MissingMemberException,
>
> Type, Array, Delegate, Void)
>
> from Microsoft import (Action, Func)
>
> I’ll send another mail when the release zip has been fixed. Thanks for
> pointing this out!
>
> -Ryan
>
> *From:* dsblank [mailto:[email removed]
> *Sent:* Thursday, May 28, 2009 2:13 PM
> *To:* Ryan Dawson
> *Subject:* Re: RE: Sympl Language Sample and Walkthrough Document
> [dlr:56338]
>
> From: dsblank
>
> I think that I am using IronPython from DLR 0.91 and sympl from the
> same. The only thing that I changed, I think, is that I built and ran
> them under .NET 3.5. Thanks for looking into this!
>
> Read the full discussion online
> <http://dlr.codeplex.com/Thread/View.aspx?ThreadId=56338&ANCHOR#Post195430>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[dlr:56338]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe or change your settings
> <http://www.codeplex.com/site/discussions/project/unsubscribe/dlr> on
> codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>
> Read the full discussion online
> <http://dlr.codeplex.com/Thread/View.aspx?ThreadId=56338&ANCHOR#Post195787>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[dlr:56338]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe or change your settings
> <http://www.codeplex.com/site/discussions/project/unsubscribe/dlr> on
> codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>


--
Douglas S. Blank
Director, Institute for Personal Robots in Education (IPRE)
http://www.roboteducation.org
Chair, and Associate Professor, Computer Science, Bryn Mawr College
http://cs.brynmawr.edu/~dblank (610)526-6501

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

May 30, 2009 at 4:06 PM

You were correct. Importing the appropriate Func, and Action indeed allows it to work. Thanks!

In payment for my pestering, a suggestion:

Change the System.Console.ReadLine() to the more Pythonic raw_input(prompt). If you use python "print" for prompt, then you should use the analogous "raw_input" (which then eliminates the need for print).Or use System.Console.Write for the prompt, to be analogous to ReadLine. But if you use "raw_input(prompt)" then those system that have remapped IO Input and Output for IronPython will work.

Thanks!