如何使用 Lisp 或 Scheme 编写 web 程序?

I usually write web apps in PHP, Ruby or Perl. I am starting the study of Scheme and I want to try some web project with this language. But I can't find what is the best environment for this.

I am looking for the following features:

  • A simple way of get the request parameters (something like: get-get #key, get-post #key, get-cookie #key).
  • Mysql access.
  • HTML Form generators, processing, validators, etc.
  • Helpers for filter user input data (something like htmlentities, escape variables for put in queries, etc).
  • FLOSS.
  • And GNU/Linux friendly.

So, thanks in advance to all replies.

转载于:https://stackoverflow.com/questions/1275547/how-can-i-do-web-programming-with-lisp-or-scheme

weixin_41568131
10.24 Things like htmlentities, escaping functions, wrappers for requests, etc. could be a nice exercise for you to implement yourself in Scheme, since you say you are just starting out learning scheme.
大约 11 年之前 回复

14个回答

Racket has everything that you need. See the Racket web server tutorial and then the documentation. The web server has been around for a while, and it has a lot of features. Probably the only thing that is not included is a mysql interface, but that exists as a package on PLaneT (Racket package distribution tool).

UPDATE: Racket now comes with DB support, works with several DBs including mysql.

weixin_41568184
叼花硬汉 Guile! web-artanis.com
2 年多之前 回复
weixin_41568134
MAO-EYE Since '09 Racket has gotten builtin database support. There is support for PostgreSQL, MySQL, SQLite and ODBS. See docs.racket-lang.org/db/index.html
接近 8 年之前 回复
csdnceshi68
local-host Seconded. The continuation interface is interesting too -- don't worry if it looks confusing though; the rest of the servlet interface still works without it. Wasn't aware of the mysql interface, I'll check that out, thanks!
大约 11 年之前 回复

Let's see what can be done with Common Lisp.

The state of the Common Lisp ecosystem (2015) and the Awesome Common Lisp list show us a couple of modern frameworks (Caveman, Lucerne, all built on the new Clack web application server, an interface for Hunchentoot and other servers). Let's discuss with our own findings.

update: a bit later, I found out Snooze, by the creator of Sly or Emacs' Yasnippet, and had a much better impression than say Caveman. Declaring endpoints is just like declaring functions, so some things that were tedious in Caveman are obvious in Snooze, like accessing the url parameters. I don't have much experience with it but I recommend checking it out.

update june 2018: also don't miss the ongoing rewrite of Weblocks, it's going to be huge ! :D http://40ants.com/weblocks/quickstart.html Weblocks allows to build dynamic webapps, without a line of Javascript, without separating the back and front. It is components-based, like React but server-side. It's very alpha as of writing (june 2018), but in progress, and it's working, I have a couple simple web apps working.

A simple way of get the request parameters (something like: get-get #key, get-post #key, get-cookie #key).

I found easier the Lucerne way, it iss as simple as a with-params macro (real world example):

@route app (:post "/tweet")
(defview tweet ()
  (if (lucerne-auth:logged-in-p)
      (let ((user (current-user)))
        (with-params (tweet)
          (utweet.models:tweet user tweet))
        (redirect "/"))
      (render-template (+index+)
                       :error "You are not logged in.")))

Caveman's way has been less clear to me.

Mysql access

Caveman advertises database integration (with Fukamachi's Datafly and sxql).

You can just use clsql or the Mito ORM: https://lispcookbook.github.io/cl-cookbook/databases.html

HTML Form generators, processing, validators, etc.

I don't know if there are form generators out there. edit: there are: cl-forms and formlets, or again 1forms, working with Caveman2.

Caveman does not have one (issue raised in 2011).

Helpers for filter user input data (something like htmlentities, escape variables for put in queries, etc).

Ratify is an input validation library, not integrated into a framework though.

FLOSS and GNU/Linux friendly ✓

Other web stuff

Speaking about web, there are other nice libraries in CL land:

  • web servers: Woo is a fast HTTP server, faster than Nodejs (beware of charts…), wookie is an async http server,
  • Dexador is an HTTP client
  • Plump, lquery and CLSS make it easy to parse html and query the DOM.
  • cl-bootstrap offers twitter-bootstrap shortcuts for the cl-who templating engine (which kind of replaces Jade/Pug, even though we have usual templates too).

Ajax in Lisp

(remember, with Weblocks, see above, we might not need those)

  • Wuwei is an interesting experiment that enables to write Ajax views in Common Lisp. The website has nice real-world demos. It can include other Javascript libraries.
  • also SmackJack, explained in this recent blog post (2017).

You may want to have a look at Clojure:

Clojure is a dynamic programming language that targets the Java Virtual Machine. [...] Clojure provides easy access to the Java frameworks, with optional type hints and type inference, to ensure that calls to Java can avoid reflection.

Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system.

Interop with Java is straightforward in Clojure, so you can re-use any existing Java libraries as you need. I'm sure there are plenty that are useful for web development.

clojure-contrib has an SQL API, and there is ClojureQL as well, which should cover your DB access needs.

There is a web framework for Clojure called Compojure under development. There may be others, too.

Clojure's source is available on github under the EPL. Getting it running on Linux is easy; I just clone the git repos and run ant.

csdnceshi54
hurriedly% Clojure runs on a JVM so you'll need to have one installed. Experience with the Java class library is definitely a plus once you get outside of Clojure's built-in types.
大约 11 年之前 回复
csdnceshi72
谁还没个明天 I don't think Java is a requirement; you'll be able to get started with Clojure just fine.
大约 11 年之前 回复
csdnceshi50
三生石@ Thanks for the reply. I don't have any experience with Java. Is a requirement for clojure setup or use?
大约 11 年之前 回复

Paul Graham (and friends) made a lisp dialect specifically for writing basic web applications. It's called Arc, and you can get it at arclanguage.org.

It's probably not suited for really big complex websites and I'm not sure what state it's database support is at but Paul Graham knows how to write web applications in lisp, so Arc will make the HTTP/HTML part easy for you while you spend most of your brain cycles learning the lisp way.

csdnceshi74
7*4 Ah Thanks. I fixed it.
10 年多之前 回复
weixin_41568183
零零乙 Should be Arc, not Ark.
10 年多之前 回复

Weblocks is nice tool for building web apps in Common Lisp, but a bit too heavy-weight for me.

We use the following stack:

  • OpenMCL (open source Lisp, very nice)

  • Portable Allegroserve (web server, HTML generator)

  • Our own Rails-like tools for doing Ajaxy stuff (update: this has now been open sourced as WuWei)

  • A variety of CL libraries like cl-json, cl-smtp, md5

You can do web development with guile scheme. Its standard library includes the (sxml simple) module that is very useful for html generation, manipulation, and parsing. The guile-www library adds support for http, cgi, etc. The guile-dbi library provides access to MySQL and other databases. With these building blocks, you can implement everything from simple cgi scripts to web applications with their own HTTP server.

csdnceshi72
谁还没个明天 +1 Guile has suddenly gotten very good for web work.
8 年多之前 回复
csdnceshi57
perhaps? PLT Scheme is now known as Racket, and lives at a different site: racket-lang.org
8 年多之前 回复
csdnceshi72
谁还没个明天 A description of the links would be nice.
大约 11 年之前 回复

Clojure is a Lisp dialect which may interest you. At this point there's a pretty decent web development stack. I can recommend a few things:

  • The leiningen dependency manager which makes is really easy to install and manage libraries that you're using. Pretty nice set of plugins for it too. There's even a plugin for Clojurescript, which is a language based on Clojure that compiles to Javascript.
  • The ring HTTP server abstraction. Its used in most actual web frameworks. Its a pretty good idea to learn that first before jumping into an actual framework.
  • hiccup is a HTML dsl/templating language written in Clojure. Its very expressive! Reminds me a bit of Jade, in a sense.
  • composure would have to be the most popular web framework for Clojure. Its essentially a routing library like express.js.

I use my own, customized version of Scheme, derived from MzScheme. It has a new, simple web-application framework, a built-in web-server (not the one that comes with MzScheme) and ODBC libraries. (http://spark-scheme.wikispot.org/Web_applications). The documentation may not be exhaustive, as this is more of a personal tool. But there are lots of sample code in the code repository.

Try Weblocks, a Common Lisp web framework:

http://weblocks.viridian-project.de/

共14条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问