Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Telamon

Will LISP Finally Be Replaced?

This topic is 5140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Will LISP, the perenial AI toolkit, finally be replaced by a more modern language? C# version 2.0 will provide native support for first class functions (lambda function objects). From the graduate class I took in programming languages, I got the impression that support for lambda functions is the key feature of LISP (or even ML/SML.NJ) that enable an elegant solution to a problem that would be otherwise painful and tedious to write in a procedural language like C++. Will this make C# a viable alternative for sophisticated AI programming? Do you think that with support for lambda functions being provided in a mainstream language, that the functional programming paradigm will find a new applications? I can see several potential uses for first class functions in constructing a data-driven AI for something like an empire-building strategy game. If not smarter opponents, it may allow for more varied AI play with less work. Of course, LISP will probably live forever, as its conceptually dense code seems to appeal to people who can think that way. I myself find it counter-intuitive and am excited that this feature has escaped the confines of LISP and its descendants. Read about C# 2.0 language innovations http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Shedletsky''s Code Library: Open source projects and demos

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Telamon
I got the impression that support for lambda functions is the key feature of LISP (or even ML/SML.NJ) that enable an elegant solution to a problem that would be otherwise painful and tedious to write in a procedural language like C++.

No. Lambda functions are present in many languages, and are only a small part of the beauty of Lisp.

Share this post


Link to post
Share on other sites
Frankly, I can't see what you could write using anonymous functions that you couldn't write without them. All you have to do is add another named function, which can sometimes be annoying but is far from painful or tedious.

Of course, I'm speaking in terms of the imperative approach to programming that C# lends itself to. I've never felt myself limited by a lack of anonymous functions when programming the C# way, but their absence would make Lisp very uncomfortable.

[edited by - twix on April 12, 2004 8:20:14 PM]

Share this post


Link to post
Share on other sites
Can you show me a source that states that C# 2 will have first class functions? (And the anonymous method syntax described in the link you posted does not actually define first class functions.)

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
Can you show me a source that states that C# 2 will have first class functions? (And the anonymous method syntax described in the link you posted does not actually define first class functions.)


The anonymous function syntax in C# wraps the function in a delegate. Delegates will remain the only method for passing around functions.

[edited by - twix on April 12, 2004 8:48:29 PM]

Share this post


Link to post
Share on other sites
So what you''re saying is that C# 2 doesn''t actually have first class functions as claimed in the original post?

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
So what you''re saying is that C# 2 doesn''t actually have first class functions as claimed in the original post?

Delegates are a somewhat clunky way of providing the same functionality as first class functions, no? Anonymous delegates just take you one step closer to the Lisp method by eliminating the named function that the delegate refers to.

So no, C# will not have real first class functions, or at least I''ve heard no rumors of such a thing.

Share this post


Link to post
Share on other sites
I''m a little confused.

Isn''t the definition of a first class function an object that can be returned as the result of another function, saved in some type of reference object, and then executed later? That seems to be the capability that they are offering here.

As for why this is useful, it allows your program to write code and then run it. To do this in C, you would need to write your own compiler. This kind of thing might come up when dealing with making a scripting language or building a finite automata. The most oft-quoted example in class was expression parsing. I actually wrote a simple expression parser for class in ML, and while the code was godawful ugly, it was succinct and the ideas behind it elegant (not to mention easily extendable).

I don''t see why they wouldn''t add first class functions to .Net - the CLR appears to provide a lot of the necessary support already.

----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Shedletsky''s Code Library:

Open source projects and demos

Share this post


Link to post
Share on other sites
quote:
Original post by Telamon
Isn't the definition of a first class function an object that can be returned as the result of another function, saved in some type of reference object, and then executed later? That seems to be the capability that they are offering here.


I've had no formal classes on languages that support them, but AFAIK the defenition of a "first class function" is simply a function that can be used as an argument or be returned by another function.
quote:

As for why this is useful, it allows your program to write code and then run it.

I agree that this is a great benefit and it's one of the things I love most about Lisp, but I don't think that C# is capable of that. Perhaps I ought to look into it some more, but I haven't heard of the ability to use C# own compiler from inside a C# program.

[edited by - twix on April 12, 2004 9:20:59 PM]

Share this post


Link to post
Share on other sites
Ah, I was wrong. C# can indeed generate code on the fly, but that has nothing to do with first class functions.

Here's a snippet of generating a very simple class.

using System;
using System.Reflection;
using System.Reflection.Emit; // To emit MSIL

using System.Threading; // To get Current AppDomain

public class MSILGen
{
public MSILGen()
{
// Create a simple name for the assembly.

AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "CodeGenAssembly";
// Create the dynamic assembly.

AppDomain appDomain = Thread.GetDomain();
AssemblyBuilder assembly = appDomain.DefineDynamicAssembly
(assemblyName,
AssemblyBuilderAccess.Run);
// Create a dynamic module.

ModuleBuilder module = assembly.DefineDynamicModule
("CodeGenModule");
// Define a public class named "CodeGenClass" in the assembly.

TypeBuilder helloWorldClass = module.DefineType("CodeGenClass",
TypeAttributes.Public);
// Define a private String field named "Message" in the type.

FieldBuilder greetingField = helloWorldClass.DefineField
("Message", typeof(String),
FieldAttributes.Private);
// Create the constructor.

Type[] constructorArgs = { typeof(String) };
ConstructorBuilder constructor = helloWorldClass.
DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
constructorArgs);
// Generate IL for the method. The constructor calls its

// superclass constructor. The constructor stores its argument

// in the private field.

ILGenerator constructorIL = constructor.GetILGenerator();
constructorIL.Emit(OpCodes.Ldarg_0);
ConstructorInfo superConstructor = typeof(Object).
GetConstructor(new Type[0]);
constructorIL.Emit(OpCodes.Call, superConstructor);
constructorIL.Emit(OpCodes.Ldarg_0);
constructorIL.Emit(OpCodes.Ldarg_1);
constructorIL.Emit(OpCodes.Stfld, greetingField);
constructorIL.Emit(OpCodes.Ret);
// Create the GetMessage method.

MethodBuilder getGreetingMethod = helloWorldClass.DefineMethod(
"GetMessage",
MethodAttributes.Public,
typeof(String), null);
// Generate IL for GetGreeting.

ILGenerator methodIL = getGreetingMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ldarg_0);
methodIL.Emit(OpCodes.Ldfld, greetingField);
methodIL.Emit(OpCodes.Ret);
// Fry the class CodeGenClass.

typ = helloWorldClass.CreateType();
}
Type typ;
public Type T
{
get { returm this.typ; }
}
}

To be honest, I think I'll stick with Lisp.

[edited by - twix on April 12, 2004 9:20:03 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!