Manuel Simoni on CL's control flow primitives
Manuel Simoni dusts his Axis of Eval blog off and writes about Common Lisp's BLOCK / RETURN-FROM and UNWIND-PROTECT. A summary for non-Lispers.
Manuel Simoni dusts his Axis of Eval blog off and writes about Common Lisp's BLOCK / RETURN-FROM and UNWIND-PROTECT. A summary for non-Lispers.
afiŝis Luís je 14:56 0 komentoj kat.: en, lisp
As many Lisp programmers may remember, Reddit was initially written in Common Lisp. Then, in late 2005, it was rewritten in Python. Much discussion ensued. Steve Huffman (aka spez, current CEO of Reddit) wrote about why they switched to Python. The late Aaron Swartz also wrote Rewriting Reddit, focusing on the Python side of things.
Last week, that original, Common Lisp version of Reddit was published on GitHub: reddit-archive/reddit1.0. There's no documentation, but we know from the articles above that it ran on CMUCL. reddit.asd is perhaps a good entry point, where we can see it used TBNL, CL-WHO and CLSQL, a common toolset at the time.
It's missing various bits of static HTML, CSS and JS, so I don't think you can actually run this website without a fair bit of scrapping and stitching from the Wayback Machine. The code is quite readable and clean. It's not terribly interesting, since it's a fairly simple website. Still, it's a website that grew to become the 6th most visited worldwide (with 542 million monthly visitors) and now has 230 employees, says Wikipedia, so it's nice to see what it looked like at the very beginning.
Thanks to Polos Ruetz, you can now play with Common Lisp directly on your Android phone. All you need to do is install CL REPL from the Google Play Store. CL REPL is one of the examples part of EQL5-Android which is built on top of EQL5, a project that marries ECL with Qt.
CL REPL
A Common Lisp REPL with command line and history, plus a simple editor with syntax highlighting, simple visual paren-matching, a file dialog for opening/saving files, and a simple debug dialog. It uses the ECL implementation for the Lisp side, and Qt5/QML for the UI. This is an open source project (see EQL5-Android).
(via @dk_jackdaniel)
afiŝis Luís je 22:37 7 komentoj kat.: en, lisp
Zach's Querying plists blog post showcases a neat little querying DSL for plists. I couldn't shake the feeling that it looked an awful lot like pattern matching. I've often been impressed by optima, but I barely get to use it, so I thought I should try and see what querying plists looked like using pattern matching.
Here's what I came up with. Zach's example
becomes:(query-plists '(:and (:= :first-name "Zach") (:= :state "ME") (:not (:= :last-name "Beane"))) *people*)
(remove-if-not (lambda-match ((plist :first-name "Zach" :state "ME" :last-name (not "Beane")) t)) *people*)
all we have to do is swap(defclass person () ((first-name :initarg :first-name) (last-name :initarg :last-name) (state :initarg :state)))
plist
with the class name person
and we're all set:(remove-if-not (lambda-match ((person :first-name "Zach" :state "ME" :last-name (not "Beane")) t)) *people*)
query-plists
because, AFAICT, optima's patterns are not first-class objects but perhaps we can cheat a little bit.;; naming things is hard. :-/ (defmacro matchp (pattern) `(lambda-match (,pattern t))) (defun filter (predicate list) (remove-if-not predicate list)) (filter (matchp (plist :first-name "Zach" :state "ME" :last-name (not "Beane"))) *people*)
matchp
is a lousy abstraction. ;-)
SLIME's just got a new contrib called slime-macrostep
, courtesy of Jon Oddie who also wrote the underlying macrostep package.
And what is slime-macrostep
? It's an interactive inline macro-expander. Have a look:
WITH-FOREIGN-OBJECT
form, then I expand the WITH-ALIEN
form, but regret it and collapse it back. Then I proceed to expand everything else, including compiler macros!slime-macrostep
is that the expansions are annotated to show which forms are further expandable and macrostep-expand
will jump automatically to the next expandable form. That's what makes it a stepper: pressing e repeadly will step through the macroexpansion. Plus, it expands macrolets!slime-fancy
meta contrib. Feedback is most welcome.
afiŝis Luís je 00:51 0 komentoj kat.: en, lisp
Edi Weitz, author of things like CL-PPCRE and Hunchentoot (amongst many other pieces of ediware), has just published a new book, “Common Lisp Recipes: A Problem-Solution Approach”. I've ordered mine. Get yours from Apress or a European Amazon store.
Common Lisp Recipes is a collection of solutions to problems and answers to questions you are likely to encounter when writing real-world applications in Common Lisp. Written by an author who has used Common Lisp in many successful commercial projects over more than a decade, this book is the first Common Lisp book which covers areas as diverse as web programming, databases, graphical user interfaces, communication with other programming languages, multi-processing, and mobile devices as well as debugging techniques and optimization, to name just a few. It is organized around specific problems or questions each followed by ready-to-use example solutions and clear explanations of the concepts involved, plus pointers to alternatives and more information. Each recipe can be read independently of the others and thus the book will hopefully earn a special place on your bookshelf as a reference work you always want to have within reach.
Common Lisp Recipes is aimed at programmers who are already familiar with Common Lisp to a certain extent but do not yet have the experience you typically only get from years of hacking in a specific computer language. It is written in a style that mixes hands-on no-frills pragmatism with precise information and prudent mentorship.
If you feel attracted to Common Lisp's mix of breathtaking features and down-to-earth utilitarianism, you'll also like this book.
afiŝis Luís je 11:18 2 komentoj kat.: en, lisp
As promised, I'll describe my solution to the Pretty Printer Puzzle I proposed last week. To recap, we wish to pretty print a Lisp form to a string and identify the textual positions of arbitrary subforms therein.
CAR
of each subform with some unique token (a gensym should be close enough), (2) pretty-print that, (3) find the token positions and replace them with the original CAR
s.#\(
reader-macro and doing the reading from a so-called form-tracking-stream.readtable
. So, we try and instrument it like in the previous approach. Each time a list is about to be pretty-printed, we store the current position in the output stream.pprint-dispatch-table
to wrap lists with some token identifying the subform being printed. (I decided to use the unicode range U+E000..U+F8FF
which is reserved for private-use, which seemed neat.) This messes up the pretty-printing a little bit, but not too much, it turns out.afiŝis Luís je 17:06 0 komentoj kat.: en, lisp