Fork me on GitHub

Is it possible to guard against evaluating an expression that may include an unresolvable symbol? I'd intended the following (automatically generated) code to return true, because *honk has no value (in the let) but can't get past the syntax error from the fact that (unquoted) *honk is unresolvable (can't even wrap it in try.)

(let [*quack "like a duck"
      bindings (quote {*quack "like a duck"})]
  (if (get bindings (quote *honk))
    (not (= *honk *quack))
I'm generating the code before I know whether I'll have bindings (for optional *vars). Does Clojure have a way around this, or do I need to re-architect?


Ok, I have a reasonably straightforward work-around.


Code with free names won't compile at all


Ok, I have a reasonably straightforward work-around. Thanks.


You can wrap the call to eval in a try/catch because that is where the exception is, not at runtime when the code is running


I want a very simple API, that will always only run on my local machine. I really only need a couple of endoints, a GET and a POST and I'm happy for it to just read / write a static json file on my HD. I'd like it to be pretty small and simple. What's a good clojure package to do this that doesn't need a lot of setup and boilerplate. I don't care about auth or CORS or anything like that at all. ?


Would something like this work for you?


(it's not a Clojure package, but maybe that doesn't matter)


I would have liked it to be clojure, but I'm happy with JS / Python if its really simple and quick to fire up


looks pretty darn simple

👍 2

I've written a little SPA in clojurescript for personal use to help me track a thing, but I've decided I want it to persist stuff now rather than trust cookies. SO I figure I'll just throw some json at an endpoint and write it to disk / read it from disk


I've used this in the past

👍 2

It doesn't really care what you throw at it, could be json, txt, binary, whatever...


miniserve has the benefit of actually performing writes


Not sure if that qualifies as small, though, what with the number of deps.

Jacob O'Bryant17:01:50

you could write a babashka script to do this pretty easily, with the (built in?) http kit webserver.


If you're okay with JS instead of CLJ(S), and only intend to serve JSON: It doesn't get any easier than • Been around almost as long as Node.js. • Battle-tested by serving up to the public for years. • Pretty extensive API options for free: pagination, sorting, mutation HTTP verbs like PUT and DELETE, etc. • Extensible with Express middleware + any arbitrary JS, if you outgrow the built-in features.


is there a function that will return an item from a seq or nil if it isn't found? It looks like core/find only works with maps? failing at searching rn


See if some works for you.


yes that should work, thanks


Either some, or use filter and check the filter result to check if there are elements in the resulting seq.