<aw->
handles empty arrays and empty objects, as well as boolean true/false, handles null, etc..
<aw->
the only thing it doesn't do are floats for obvious reasons
<geri>
hadn't, didnt know about it xd
<geri>
aha, if its an array first element is T
<geri>
much simpler
<geri>
and takes up less space
<geri>
explain.md points to itself saying its about older version of the library btw
<aw->
oh haha i didn't notice that about explain.md
<aw->
it should point to explain_v3
<aw->
thanks
<geri>
np
<geri>
@lib/json.l probably still needs an overhaul or replacement though tbh
<geri>
its fun how almost everyone has their own formatting style when writing picolisp xd
<geri>
also probably silly but i think encode function should be capable of encoding symbols and numbers as well
<aw->
?
<geri>
your json-encode can only do arrays or objects
<geri>
like at top level
<geri>
if that's for simplicity honestly fair enough lol
<aw->
what
<aw->
did you read the README?
<aw->
JSON Specification
<aw->
This library conforms to the ECMA-404 The JSON Data Interchange Standard, except for the following semantic exceptions:
<aw->
[Numbers] Scientific (floating point, fractional, exponential) numbers (ex: 3.7e-5) are not accepted. They must be provided as strings (ex: "3.7e-5").
<aw->
where did you see that it only supports arrays and objects?
<geri>
i thought 7159 was when it was still array or object
<geri>
didn't know about (key), neat
<geri>
what was the function to read N utf-8 encoded characters in?
<geri>
i guess (char) in a loop
<geri>
nah not accurate, it has to be bytes + parsing number to a string, hmm
<geri>
abu[7]: documentation for buf doesn't explain units for 'cnt, im guessing its bytes
<geri>
i could maybe use buf + struct + Cffi call to read N bytes and return them as a string/transient symbol, but if rd is a thing then that should be possible without it...
<geri>
i probably need rd + struct but i cant get it working...
<abu[7]>
Good morning geri + aw-!
<abu[7]>
Good discussion :)
<geri>
)
<abu[7]>
geri: yes, the size for 'buf' is in bytes
<geri>
trying to convert (rd 20) to a string rn
<abu[7]>
a bignÜm?
<geri>
yes
<geri>
doubt itll ever be a short num
<abu[7]>
String from buffer is (buf P 20 ... (struct P 'S)) iirc
<abu[7]>
But you must put the num into the buffer with 'byte' then (until (=0 N) (byte (++ P) (& N 255)) (setq N (>> N 8)))
<abu[7]>
Better (do 20 (byte (++ P) (rd 1)))
<abu[7]>
or (%@ "read" 'I P 20)
<geri>
read looks cleanest, couldnt get it working yet though
<geri>
doesnt read take an fd as first argument or smth?
<abu[7]>
Yep
<abu[7]>
'fd'
<geri>
what do i use if i need to use it with (in)
<abu[7]>
(fd)
<geri>
epic
<geri>
yeah sec
<geri>
that seems to have worked
<geri>
thanks
<geri>
thoughts on json situation?
<abu[7]>
I think best is if first aw-'s lib is perfected, and then we take parts of the changes to @lib/json.l
<geri>
breaking backwards compat tho
<abu[7]>
But changing 'sym' to 'name' is good anyway, right?
<abu[7]>
t?
<abu[7]>
Where does it break?
<geri>
actually i thought best solution was using (sym (name @)) for atom case haha
<abu[7]>
Why
<geri>
(sym (name 'X)) => "\"X\""
<geri>
same for "X"
<abu[7]>
There is the 'link' already
<geri>
m?
<geri>
what about it
<abu[7]>
ok, only in second case
<abu[7]>
(link "\"") in line 82
<abu[7]>
81
<geri>
yeah
<geri>
i think that's actually why "hi" was getting doublequoted
<geri>
i think i forgot to fix it in my file? xd
<geri>
oh nah i just made it use name there
<geri>
so all is good
<abu[7]>
Avoiding 'sym' is better anyway
<abu[7]>
it is expensive
<geri>
hmm
<abu[7]>
very expensive
<geri>
ouchie
<geri>
i really like the idea of using T as car for arrays
<abu[7]>
it does the whole parsing again
<geri>
simple and effective!
u0_a277` has joined #picolisp
u0_a277` is now known as geri-mobile
<abu[7]>
is it removed from @lib/json.l ?
<abu[7]>
the T thing
<abu[7]>
it used to be there
<geri>
maybe im dumb, let me see
<geri>
packJson just inserts T literally
<abu[7]>
Seems I removed it
<abu[7]>
Don't remember
<geri>
yeah
<geri>
readJson for [1, 2, 3] returns (1 2 3)
<geri>
i think its a really good idea for reliability
<geri>
but still need a solution for false/empty object
<geri-mobile>
switcheroo to phone
geri has quit [Quit: ERC 5.5.0.29.1 (IRC client for GNU Emacs 29.4)]
geri-mobile is now known as geri
<geri>
double switcheroo
<abu[7]>
The old version in RosettaCode still has it
<abu[7]>
(link T) # Array marker
<geri>
gotta check later what aw did for empty dicts
<geri>
thats funny
<abu[7]>
I think i found it inconsistent
<abu[7]>
inconvenient
<abu[7]>
the T is in the way
<geri>
it is, but lets you do nested arrays
<geri>
oh right
<geri>
i was gonna propose to parse {} as (cons NIL NIL) xd
<geri>
but probably not it, it has to be a valid alist
<geri>
and kernel is like the language designed out of it
<geri>
interesting youve never heard about it
<abu[7]>
I take a look a little later
<geri>
ill be honest i hadnt ever read the whole thing cause its a billion pages long
<geri>
but basically fexprs with lexical environment
<geri>
i think also interpreted or not even existing
<abu[7]>
Indeed, I think I heard about it a while ago, but forgot ...
<abu[7]>
Looks like a proponent of PicoLisp ;)
<abu[7]>
TLDR, PicoLisp is better ;)
<geri>
ofc it is, kernel like doesn't exist outside of papers and a little prototype
<geri>
xd
<geri>
why do examples of `input` use ++ when starting the reading?
<geri>
(let L (chop "hello world") (input (++ L) (read)))
<geri>
this stuff
<abu[7]>
It is not just starting. It *is* the reading
<abu[7]>
The exe must gererate the next char
<geri>
ohh
<geri>
so its kinda like a function but not at all :D
<abu[7]>
Well, an "exe" :)
<abu[7]>
Pil uses much more 'exe's and 'prg's than 'fun's
<geri>
okay, just found a reference for these function argument types xd
<abu[7]>
yeah, in the fun ref
<geri>
abu[7]: well, probably cause a. it can and b. its cheaper
<abu[7]>
T
<geri>
brb going for a walk
<abu[7]>
Good idea!
<abu[7]>
Me too
bjorkintosh has joined #picolisp
bjorkintosh has joined #picolisp
<geri>
harro bjork
<bjorkintosh>
hi geri.
rob_w has quit [Remote host closed the connection]
<geri>
abu[7]: im thinking if you represent floating point numbers in a json parser as an encoded string (for example, cons cell like (float . "123.7")), then you could use format scl and friends to do maths, thoughts on that?
<abu[7]>
Fixpoint works right out of the box
<abu[7]>
Just call 'scl'
<geri>
oh like
<geri>
before you do json parsing?
<abu[7]>
Yep
<abu[7]>
as it uses 'read'
<geri>
what do you do if you got a mix of things like 1.5 and 2?
<abu[7]>
you get 1500 and 2 if *Scl is 3
<geri>
that could be a problem if you were gonna add them...
<geri>
math is tough
<abu[7]>
You get *lots* of problems anyway if you try such a general Json machinery