lcn2 / calc

C-style arbitrary precision calculator
http://www.isthe.com/chongo/tech/comp/calc/index.html
Other
346 stars 52 forks source link

Enhancement: read/write json #121

Closed ghost closed 10 months ago

ghost commented 11 months ago

Read/Write JSON.

lcn2 commented 11 months ago

What would be the purpose for writing JSON files? What should happen when a JSON file is read by calc?

Can you give a usage case for JSON file reading and writing, and perhaps an example of why it would be useful for calc to read and write JSON files?

UPDATE 0

We see that the person submitting this enhancement is no longer a valid GitHub user.

Anyone who might have an idea is welcome to try and answer our above questions.

kcrossen commented 11 months ago

There are likely a few open source packages that meet this need. In Python, Simple JSON traverses via recursive descent a dict object, generating the serializable text form. Notably, this does not handle date/time/datetime data despite the existence of an official ISO format. This deficiency is trivially fixed. Have never researched this for C/C++.

lcn2 commented 11 months ago

Reading JSON in calc probably raises more questions.

Consider this valid JSON:

{
    "foo" : [{
        "foo" : [{
            "bar" : 42
        }]
    }]
}

Say somehow that calc "read" that JSON. What do you expect to happen in calc as a result?

Or consider this valid JSON:

[ 200, 200.0, 2e2, 200.000, 2.0e2, 0.2e3, 20.0e1 ]

Say somehow that calc "read" that JSON. What do you expect to happen in calc as a result?

Or for a more involved use case, consider this valid JSON:

{
    "number":42,
    "value":"value",
    "number_as_str":"42",
    "answer to life, the universe and everything" : 42,
    "panic":false,
    "panic":true,
    "false":true,
    "true":false,
    "killers":"Vogons",
    "Killers":"Vogons",
    "hitchhikers" : [
        {
        "person" : [
            {
            "name" : "Arthur Dent",
            "race" : "human",
            "status" : "dead",
            "alive": false
            },
            {
            "name": "Ford Prefect",
            "race" : "Betelgeusian",
            "status" : "dead",
            "alive": false
            }
        ]
        }
    ],
    "Vogons" : [
        {
        "alien" : [
            {
            "name" : "Prostetnic Vogon Jeltz",
            "job": "Destroy Earth"
            }
        ]
        }
    ],
    "value" : [ "value", "value", "value" ],
    "hitch-hikers":"hitchhikers"
}

What would one expect to happen if calc read that JSON?

It is one thing to say "have calc read JSON". It is another thing to explain what calc would do having read some JSON.

And calc has general I/O routines to write anything. Sure, one could add a cal/write_json.cal resource file to make it easier to write JSON syntax.

Without a general use case to READ JSON and do after calc reads JSON there isn't a good enough reason to justify the effort to integrate JSON with calc, let alone have a explanation of what calc should do with valid JSON that it has "read".

UPDATE 0

Hopefully the above will spur someone to try and answer the questions above. Should we receive replies, we would be happy to explore further.

UPDATE 1

Should we understand the JSON use case, we would be happy to consider adding JSON read/write support to the calc view TODO list.

We will leave this issue open thru the end of 2023 to see if we can better understand the request.

lcn2 commented 11 months ago

Sorry that you, @kcrossen, found the above questions "harsh".

kcrossen commented 11 months ago

Can you see that the following:

Reluctantly, given a lack on direct response our questions about "protect" inheritance from @kcrossen https://github.com/kcrossen, we have removed a related calc v3 TODO.

Sadly we did not see (or somehow missed) a direct replies to our questions about the feature request. So we have put tbudren on @kcrossen https://github.com/kcrossen to code and submit changes for whatever his "protect" inheritance is via a GitHub Pull request https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request. (Click the link for GitHub pull request info).

might be interpreted by me as impatient, judgemental, sarcastic, hair-trigger, ... potentially hostile? Read again our (many months ago) previous exchange. These current follow a similar (though less extreme) pattern.

We may value differing qualities in relationships. For me kindness and compassion are primary, especially as I treat others. I've got some way left to stumble down that road.

Respectfully, Ken

On Wed, Oct 18, 2023, 10:13 PM Landon Curt Noll @.***> wrote:

Sorry that you, @kcrossen https://github.com/kcrossen, found the above questions "hostile".

— Reply to this email directly, view it on GitHub https://github.com/lcn2/calc/issues/121#issuecomment-1769780547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO4OEFH2BXGNXX2VVYD5PDYACEFHAVCNFSM6AAAAAA6DVTHTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRZG44DANJUG4 . You are receiving this because you were mentioned.Message ID: @.***>

pmetzger commented 10 months ago

I don't see why one would want this. FWIW, the person who posted the original request seems to have done an awful lot of inexplicable hit and run tickets on various things.

lcn2 commented 10 months ago

I don't see why one would want this. FWIW, the person who posted the original request seems to have done an awful lot of inexplicable hit and run tickets on various things.

Thank you 🙏, @pmetzger.

JSON support seems to have little value to offer calc.

UPDATE 0a

We received suggestions that the "inexplicable hit and run tickets on various things" from the ghost 👻 account was due to a user who would open a new account, post odd things and odd pull requests, and the close the new account (turning the new account into a ghost 👻 account).

The user would then post to sympathetic comments the odd suggestions and odd pull requests: perhaps in the hopes that their sympathetic comments would help elevate the ghosted 👻accounts actions? Hard to say for sure why they might have done that.

Steps were taken to try and prevent future odd things from the non-ghost account.

We are cloning this request.