Lisp Webtales Chapter 5 - how to get it working

M

mwal

Guest
Following on from my solution to getting the code in chapter 4 working as here, I need some help debugging the application "linkdemo" in Chapter 5 of lisp webtales.

I've carefully typed in all the code & eliminated one typo contained in the book.

In CCL if I issue (ql:quickload "linkdemo") I get this:

CCL is free software. It is distributed under the terms of the Apache
Licence, Version 2.0.
? (ql:quickload "linkdemo")
To load "linkdemo":
Load 1 ASDF system:
linkdemo
; Loading "linkdemo"
.
;;; Checking for wide character support... yes, using code points.
;;; Checking for wide character support... yes, using code points.
;;; Building Closure with CHARACTER RUNES
.
> Error: The value NIL is not of the expected type STRING.
> While executing: ENSURE-SIMPLE-STRING, in process listener(1).
> Type :pOP to abort, :R for a list of available restarts.
> Type :? for other options.
1 >


If I type :R I get this:

1 > :R
> Type :)C <n>) to invoke one of the following restarts:
0. Return to break level 1.
1. #<RESTART ABORT-BREAK #x133AEDD>
2. Retry compiling #P"/Users/m/quicklisp/local-projects/linkdemo/defmodule.lisp"
3. Skip compiling #P"/Users/m/quicklisp/local-projects/linkdemo/defmodule.lisp"
4. Retry compiling #<CL-SOURCE-FILE "linkdemo" "defmodule">.
5. Continue, treating compiling #<CL-SOURCE-FILE "linkdemo" "defmodule"> as having been successful.
6. Retry ASDF operation.
7. Retry ASDF operation after resetting the configuration.
8. Give up on "linkdemo"
9. Return to toplevel.
10. #<RESTART ABORT-BREAK #x133C53D>
11. Reset this thread
12. Kill this thread
1 >


from which I infer the error is in defmodule.lisp.

Then, I found that if I comment out the following entire block in defmodule.lisp:

(restas:define-policy datastore
:)interface-package #:linkdemo.policy.datastore)
:)interface-method-template "DATASTORE-~A")
:)internal-package #:linkdemo.datastore)

(define-method init ()
"Initiate the datastore")

(define-method find-user (username)
"Find the user by username")

(define-method auth-user (username password)
"Check if a user exists and has the supplied password")

(define-method register-user (username password)
"Register a new user")

(define-method upvoted-p (link-id username)
"Check if a user has upvoted a link")

(define-method upvote (link-id user)
"Upvote a link")

(define-method post-link (url title user)
"Post a new link")

(define-method get-all-links (&optional user)
"Get all of the links in the datastore")

(define-method upvote-count (link-id)
"Get the number of upvotes for a given link"))


then re-issue (ql:quickload "linkdemo"), I get no error.

(Also, if I then comment it in again, and reload with quickload, I also get no error. I'm not sure what's happening there or the reason for that.)

Whether I've quickloaded with or without the offending section above, I am able to explore a function within pg-datastore.lisp, like so:

1 > (linkdemo.pg-datastore::hash-password "42")
:)PASSWORD-HASH "71a8c8f54475acb5afee9eae061fa5f7ba838215f280259855e59a7c0ac768f8" :SALT "a283c5328f67c36595dd7277c54342f3")


It doesn't seem possible to try to boot up the server yet, as code from Chapter 6 is needed before it's fully functional (we have no routes yet, just the DAO layer with postmodern).

So not sure how to proceed with testing the code in Ch.5 / debugging this. The error seems to be something in restas itself - maybe.

Seeking any educated guesses on how to proceed.

The error can be reproduced by simply doing (ql:quickload "restas") followed by evaluating the block given above. This gives Error: The value NIL is not of the expected type STRING. I am new to using the code of others in LISP, so I'm a bit stuck on how to proceed.

More info: it is the calls to define-method that are giving this error, and the source is the file policy.lisp here, which is a bit beyond me at the moment.

I tried sbcl too:

* (ql:quickload "linkdemo")
To load "linkdemo":
Load 1 ASDF system:
linkdemo
; Loading "linkdemo"
.
;;; Checking for wide character support... WARNING: Lisp implementation doesn't use UTF-16, but accepts surrogate code points.
yes, using code points.
;;; Building Closure with CHARACTER RUNES
.........
debugger invoked on a SB-KERNEL:CASE-FAILURE in thread
#<THREAD "main thread" RUNNING {10004F04C3}>:
NIL fell through ETYPECASE expression.
Wanted one of (SIMPLE-STRING STRING SB-FORMAT::FMT-CONTROL).

...

(SB-FORMAT::%FORMAT #<SB-IMPL::CHARACTER-STRING-OSTREAM {1003BD1673}> NIL ("UPVOTE-COUNT") ("UPVOTE-COUNT"))
0]

Continue reading...
 
Top