The .NET Framework is a layer on top of Win32. Some of its main features are the use of byte code (intermediate language, IL), programming language independence and language cooperation, a common runtime library for all languages (CLR), the new language C# and a sandbox environment with code verification ("managed code").
Tcl and Tk could be ported to use the framework instead of the OS API. This would gain us even more interoperability (although we already have that through COM, as cooperation with COM is built into .NET). It would also allow Tcl and Tk to run in a "managed" environment, i.e. Tcl and Tk could be "trusted" in the Microsoft sense of the word.
A "Shared Source" version of the CLI and the C# and JScript compilers is at [4 ]. This code has an actual example "platform-independent UI (PIGUI)" that uses Tcl and Tk.
TclBridge allows full access to Tcl/Tk from all .NET languages.
JJM 2003-01-09: Yes. It provides bi-directional communication with COM components. Tcl/Tk scripts may be evaluated from the COM side and new Tcl commands may be added via methods of COM objects. This allows for full Tcl/Tk based scripting of any application capable of using COM objects.
Please see http://www.tclbridge.com/html/CreateCommand.html and http://www.tclbridge.com/html/CreateDynamicCommand.html for more information.
DKF 2003-01-06: Note that porting to the IP/CLR is in effect equivalent to porting to Java or Parrot; you're really forced to write a Tcl parser in the target language and then produce an implementation of all (well, a useful subset in the first instance) the commands in the target language too. The key problem is that the current Tcl bytecodes are defined at a level that is meaningful to Tcl, not at a level that virtually any other bytecode operates at; very few bytecodes have an opcode for "increment-hash-entry-and-fire-attached-traces"! Given that, you're either just producing another language reimplementation (like Jacl) or you're taking on the hard task of defining how to go from Tcl to the fairly-common low-level register-based bytecode engines that so many other languages use. Which would be nice and useful, but is a really huge (and definitely complex and deep) task...
CL follows up: perhaps readers are wondering what's wrong with Donal; hasn't Microsoft emphasized that .NET is "multi-lingual" and "standards-based" and so on? Yes, that's how Microsoft markets .NET. Keep in mind that Microsoft feels no obligation to link its marketing to any particular engineering reality. Developers can, in principle, use any language for their .NET work. The reality is quite a bit different, Microsoft collectively knows this, but feels no urgency to correct the confusion.
TAC Tcl runs best under its own virtual machine ;-) The problem with generic (or multi-lingual) virtual machines (byte-code interpreters) is that they provide yet another abstraction above the CPU's machine code (which may not be geared toward your favorite language's semantics anyway). Forth runs fastest on Forth chips (where the machine code and possibly the microcode/wiring is optimized toward running Forth). Sorry, I'm digressing... But anyway, Java runs best under the JVM. In the end, you want your bytecode to match the semantics of your language. I would be interested in finding a language built on top of the Java Virtual Machine (JVM) that runs faster than Java. The idiosyncracies of common .NET languages (C#) set the bytecode for .NET. You can get other languages to play (like Tcl), but be prepared for complex semantic mappings.
Jeffrey Hobbs just had this to say on the very topic on comp.lang.tcl:
From: Jeffrey Hobbs <[email protected]> Subject: Re: TCL/TK .NET Newsgroups: comp.lang.tcl Date: Tue, 07 Jan 2003 03:32:10 GMT Organization: ActiveState [...] Tk does not become any more x-platform than it currently is by having an IL implementation of Tcl. While this may be interesting in the research sense now, I'm not sure that there is much practical value. The .NET CIL is not well suited for dynamic languages, but there is also no limitation in using the current Tcl binaries on Microsoft's .NET OSes, as .NET is (currently) just an adjunct to the rest of the system. I'm not against seeing such an implementation, but I do try and understand the motivation behind seeking way (and trying to make sure people aren't misled by MS's misleading marketing mumbo-jumbo).
Does not Tcl be already running under all Windows? What is the interest of having Tcl included in the .NET platform?
My understanding is that Tcl is for all and .NET only for Microsoft.
Sean Halliday 2003-01-17:
I think some people might be missing the big picture with .NET. The .NET IL gets compiled to native code at run-time. This makes it a big win over other byte-code languages that interpret the byte code. There is also a common type system (CTS) and common runtime. This allows code that was written in various languages to all work together. I am a big fan of Tcl/Tk and have been using it for about 8 years. I am now a big fan of .NET and I hate COM and ActiveX. Don't prejudge .NET just because it is from MS. As for Tcl/Tk being a .NET language, I don't know. I think if it was taken seriously, it could be done quite well. The big question is whether the .NET framework will really catch on. Anyway, I currently have Tcl and .NET working together just fine (without the need for COM.) I just write managed C++ code to access .NET. Since unmanaged code can call managed code, the Tcl commands I add can access .NET. I have even hosted C# windows forms in a Tcl app (again without ActiveX or COM.) This is the other really big win with .NET, it is very easy to write interfaces to existing C/C++ libraries - I didn't even need a Wizard :-)
BR: That last sentence sounds more like Tk to me ;-)
Sean brings up an interesting idea on interopability. Let Tcl be as it is with an adaptor handling the connection. But I'm wondering (don't have VC7, so I can't test), as C# is so close to the C syntax, can Tcl's generic code be compiled by C# ?? If so, could a new platform directory be made for ngws ? -- DG
CL reacts: so many ideas are showing up here. I know I am confused.
Davy, it would be entertaining to compile Tcl with C#. Maybe I'll try that when I can make time ... In any case, don't think you need VC7; there are open-source C# compilers. I'm working to make this more obvious on the C# Wiki page.
I agree that there's an open question about whether .NET will succeed and be pervasive. No, wait, there isn't; MS's marketeers already have enough to ensure its longevity. The library is so big and compelling to conventional development shops, that they're switching to it from MFC, win32api, and such, so .NET is successful. With just a bit more lubrication, that'll be interpreted as success for the whole architecture.
I'd love to learn more about the contrast Sean Halliday sketches between COM and .NET. Jacob Levy, for example, has written me that "Every '.NET' object is a COM+ object with some more stuff thrown in. If you don't need that additional stuff (you only need it if you're running on the CLR -- the common language runtime, their name for their VM) then calling through COM+ should work fine. Calling in the other direction -- from a '.NET' object to an old-style COM object -- might not work.
I think Tcl has adequate mechanisms for talking to COM+ objects. All '.NET' objects support type information, so it should even be easy to auto-generate a procedure that makes this efficient as well as type-safe." That matches my understanding. So how can one like .NET so much while abhorring COM?
Sean Halliday 2003-01-18
You really have to work with .NET and COM to understand why .NET is head and shoulders better than COM. Interoperability with COM and .NET is quite easy. You can easily access COM objects in .NET (one line of code brings in the COM object interface). There are tools to convert/wrap .NET code with COM. I think there even may be one to convert .NET controls to ActiveX. I wrote a Tcl/Tk based program that I eventually made an ActiveX control and it was a MAJOR pain! The .NET control version was WAY easier to write and didn't even require a wizard. This does not have much to do with the topic except that .NET will not just catch on because MS is pushing it. Every programmer I have talked to about using .NET likes it a lot - and they were all very sceptical :-)
peterc 2008-02-19: Some big reasons why .NET is an interesting technology and may be useful for Tcl coders: (1) Dotnet on Windows and Mono elsewhere makes it fairly multiplatform, (2) It's a big tickbox in today's job and IT procurement market, (3) Dotnet is well documented, while COM isn't anymore, (4) There may be some efficiency pay-offs by calling Dotnet functions instead of their Tcl/Tk counterparts, particularly on Windows, by virtue of the Dotnet variant not using Tk's X11 emulation layer (XLEL).
SC: This all sounds great and good but is there any evidence that .NET will be anything but the next generation of the Windows API? I realise that mono is more cross-platform but will it ever catch on enough that one could hope to deploy to Mac and Unix based systems and gain some advantage over the current Way of Things?
Technical points: COM interoperability is slower than pure COM or pure .NET (true?). REGASM.EXE can be helpful in interoperability, because it creates the type libraries and registers them for COM.
Tcl Interpreter in C# Application code example for embedding Tcl in C# Application
A Tcl/.net interop solution would allow Tcl script to use the entire .net framework and any other CLS compliant assembly without sacrificing the huge investment made in the existing Tcl interpreter and associated libraries. If someone were to write such a bridge they could take advantage of the ScriptingExtensions for .net library that has been developed for rubydotnet. [7 ]
JH: has written, "... in general, Tcl works just fine in the .NET world as an unmanaged component. Since that's true of a lot of stuff, there is nothing wrong with just assuming that your Tcl works fine on a '.NET desktop'."
Calling Tcl from C# isn't all that exciting to me. What I want to see is something like this:
#!/usr/bin/tclsh using System import Console -from System Console WriteLine "Hello World!"
Whether this is a managed or unmanaged application isn't all that interesting, I'm just here for the scripting.
See: Tablet PC
veb 2010-09-30 18:04:34:
I am working on an application which involves both TCL command line and C# .NET based application. C# .NET application is a console based wherein it outputs the data it sniffs to the console. At a same time, it wait for the user input. We want tcl to invoke this application .exe and then inject some input to the console such that it is read by the .exe console application. I had success invoking the .exe from tcl command based utility, however, I did not get the control back to the tcl which I should. I do not have any previous experience working with it. Can you please advice what causing the problem? Is it the .NET framework or something else??