在C#中使用Lisp

正如很多人在这个问题中指出的那样,Lisp主要用作学习经验。 不过,如果我能以某种方式使用我的Lisp算法并将它们与我的C#程序结合起来,那将会很棒。 在大学里,我的教授从来没有告诉我如何在程序中使用我的Lisp例程(不,不是在Lisp中编写GUI,谢谢)。 那我该怎么办?

试试这些Lisp的.Net实现:

  • IronScheme

IronScheme旨在成为基于Microsoft DLR的R6RS符合方案实施。

  • L Sharp .NET

L Sharp .NET是一种强大的类似Lisp的.NET脚本语言。 它使用类似于Arc的Lisp方言,但与.NET Framework紧密集成,后者提供了丰富的库集。

Clojure是一个Lisp-1,可以即时编译为Java字节码,从而实现非常好的运行时性能。 您可以使用Clojure,并使用IKVM的ikvmc将其交叉编译为.NET程序集。 当然,在.NET中使用时,Clojure很乐意生成.NET IL,从而在JVM上使用它时可以获得相同类型的编译代码性能。

如果它只是您想要使用的例程,您可以尝试LSharp,它允许您在.NET中使用Lisp表达式:

http://www.lsharp.org/

另一种方式(使用Lisp中的.NET)将是RDNZL:

http://www.weitz.de/rdnzl/

.Net 1.1 SDK包含LISP编译器示例。 请参阅SDK \ v1.1 \ Tool Developers Guide \ Samples \ clisp

我知道这是一个非常古老的问题。 但我会尝试从自己的经验和观点提供答案。

对于喜欢我们喜欢Scheme / Lisp的纯粹,优雅和简洁的人,我希望这会给你一些鼓励和灵感,让他们在实际制作中非常有用:)

我最近开源了一个类似Scheme的解释器,名为schemy ,用C#编写(约1500行代码)。 这是动机以及它如何有用 –

在没有详细介绍的情况下,我正在构建一个Web API服务器,其请求处理逻辑需要由其他开发人员/数据科学家即插即用。 这里明确要求分离关注点 – 服务器并不关心请求处理逻辑,但它需要知道它可以处理哪些请求以及在何处查找和加载处理程序的逻辑。

因此,服务器不是将处理程序实现放在服务器应用程序中,而是提供可重用的“块”,这些块可以基于某些标准和逻辑链接在一起以形成管道 ,即通过配置定义的处理程序。 我们尝试使用JSON / XML来描述这样的管道,并很快意识到我实际上构建了一个抽象语法树解析器

这是我意识到这是对轻量级,基于表达式的小语言的需求。 因此我实现了可嵌入的schemy解释器。

我在这里放了一个示例命令处理应用程序,它捕获了我上面提到的Web服务器的设计理念的本质。 它的工作原理如下:

  1. 它扩展了嵌入式Schemy解释器,其中包含一些用C#实现的函数。

  2. 它找到.ss脚本,它通过使用那些实现的函数来定义命令处理管道。

  3. 服务器通过查找符号类型为Func的符号EXECUTE ,从脚本中查找并保留组合管道。

  4. 当命令请求进入时,它只调用相应的命令处理器(由EXECUTE定义的命令处理器),并响应结果。

最后,这是一个复杂的示例脚本,它通过此TCP命令服务器提供在线手册页查找:

 ; This script will be load by the server as command `man`. The command ; is consistent of the following functions chained together: ; ; 1. An online man-page look up - it detects the current operating system and ; decides to use either a linux or freebsd man page web API for the look up. ; ; 2. A string truncator `truncate-string` - it truncates the input string, in ; this case the output of the man-page lookup, to the specified number of ; characters. ; ; The client of the command server connects via raw RCP protocol, and can issue ; commands like: ; ; man ls ; ; and gets response of the truncated corresponding online manpage content. (define EXECUTE (let ((os (get-current-os)) (max-length 500)) (chain ; chain functions together (cond ; pick a manpage lookup based on OS ((equal? os "freebsd") (man-freebsd)) ((equal? os "linux") (man-linux)) (else (man-freebsd))) (truncate-string max-length)))) ; truncate output string to a max length 

通过命令服务器加载此脚本,TCP客户端可以向服务器发出命令man

 $ ncat 127.0.0.1 8080 man ls LS(1) FreeBSD General Commands Manual LS(1) NAME ls -- list directory contents SYNOPSIS ls [--libxo] [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format] [file ...] DESCRIPTION For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, 

也许你应该看看L#。 我不知道你是否正在寻找它(自大学以来没有触及Lisp),但值得一试。

http://www.lsharp.org/

还有DotLisp 。