Fork me on GitHub
#beginners
<
2023-01-06
>
bschrag03:01:01

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))
    true))
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?

bschrag15:01:56

Ok, I have a reasonably straightforward work-around.

hiredman04:01:32

Code with free names won't compile at all

bschrag15:01:11

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

hiredman04:01:38

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

Stuart16:01:58

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. ?

moe16:01:11

Would something like this work for you? https://www.npmjs.com/package/json-mock-api

moe16:01:59

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

Stuart16:01:25

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

moe16:01:02

looks pretty darn simple

👍 2
Stuart16:01:12

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

dharrigan16:01:57

I've used this in the past

👍 2
dharrigan16:01:20

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

moe16:01:53

miniserve has the benefit of actually performing writes

flowthing17:01:01

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.

2
skylize20:01:18

If you're okay with JS instead of CLJ(S), and only intend to serve JSON: It doesn't get any easier than https://github.com/typicode/json-server. • Been around almost as long as Node.js. • Battle-tested by serving up https://jsonplaceholder.typicode.com/ 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.

mister_m23:01:46

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

dorab00:01:30

See if some works for you.

mister_m00:01:47

yes that should work, thanks

icemanmelting15:01:31

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