fukamachi / caveman

Lightweight web application framework for Common Lisp.
http://8arrow.org/caveman/
775 stars 63 forks source link

Default values for *session*? #145

Closed floren closed 4 weeks ago

floren commented 4 weeks ago

I'd like to define defaults for some fields in *session*. What's the right way to do this? Currently I've got macros defined like this:

(defmacro session-foo ()
    `(or (gethash :foo *session*)
        "default"))

but perhaps there's a better way? I'm still learning/relearning a lot of stuff in CL so please excuse me if I've missed something obvious.

fukamachi commented 4 weeks ago

I'm not sure what the problem is with it, but you can also write it like (gethash:foo *session* "default").

vindarel commented 4 weeks ago

(and why a macro? It looks exactly like a function)

floren commented 4 weeks ago

I'm not sure what the problem is with it, but you can also write it like (gethash:foo *session* "default").

I should have looked at the docs for gethash first, this would work perfectly well. Thank you.

(and why a macro? It looks exactly like a function)

So I don't have to pass *session* as an argument to the function when I call it, but can instead just let ((foo (session-foo)))

(I see that the simplified example I gave was missing the backtick, that's probably what you meant)