Destructuring macro for ST-JSON JSO object -
There is another question about JSON encoding in my normal Lisp. I settled on But when I call it the Thank you. Obviously, you have However, So, if you want to write Parameters (list foo bar)) (42 "punk") pre> Here, variable bindings first (template) JSON, value from second. JSON macroexpansion is parsed at time, Whether any of these are a useful way for you or not, I do not know. 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))
JSO object , I get the error
value PARAMS is not the required type structure. Can anyone explain this to me, where is
PARAMS object?
destruct-jso like this:
(let's (params (St-Jason: reading-jason-to-string "{\" foo \ ": 42, \" bar \ ": \" baz \ "}"))) ( Rebel-JSO Parameters (List Foo Bar)))
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.
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:
& 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 ")
parameter JSON every time your code is executed.
Comments
Post a Comment