19
loading...
This website collects cookies to deliver better user experience
programmable programming language
for it's great extensible characteristics. It pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, conditionals, higher-order functions, recursion, the self-hosting compiler and the read–eval–print loop.sudo apt-get install sbcl
brew install sbcl
sbcl
CL-USER> (+ 1 2)
3
M-x package-install
and then type slime
and press Enter.M-x slime
which is Alt
or Meta
key + x and then type slime
and enter. It will start the default Lisp program you configured (SBCL in our case) before, within Emacs itself. You can play around in the interpreter just like you did with SBCL earlier.(ql:quickload :caveman2)
(caveman2:make-project #P"~/quicklisp/local-projects/hello-caveman" :author "Rajasegar")
(ql:quickload :hello-caveman)
(hello-caveman:start :port 3000)
http://localhost:3000
. You will get a blank web page saying Welcome to Caveman2
.web.lisp
file situated under src
folder of your newly created project.http://localhost:3000/about
to your app, you can define a new route under the default route like below.(defroute "/about" ()
(render #P"about.html"))
(in-package :cl-user)
(defpackage super-rentals.web
(:use :cl
:caveman2
:super-rentals.config
:super-rentals.view
:super-rentals.db
:datafly
:sxql)
(:export :*web*))
(in-package :super-rentals.web)
;; for @route annotation
(syntax:use-syntax :annot)
;;
;; Application
(defclass <web> (<app>) ())
(defvar *web* (make-instance '<web>))
(clear-routing-rules *web*)
;;
;; Routing rules
(defroute "/" ()
(render #P"index.html"))
(defroute "/about" ()
(render #P"about.html"))
;;
;; Error pages
(defmethod on-exception ((app <web>) (code (eql 404)))
(declare (ignore app))
(merge-pathnames #P"_errors/404.html"
*template-directory*))
templates
folder situated at the root of your project. Just create a new file about.html
and some HTML to it.<h1>About page</h1>
<p>This is the about page</p>
web.lisp
file, reload your changes to reflect the newly created routes to take effect. In Emacs, you can just do C-c C-l
which is Ctrl-c
and then Ctrl-l
to compile your file and load it into the SLIME environment. Then go to your browser and visit the url http://localhost:3000/about
to view your new page. The beauty of using a framework like Caveman is whatever changes you make inside your templates, the HTML files, will be automatically reflected in the browser. All you need to do is to just refresh the page.main.css
under the static/css
folder in the root of your project. You can add any custom css properties and declarations to style your web pages./* static/css/main.css */
h1 {
color: red;
}
h1
tags to have red color text. Now we have played around enough to understand our project structure and developed a very simple web app, it's time to deploy our app in the cloud so that we can share it with others. templates/index.html
file. This is the home page template for our app.{% extends "layouts/default.html" %}
{% block title %}Lisp for the web{% endblock %}
{% block content %}
<div id="main">
<h1>Lisp for the Web</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
<p>Source Code: <a href="https://github.com/rajasegar/lisp-for-the-web">Github</a></p>
</div>
{% endblock %}
heroku apps:create my-awesome-app
heroku-buildpack-roswell
created by gos-k. So how we are going to use this buildpack. We need to pass a flag --buildpack
with the url of the buildpack to our heroku command like this.heroku apps:create my-awesome-app --buildpack https://github.com/gos-k/heroku-buildpack-roswell
clack
sbcl-bin
clack
clackup
command.web: clackup --port $PORT --address 0.0.0.0 app.lisp
--port
flag to use the env variable PORT
assigned by Heroku for your project and use the --address
flag to use the 0.0.0.0
address instead of localhost
. This flag is very important otherwise your app will throw a startup error saying that the application is not bound to the port within the specified timeout. And finally we supply our main file app.lisp
for clack./app
folder in Heroku once the build is completed and the project is ready to load. We will add this line to the top, in our app.lisp
file in the root of the project folder.(require "asdf")
..asd
extension where you can specify some details about your project. It is like a project manifest file similar to package.json
for Node.js and cargo.toml
for Rust.;; app.lisp
(push #p"/app/" asdf:*central-registry*)
git push heroku master
19