Re: Yet Another JSON Parser

2025-01-31 Thread GB
Hey Lindsay,

Good thing you're having fun writing useful projects!

I wrote a small parser myself for picolisp so here's a few points for
improvement:

- Data on json.org is not a full spec, I recommend using ECMA404 or
RFC8259, as they specify behaviours way more accurately. For example, I'm
not sure if i saw if it can parse UTF-16 surrogate pairs (this lets you
parse encoded emojis), which is specified in the RFC.
- Look into `loop`, it can make your code quite a bit neater. For example
most of the NotDone flags could be removed by using loop conditionals.
- You can probably use make and link in more cases, but I'm not sure if
it's better than current approach, @abu probably knows.
- Check out https://picolisp.com/wiki/?simplerfc8259json if you want some
inspiration (maybe into direction of "oh god this is horrible", I don't
mind :D)

Have fun!
Geri

On Fri, Jan 31, 2025, 21:45 Lindsay Lawrence 
wrote:

> Hi,
>
> I added another page to the Examples section of the wiki.
>
> https://picolisp.com/wiki/?Documentation#yajson
>
> Aside from the code, I included several examples of use, along with
> 'bench' times and a somewhat detailed description. All examples can be run
> from the repl and more can be found on the linked github page.
>
> As a beginning/intermediate picolisp programmer, I've found it can be a
> challenge to progress forward from 'academic' code, and simple examples, to
> more complex applications, to discovering new insight into functionality
> and how to apply the language. Developing bottom-up from the repl is a
> great way to do that. Hopefully, the included examples are useful to others.
>
> /Lindsay
>
>
>
>


Re: New JSON library

2024-11-23 Thread GB
As it always happens, I had found a bug in the json-read-from-string
function an hour after sending the source code.

As per Abu's recommendation, I've put the source code onto wiki alongside a
writeup about it:
https://picolisp.com/wiki/?simple-rfc8259-json

BR,
geri

On Sat, Nov 23, 2024, 11:29 GB  wrote:

> Hello everyone,
>
> I had some problems with data representation in builtin json.l and decided
> to write my own little version.
>
> With an exception of not being able to represent a null byte in strings,
> RFC8259 json standard is fully supported.
>
> I'm also slowly working on a more strict version of the parser and if
> there's interest I'll post it later as well, but it won't look anywhere as
> nice.
>
> Feedback is welcome.
>
> BR,
> Geri
>


Subscribe

2024-11-23 Thread GB



New JSON library

2024-11-23 Thread GB
Hello everyone,

I had some problems with data representation in builtin json.l and decided
to write my own little version.

With an exception of not being able to represent a null byte in strings,
RFC8259 json standard is fully supported.

I'm also slowly working on a more strict version of the parser and if
there's interest I'll post it later as well, but it won't look anywhere as
nice.

Feedback is welcome.

BR,
Geri


mini8259.l
Description: Binary data


Re: How do I distinguish a list from cons pair?

2025-02-11 Thread GB
Hey,

I'm curious myself honestly.

Lists are kind of a virtual type, it's just a bunch of cons cells in a
sequencial pattern.

I think you'd need to write your own function that walks the list to see if
its proper or improper (ends with non-nil).

Best regards,
Geri

On Wed, Feb 12, 2025, 08:28 Lindsay Lawrence 
wrote:

> Is there a way to distinguish a list from a cons pair?
>
> The 'pair' function does not seem to do what I want.
>
> : (pair (cons 1 2))
> -> (1 . 2)
> : (pair (list 1 2))
> -> (1 2)
> : (pair (list 1 (2 3)))
> -> (1 (2 3))
> : (pair (cons 1 (2 3)))
> -> (1 2 3)
>
> I would like to be able to distinguish the cons pair structure from 'list'
>
> /Lindsay
>
> : (view (cons 1 2))
> +-- 1
> |
> 2
>
> : (view (list 1 2))
> +-- 1
> |
> +-- 2
>
> : (view (cons 1 (2 3)))
> +-- 1
> |
> +-- 2
> |
> +-- 3
>
> : (view (list 1 (2 3)))
> +-- 1
> |
> +---+-- 2
> |
> +-- 3
>
>>