11

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

4

7 回答 7

13

试试 Lisp 的这些 .Net 实现:

IronScheme 的目标是成为基于 Microsoft DLR 的符合 R6RS 的 Scheme 实现。

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

于 2008-09-16T07:19:57.920 回答
10

Clojure是一种 Lisp-1,可即时编译为 Java 字节码,从而带来非常好的运行时性能。您可以使用 Clojure,并使用IKVM的 ikvmc将其交叉编译为 .NET 程序集。当然,在 .NET 中使用时,Clojure 会愉快地生成 .NET IL,从而获得与在 JVM 上使用它时所期望的相同类型的编译代码性能。

于 2008-09-16T11:31:06.943 回答
3

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

http://www.lsharp.org/

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

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

于 2008-09-16T07:21:30.770 回答
3

.Net 1.1 SDK 包含一个 LISP 编译器示例。请参阅 SDK\v1.1\Tool 开发人员指南\Samples\clisp

于 2008-09-16T07:22:55.293 回答
3

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

对于像我们这样喜欢 Scheme/Lisp 的纯粹、优雅和简单的人,我希望这能给你一些鼓励和启发,让它们在实际生产中非常有用:)

我最近从名为schemy的工作中开源了一个类似于 Scheme 的解释器,它是用 C# 编写的(大约 1500 行代码)。这是动机以及它的用处 -

没有过多的细节,我正在构建一个 Web API 服务器,它的请求处理逻辑需要其他开发人员/数据科学家即插即用。这里有一个明确的关注点分离需求——服务器不太关心请求处理逻辑,但它需要知道它可以处理哪些请求以及在哪里找到和加载处理程序的逻辑。

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

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

我在这里放了一个示例命令处理应用程序,它抓住了我上面提到的 Web 服务器设计理念的精髓。它是这样工作的:

  1. 它使用 C# 实现的一些功能扩展了嵌入式 Schemay 解释器。

  2. .ss通过使用那些实现的功能找到定义命令处理管道的脚本。

  3. EXECUTE服务器通过查找应该是 type的符号,从脚本中找到并保存 composes 管道Func<object, object>

  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 <unix_command>向服务器发出命令:

$ 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,
于 2018-04-02T19:03:56.337 回答
2

也许你应该看看 L#。我不知道它是否是您正在寻找的东西(自大学以来就没有接触过 Lisp),但它可能值得一试。

http://www.lsharp.org/

于 2008-09-16T07:22:29.443 回答
2

还有DotLisp

于 2010-03-18T14:22:55.177 回答