How can I do web programming with Lisp or Scheme?

后端 未结 14 828
遇见更好的自我
遇见更好的自我 2021-01-29 18:35

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 enviro

相关标签:
14条回答
  • 2021-01-29 18:59

    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.

    0 讨论(0)
  • 2021-01-29 18:59

    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.

    0 讨论(0)
  • 2021-01-29 19:02

    This may be what you are looking for.

    http://www.plt-scheme.org/

    http://docs.plt-scheme.org/web-server/index.html

    http://common-lisp.net/project/cl-weblocks/

    0 讨论(0)
  • 2021-01-29 19:07

    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 2019: there's a new tutorial on the Common Lisp Cookbook: https://lispcookbook.github.io/cl-cookbook/web.html It covers routing, template engines, building self-contained binaries, deployment, etc.

    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)

    With ParenScript, we can write JavaScript in Common Lisp, without living our usual workflow, and we can thus use the fetch web API to write Ajax calls.

    0 讨论(0)
  • 2021-01-29 19:09

    I've written a pretty extensive tutorial/ebook on the topic: http://lispwebtales.ppenev.com/

    Quick summary:

    • It uses Common Lisp
    • It uses the Restas framework
    • It has examples for pretty much most of basic web development, including DB access, authentication, HTML generation and templating.
    • Since the Restas documentation is pretty much out of date, my tutorial is the closest thing to up to date docs.
    • Shows a few of the more advanced features, like policies, which allow you to write pluggable interfaces, for instance you can write a data store layer, and write back-ends for different storage mechanisms with relative ease, the module system which allows you to write reusable components, like auth frameworks and things like that.
    • It covers things like installing lisp, setting up the ASDF build system and the quicklisp package manager etc.
    • It's free online, and as soon as I finish it it will be free on leanpub as well. The source is on https://github.com/pvlpenev/lispwebtales under a CC license, the source code is MIT. Not all of it is published yet, and I'm in the process of revising.
    0 讨论(0)
  • 2021-01-29 19:09

    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
    0 讨论(0)
提交回复
热议问题