获得 Lisp“hello world”的最简单方法网络应用程序正在进行

发布于 2024-10-10 06:41:56 字数 269 浏览 0 评论 0原文

我想编写一个 Lisp Web 应用程序只是为了好玩。我发现这个问题关于 Lisp Web 应用程序但所有的答案都显得那么复杂。查看答案中提供的链接后,解决方案似乎非常复杂。

如果我只想要一个简单的“hello world”Lisp Web 应用程序,难道没有一种简单的方法可以做到吗?

I want to write a Lisp web application just for fun. I found this question about Lisp web apps but all the answers seem so complicated. After looking into the links provided in the answers, the solutions seem really complicated.

If I just want a simple, "hello world" Lisp web app, is there not a simple way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

金兰素衣 2024-10-17 06:41:57

这个答案看起来很复杂,但我认为建立并运行一个简单的 Lisp Web 应用程序将比学习 Lisp 的其他更棒的部分更容易,所以它可能是值得的。

有几本非常棒的 Common Lisp 书籍,其中包含介绍 Web 应用程序的章节:实用 Common Lisp 和 < a href="http://landoflisp.com/" rel="noreferrer">Lisp 之国。

Land of Lisp 中有一个章节介绍了使用套接字构建一个简单的 Web 服务器。它非常初级,但我认为可以作为“hello world”类型的 Lisp 应用程序的一个很好的起点。

Practical Common Lisp 中的章节处于更高的水平,并且与称为 Allegro Serve 的成熟服务器一起使用。后面的章节将构建 MP3 流应用程序。

实用 Common Lisp 是免费提供的,以下是感兴趣的章节: http:// /gigamonkeys.com/book/practical-web-programming-with-allegroserve.html

我认为这两本书对于开始使用 Common Lisp 来说都是很好的资源(作为我自己刚刚开始学习的人),尽管《Land of Lisp》是尽管它确实涵盖了一些有趣的问题,例如惰性求值和搜索博弈树,但更易于访问和更有趣。实用的 Common Lisp 更……实用,但这并不是一件坏事。它是针对专业程序员的,所以它的语气稍微严肃一些。

警告一句:

据我所知 Common Lisp 并没有一种真正标准的网络编程方法,所以这是 Lisp 学习的一个领域,如果你不选择与本书相同的实现,你就会开始遇到问题正在读书。

Land of Lisp 始终使用 CLisp,但如果您按照附近的这篇博客文章操作,则可以使用 SBCL:http://blog.ciaranbradley.com/crossing-the-streams-land-of-lisp-chapter-12-0

实用 Common Lisp 使用 Allegro Serve 作为我说,我认为他们的网站上有一个 Allegro Lisp 版本可以与这本书一起使用。不过,您也可以使用便携式 Allegro Serve。如果您使用 Mac OS X 和 SBCL(就像我一样),请小心:SBCL 的线程支持在 OS X 上是实验性的,因此如果您采用这种方式,最好的选择是在虚拟机中安装 Ubuntu,然后 apt-安装 sbcl 并在其中进行 Allegro Serve 编程,其中 SBCL 线程得到更好的支持。也许一些 CL 向导可以在这里提出一些其他技巧。这正是对我有用的。

This answer LOOKS complicated, but I think that getting a simple Lisp web app up and running is going to be easier than learning the other more awesome bits of Lisp anyway, so it's probably worth it.

There's a couple of really great Common Lisp books with intro-to-web-app chapters: Practical Common Lisp and Land of Lisp.

There's a chapter in Land of Lisp which covers building a simple web server using sockets. It's pretty rudimentary, but I think would serve as a great starting point for a "hello world" type of Lisp app.

The chapter in Practical Common Lisp is at a higher level, and works with a full-fledged server called Allegro Serve. There are later chapters which build an MP3 streaming app.

Practical Common Lisp is available for free, here's the chapter of interest: http://gigamonkeys.com/book/practical-web-programming-with-allegroserve.html

I think both books are great resources for starting out with Common Lisp (as someone who's just starting out myself), although Land of Lisp is a bit more accessibile and more fun, although it does cover some interesting problems like lazy evaluation and searching game trees. Practical Common Lisp is more... practical, but that's not really a bad thing. It's aimed at professional programmers so its tone is just a little more serious.

One word of warning:

AFAIK Common Lisp doesn't have a really standard way of doing network programming, so this is one area of Lisp learning where you start to run into problems if you don't pick the same implementation as the book you happen to be reading.

Land of Lisp uses CLisp throughout, but you can use SBCL if you follow along with this blog post nearby: http://blog.ciaranbradley.com/crossing-the-streams-land-of-lisp-chapter-12-0

Practical Common Lisp uses Allegro Serve as I said, and I think there is a version of Allegro Lisp available from their site for use with the book. However, you can also use Portable Allegro Serve. Be careful if you are using Mac OS X and SBCL (as I am): SBCL's thread support is experimental on OS X, so if you go that route, the best bet is to install Ubuntu in a VM and then apt-get install sbcl and do your Allegro Serve programming in there, where SBCL threads are better supported. Maybe some CL wizards can suggest some other tips here. That's just what worked for me.

柠檬色的秋千 2024-10-17 06:41:57

对于 CL-HTTP,人们会将服务器加载到 Lisp 中并执行以下操作:

(defun hello-world (url stream)
  (http:with-successful-response (stream :text)
    (princ "hello world" stream)))

上面是一个响应函数。响应函数有两个参数:URL 和流。响应函数添加通常的响应标头并表示它返回“文本”。在此我们只是将字符串打印到输出流。

(http:export-url #u"/hello-world"
                 :computed
                 :response-function 'hello-world)

上面导出一个 URL,该 URL 与默认上下文(默认服务器名称和端口)合并。 #u 是一个用于创建 URL 对象的读取宏。 URL 导出为 :COMPUTED,因此需要 :RESPONSE-FUNCTION 来计算响应。我们传入上面定义的函数。

当客户端向此服务器发送带有 URL 的 GET 请求时,它会调用该 URL 的响应函数并提供输出流。

然后生成以下内容:

CL-USER 4 > (http:show-raw-url #u"/hello-world")

Status Code: 200 (OK)
Server Version: http/1.1
Date: Wed, 29 Dec 2010 23:39:52 GMT
Server: CL-HTTP/70.218 (LispWorks; 2.1.8)
Content-Type: text/plain; charset=ISO-8859-1
Transfer-Encoding: chunked

hello world

就是这样。

For CL-HTTP one would load the server into Lisp and do:

(defun hello-world (url stream)
  (http:with-successful-response (stream :text)
    (princ "hello world" stream)))

Above is a response function. The response function has two arguments: an URL and a stream. The response function adds the usual response headers and says that it returns 'text'. Within this we just print a string to the output stream.

(http:export-url #u"/hello-world"
                 :computed
                 :response-function 'hello-world)

Above exports an URL that is merged with the default context (the default server name and port). The #u is a read macro to create URL objects. The URL is exported as :COMPUTED and thus needs a :RESPONSE-FUNCTION to compute the response. We pass in the function we defined above.

When a client sends a GET request with the URL to this server, it calls the response function for that URL and supplies an output stream.

Which then generates this content:

CL-USER 4 > (http:show-raw-url #u"/hello-world")

Status Code: 200 (OK)
Server Version: http/1.1
Date: Wed, 29 Dec 2010 23:39:52 GMT
Server: CL-HTTP/70.218 (LispWorks; 2.1.8)
Content-Type: text/plain; charset=ISO-8859-1
Transfer-Encoding: chunked

hello world

That's it.

城歌 2024-10-17 06:41:57

一个简单的 Hello world 应该由 hunchentoot 和 cl-who 组成。

(defparameter *httpd*
  (hunchentoot:start
   (make-instance 'hunchentoot:acceptor
                  :port 8080)))
(princ "Hunchentoot started on port ")
(princ *httpd-port*)
(terpri)

(hunchentoot:define-easy-handler (hello-world (:uri "/hello"))
    ()
  (with-html-output (*standard-output* nil :indent t)
       (:html
              (:head
                 (:title "Hello World"))
              (:body
                 (:p "Hello world!...")))))

欲了解更多信息:http://weitz.de/hunchentoot/http://zaries.wordpress.com/2010/11 /09/lisp-web-server-from-scratch-using-hunchentoot-and-nginx/

要安装hunchentoot,请使用quicklisp(这是最简单的)。

  (ql:quickload :hunchentoot)

A simple Hello world should be with hunchentoot and cl-who.

(defparameter *httpd*
  (hunchentoot:start
   (make-instance 'hunchentoot:acceptor
                  :port 8080)))
(princ "Hunchentoot started on port ")
(princ *httpd-port*)
(terpri)

(hunchentoot:define-easy-handler (hello-world (:uri "/hello"))
    ()
  (with-html-output (*standard-output* nil :indent t)
       (:html
              (:head
                 (:title "Hello World"))
              (:body
                 (:p "Hello world!...")))))

For more information: http://weitz.de/hunchentoot/, http://zaries.wordpress.com/2010/11/09/lisp-web-server-from-scratch-using-hunchentoot-and-nginx/

To install hunchentoot, use quicklisp (it's the easiest).

  (ql:quickload :hunchentoot)
看春风乍起 2024-10-17 06:41:57

PLT Racket是一种功能非常齐全的Scheme方言,可以做到这一点。他们在此处提供了一个简单的教程,其中他们开发了一个小型 CMS,并进行了一些讨论有关 Racket Web 服务器的信息请此处。如果我是你,我会尝试这样做。他们的“hello world”看起来像这样:

(define (start request)
 '(html
   (head (title "My Blog"))
   (body (h1 "Under construction"))))

看,这还不错!

(如果 Clojure 算作 Lisp,当然,还有几个处于不同开发状态的 Web 应用程序框架。)

PLT Racket is a very fully-featured Scheme dialect that can do this. They have a straightforward tutorial here in which they develop a small CMS, and some discussion about a Racket web server here. If I were you, I'd try that. Their "hello world" looks like this:

(define (start request)
 '(html
   (head (title "My Blog"))
   (body (h1 "Under construction"))))

See, it's not so bad!

(If Clojure counts as Lisp, of course, there are several web application frameworks in varying states of development for it as well.)

无言温柔 2024-10-17 06:41:57

此处是最近一篇有关使用 Common Lisp 构建简单网络应用程序的文章。

Here is a recent article on building a simple webapp in Common Lisp.

爱她像谁 2024-10-17 06:41:57

看看“使用 Quickproject 和 Quicklisp 创建一个小型 Lisp 项目”作为稍微复杂一点的示例比“你好世界”。

Have a look at "Making a small Lisp project with quickproject and Quicklisp" for an example slightly more complicated than "Hello World".

帅的被狗咬 2024-10-17 06:41:57

这是一篇博客文章,它设置 SBCL 和 Hunchentoot 来服务你好世界页面。

我不会说这是设置网络应用程序的最佳方式,但它非常简单。

Here's a blog post that sets up SBCL and Hunchentoot to serve a hello-world page.

I won't claim it's the best way to set up a web app but it is pretty straightforward.

↙温凉少女 2024-10-17 06:41:57

嗯,我不完全确定你所说的“网络应用程序”是什么意思。当我构建一个动态网站时,我通常以 CGI 思维方式工作。
这是 Common Lisp 的 CGI 设置的链接 http://www.cl- user.net/asp/jf8v/sdataQvStnw8XWwrFDQ3xCR8X8yBX8yBXnMq=/sdataQu3F$sSHnB==

由于我还不确定的原因,大多数 Lisp Web 工作似乎都以 Lisp 内置的 Web 服务器为中心,而不是 Apache 或IIS 调用 Lisp 软件来解析 .lisp 文件。

Well, I'm not completely sure what you mean by "web app". When I bang together a dynamic site, I usually work in a CGI mindset.
Here's a link to a CGI setup for Common Lisp http://www.cl-user.net/asp/jf8v/sdataQvStnw8XWwrFDQ3xCR8X8yBX8yBXnMq=/sdataQu3F$sSHnB==

For a reason I'm not yet sure of, most Lisp web work seems to center around a web server built in Lisp instead of having Apache or IIS call out into the Lisp software to parse the .lisp file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文