Destructuring macro for ST-JSON JSO object -


There is another question about JSON encoding in my normal Lisp. I settled on ST-JSON as my tool. I am able to get a JSO object with JSON data and I am using all fields with st-json: getjso . I wanted to write a macro similar to theory in destructuring-bind which would provide local binding to the variable named after the JSON field (since then I suspected that this is a good idea, but it is a Different question). I came up with the following:

  (defmacro destruct-jso (jso and body body) (let's value values) (st-json: mapjso # '(lambda (key value) (push ) () Value (push value value) jso) `(demolition-dam, keys, value, body))   

But when I call it the JSO object , I get the error value PARAMS is not the required type structure. Can anyone explain this to me, where is PARAMS object?

Thank you.

Obviously, you have destruct-jso like this:

  (let's (params (St-Jason: reading-jason-to-string "{\" foo \ ": 42, \" bar \ ": \" baz \ "}"))) ( Rebel-JSO Parameters (List Foo Bar)))   

However, destruct-jso , becomes a macro, becomes the macro extension handled over time, long ago JSON parsed parameters Your macro has been passed as a symbol without evaluation; And even if an attempt was made to evaluate it, it would be unbound.

So, if you want to write destruct-jso , then you will need a list of keys at the time of macro expansion. You can pass the list in a normal way:

  & gt; (Defmacro destructure-jso-2 (Works Jason and Body Body) `(, (Map Maker # '(Lamb) (list var` (getjso, (string-downcase), jsn)) Vars ), @Body)) Distinctive-JSO-2 & gt; ((Param (st-jeson: reading-jason-to-string) {\ "foo \": 42, \ "bar \": \ "baz \"}))) (district-jso-2 (foo bar) ) Use the "Template" JSON to create a mapping:   

Parameters (list foo bar)) (42 "punk")

pre> & gt; (Demetrakro Structure - JS-3 (Template Jason and Body Body) (Penalties) (St-Jason: Mapz # '(Lambda (Head Val) (Announce) (Pukara (List) (Push (List (Intern (String- Ups (key)) (`jezo, key, jsno) binding) (ST-JSN: reading-jsn-to-scheme template))` (let's, binding, @ body))) Districts -JSO-3 & gt; (( Mercury (St -Jeson: read-jsn-string "{\" foo "" 42: "\" bar \ ": \" baz \ "}"))) (district-jso-3 "{\" foo " : Nul L, \ "bar \": null} "parameters (list foo bar)) (42" hawk ")

Here, variable bindings first (template) JSON, value from second. JSON macroexpansion is parsed at time, parameter JSON every time your code is executed.

Whether any of these are a useful way for you or not, I do not know.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -