Skip to content

Commit

Permalink
Add in a basic function to convert JSON from the Parson's block to Ma…
Browse files Browse the repository at this point in the history
…xima proof functions.
  • Loading branch information
sangwinc committed Oct 30, 2023
1 parent 39adc5a commit 9642039
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions stack/maxima/contrib/prooflib.mac
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ count_matches(l1, l2):= if emptyp(l1) then 0 else
*/
first_diff(ex):=if is(length(ex)=1) then [] else append([first(ex)-second(ex)], list_diff(rest(ex)));

/******************************************************************/
/* */
/* STACK Parson's block functions */
/* */
/******************************************************************/

/*
* Take the JSON from STACK Parson's block and return a proof function.
*/
proof_parsons_interpret(st) := block([pf],
pf:stackjson_parse(st),
pf:apply(proof, stackmap_get(pf, "used"))
);
s_test_case(proof_parsons_interpret("{\"used\":[\"0\",\"3\",\"5\"],\"available\":[\"1\",\"2\",\"4\",\"6\",\"7\"]}"), proof("0","3","5"));

/******************************************************************/
/* */
/* Display functions */
Expand Down
4 changes: 2 additions & 2 deletions stack/maxima/stackstrings.mac
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ stackjson_parse(json) := block([r,tmp,tokens,mode,i,lastslash,c,starts,nt,k,v,dm
/* Change this to actual sublist as this is not the way to do it... */
while ev(is(i<last(starts)), simp) do (nt:append(nt,[tokens[i]]), i:ev(i+1, simp)),
if is(tokens[last(starts)]=_stackjson_tokens_list_open) then (
i:last(starts)+1,
i:ev(last(starts)+1, simp),
while not is(tokens[i]=_stackjson_tokens_list_close) do (
if not is(tokens[i]=_stackjson_tokens_list_sep) then r:append(r,[tokens[i]]),
i:ev(i+1, simp)
Expand All @@ -150,7 +150,7 @@ stackjson_parse(json) := block([r,tmp,tokens,mode,i,lastslash,c,starts,nt,k,v,dm
)
),
nt:append(nt,[r]),
i:i+1,
i:ev(i+1, simp),
/* Change this to actual sublist as this is not the way to do it... */
while ev(is(i<length(tokens)+1), simp) do (nt:append(nt,[tokens[i]]),i:ev(i+1, simp)),
if ev(is(length(nt)<length(tokens)), simp) then dm:0,
Expand Down

0 comments on commit 9642039

Please sign in to comment.