r/ProgrammingLanguages • DQ • Jul 16 '26

New Languages: Standardizing API, Examples ?

Hi, some of you are developing new general-purpose programming languages here. When the language is ready, you have to develop standard APIs, like file-io, json-handling etc. Users, and you would have benefit, when the APIs would be same/similar across multiple different languages.

Standardizing some Examples would allow the users to compare languages more easily.

What do you think?

11 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/Mean-Decision-3502 DQ Jul 16 '26

I'm at the beginning of lib/API development with the DQ, seeing the Seed7 we have some similar concepts. For example (the debated) block specific enders. Your Seed7 work is very impressive.

DQ is my view, how I see the ideal language (with acceptable compromises).

To stay in this topic: For example a standard example for JSON writing, reading and examining could help, I think.

Mine is not perfect for sure, this is what I got so far:

use print
use json
use strutils

const TEST_FILE_NAME : cstring = 'test.json'

function WriteTest():
    PrintLn('JSON Writing Test')

    var jroot <- OJson()
    var jns : OJson
    var jnn : OJson
    var jno : OJson
    var jn : OJson

    jns = jroot.AddStr('strnode', 'hello')
    jnn = jroot.AddNum('numnode', 3.14)
    jn  = jroot.AddBool('boolnode', true)
    jno = jroot.AddObj('objnode')

    jn = jno.AddStr('substr', 'abc')
    jn = jno.AddNum('subnum', 42)
    jno.AddBool('subbool', false)
    jno.AddNull('subnull')

    jn.as_num = 46

    jn = jroot.AddArr('arrnode')
    jn.AddNum('', 1)
    jn.AddNum('', 2)
    jn.AddNum('', 3)

    jroot.ForcePath('first.second.third').as_str = 'deepvalue'

    PrintLn('"{}" = "{}"', [jns.name, jns.as_str])
    PrintLn('"{}" = "{}"', [jnn.name, jnn.as_num])

    PrintLn('as json compact:')
    PrintLn(jroot.json)
    PrintLn('as json pretty:')
    PrintLn(jroot.pretty_json)

    jroot.SaveToFile(TEST_FILE_NAME, true)
    PrintLn()
endfunc

function ReadTest():
    PrintLn('JSON Read Test')

    var jroot <- OJson()
    var jn : OJson
    var jv : OJson

    jroot.LoadFromFile(TEST_FILE_NAME)
    PrintLn('as json pretty:')
    PrintLn(jroot.pretty_json)

    PrintLn('arrnode:')
    if jroot.Find('arrnode', jn):
        PrintLn('  arrnode.as_str: {}', [jn.as_str])
        PrintLn('iterating array node:')
        for i : int = 0  count jn.length:
            jv = jn[i]
            PrintLn('  {}. = {}', [i, jv.as_num])
        endfor
    else:
        PrintLn('"arrnode" was not found !')
    endif

    PrintLn('objnode.subnum:')
    if jroot.Find('objnode.subnum', jv):
        PrintLn('  = {}', [jv.as_num])
    else:
        PrintLn('"objnode.subnum" was not found !')
    endif

    if jroot.Find('objnode', jn):
        PrintLn('Iterating objnode:')
        for i : int = 0  count jn.length:
            jv = jn[i]
            PrintLn('  {}.: "{}" = {}', [i, jv.name, jv.json])
        endfor
    else:
        PrintLn('"objnode" was not found !')
    endif

    PrintLn()
endfunc

function *Main() -> int:
    PrintLn('DQ JSON test')
    PrintLn('Test file name: "{}"', [TEST_FILE_NAME])
    WriteTest()
    ReadTest()
    return 0
endfunc

So again you can separate two things here, the API and the example.