beneroth changed the topic of #picolisp to: PicoLisp language | The scalpel of software development | Channel Log: https://libera.irclog.whitequark.org/picolisp | Check www.picolisp.com for more information
bjorkintosh has quit [Quit: "Every day, computers are making people easier to use." David Temkin]
<geri> hey-hey, im early again :D
<geri> so ive been pondering over this packJson issue and im realizing that the representation has some inherent problems...
<geri> just because its not convertable forwards and backwards
<geri> you cant normally represent false, empty dictionary, empty array or nested arrays, (also floats, but that one i dont have a solution for)
<geri> check out the bottom when youre up
<geri> ill happily fix it up if its wanted
<aw-> geri: did you try my json library?
<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?
<aw-> that doesn't even make sense
<aw-> so JSON can start with any value? not just object or array?
<geri> yeah
<geri> "hi" is valid json
<geri> as far as i know anyway
<aw-> ohhh
<aw-> hmmm
<aw-> that's... new
<geri> yeah its not used often xd
<aw-> since RFC 7159
<aw-> hah I had no idea
<aw-> lol
<aw-> well I guess I should update the library for that
<geri> contributin B)
<geri> encoding array with T is genius to be honest
<aw-> that's abu[7]'s idea of course
<geri> :D
<aw-> not surprising
<geri> true
<aw-> ok give me a few hours or days and I'll try to update this to follow the RFC
<aw-> thanks for the heads up
<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
<abu[7]> This version http://pb1n.de/?395ae4 still had the T convention
<abu[7]> pil64
<geri> ah
<geri> latest lib is from 2020s i think?
<abu[7]> In pil21?
<geri> nvm, 2023
<geri> in pil21 yes
<abu[7]> yeah
<abu[7]> There is no perfect way
<geri> there are mostly-properly-working ways at least
<geri> :D
<abu[7]> Perhaps only 'printJson' should have Arr
<geri> i thought so too, but then its weird that you cant pack json you just read
<geri> so im not sure
<abu[7]> It depends on the use case
<geri> yeah
<geri> read ia perfectly usable so far imo
<abu[7]> Json is so simple, each app could have its own tailored
<abu[7]> I think I used only printJson
<abu[7]> get data
<geri> not like everyone enjoys writing json parsers
<abu[7]> T :)
<geri> print doesnt have problems with {}, [] and false?
<abu[7]> I don't think so. Depends on the app
<abu[7]> for communication *to* JavaScript I use PLIO anyway
<geri> polish input/output?
<abu[7]> PLIO is rd, pr, database etc
<abu[7]> @lib/plio.js
<geri> oh
<geri> nvm, 2023
<geri> wrong paste
<geri> gotta go for a few hours
<geri> laters
geri has quit [Quit: ERC 5.5.0.29.1 (IRC client for GNU Emacs 29.2)]
u0_a277 has joined #picolisp
u0_a277 has quit [Client Quit]
rob_w has joined #picolisp
geri has joined #picolisp
<geri> back
<geri> aw-: okay so i found out your parser cant represent empty strings differently from empty dictionaries...
<geri> which is very sad cause overall representation is very nice
<geri> s/dictionaries/objects/
<geri> i think i have an idea to make it 100% convertable but it's not gonna be fun to use and wont be efficient xd
<geri> those damned 20%...
<tankf33der> morning
<geri> hello
<tankf33der> opened bluesky account for tankf33der
<geri> decentralized open source (?) twitter?
<tankf33der> A decentralized social media platform like twitter
<tankf33der> yes
<geri> honestly, why use twitter or anything like it?
<geri> even if its open standard
<tankf33der> :)
<geri> xd
<geri> can you mix binary and normal reading? abu[7]
<abu[7]> No, they differ internally in char-lookahead and buffering
<geri> no wonder
<geri> i need to read a number, i guess i need to do it with rd?
<geri> from and till count as binary or normal reading?
<abu[7]> normal
<geri> or both hopefully
<geri> eh
<abu[7]> binary is only 'rd'
<geri> i know that i need for example 130 bytes to be there
<geri> maybe i could do normal read + a bytes check? xd
<abu[7]> For what is the check?
<geri> to know that i got 130 bytes and i can stop looping
<aw-> geri: rather than saying what the library can and can't do, I think it would be more useful if you actually say what you're trying to do.
<abu[7]> Hmm, what is the format like? Biiary!
<abu[7]> ?
<aw-> geri: there's nothing "sad" about code that doesn't work the way you expect. Tell us what you want to do and we'll fix our code if necessary
<geri> aw-: i just want a library that can accurately translate json to picolisp and backwards
<geri> and it keeps on bumping into edge cases
<aw-> ok but
<aw-> i'm sorry
<aw-> 20
<aw-> is not fucking json
<geri> it is :D
<aw-> i'm not going to modify my code for it to read 20 from a file and then turn it to 20
<geri> but im taking about empty strings
<aw-> do it yourself
<aw-> waste of my time
<geri> im not saying you should
<aw-> you don't need a JSON library to read 20 and figure out that it's 20
<geri> im just wondering what would be the most accurate representation that doesnt lose any information when converting
<aw-> show us the data you're working with, because if you're reading a file named data.json and the only content is 20, then you're doing it wrong.
<aw-> show us the data
<aw-> i have no idea what i'm testing for. I wrote tests to read a json file containing only 20 and then i stopped and thought "wtf am I doing?"
<aw-> so tu turn the question to you: what are you doing? what data are you having issues with?
<geri> first of all, my comment was about the printer, not the reader; im pretty sure your reader could parse single 20 already as is
<aw-> but why do you want to output 20 to a file using a JSON library?
<aw-> i don't understand what you're doing
<aw-> it makes no sense
<aw-> why should the library do heavy lifting for something a user is doing incorrectly? just (out "20.json" (prin 20))
<aw-> you don't need a library
<geri> is it incorrect if it's in the spec though?
<geri> again
<geri> i said dont touch it if that was your intention
<geri> "nobody does it anyway, let's leave it as is" is fine, i said it literally 2 times, now third
<aw-> but you're here complaining about my code because it doesn't do something that can be done 100 other ways
<geri> but it is a valid case in json overall, hence why i brought it up
<aw-> perhaps. Well if it's a big enough issue for you, the code is open source and you're free to modify it to your needs
<aw-> personally I don't think I should waste my time implementing yet another method of outputting a number to a file, in PicoLisp
<geri> *then dont do it*
<geri> i just said theres an edge case in representation, which is sad because in 80% of the cases the representation strategy is really cool
<geri> that's it
<geri> abu[7]: format is a header a la html (Content-Length: number followed by \r\n\r\n) followed by number of bytes of json
<abu[7]> So it is decimal, not binary. @lib/http.l does it somewhere
<geri> well, number is in bytes
<abu[7]> T
<abu[7]> line 280
<geri> first time seeing a global variable naming convention used as a parameter for a function (in http function)
<geri> looks like it could be it, sec
<geri> okay, you use ht:Read with *ContLen
<geri> that's in @src/ht.l?
<abu[7]> for chunked transfers
<abu[7]> yes
<geri> so that one does normal reading?
<geri> seems to be doing getChar, so i assume yes
<abu[7]> T
<geri> have you heard of kernel lisp?
<abu[7]> no
<geri> a research paper on f expressions
<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
<geri> also true
<geri> what lib file has the most maths in it?
<geri> probably except math.l :D
<abu[7]> probably none :)
<geri> pico no likey crunching numbers :(
<abu[7]> lib/openGl.l ?
<abu[7]> The flight sim does heavy math
<geri> i dont see opengl.l in lib
<abu[7]> hmm, not included
<abu[7]> moment
<abu[7]> openGl.tgz on software-lab ?
<geri> z3d.l got C in it 🤔
<abu[7]> yeah
<geri> how does that work?
<abu[7]> But only for 3D graphics
<abu[7]> the physics (flight) is all Lisp
<abu[7]> The wiki above may be a bit outdated (?)
<geri> video doesnt work on the page :(
<abu[7]> haven't tried a long time
<geri> oh yeah, i also found out about (key) like yesterday
<abu[7]> can you investigate a little? I must go to a meeting in a few minutes
<geri> checking code out right now :D
<geri> im on wayland though so its a question if ill get it working
<geri> and nixos
<abu[7]> Thanks!
<geri> :(
<abu[7]> oh
<geri> we'll see xd
<abu[7]> it is coded for X11
<abu[7]> ok
<geri> what's recur/recurse good at?
<abu[7]> Good to recurse :D
<geri> is it any faster than just referring to function name itself?
<abu[7]> Not faster, but you don't need a helper function
<abu[7]> You can recurse *inline*
<geri> recur is where the inline function starts?
<geri> like in (doc 'recur), it's after fibo check for positive?
<abu[7]> Eg. (vi 'depth)
<abu[7]> Would need a separate function
<abu[7]> there are many examples in the libs
<geri> cause you do it with an accumulator
<geri> makes sense
<geri> symbols interned in different namespaces are not ==, right?
<abu[7]> They may be ==
<geri> if not redefined?
<abu[7]> a symbol may be interned in several namespaces
<geri> eh
<abu[7]> This has nothing to do with the values or definitions
<geri> do libraries typically use their own namespace or nah?
<abu[7]> Some
<abu[7]> @lib/svg.l
<abu[7]> @lib/gis.l
<abu[7]> @lib/rsa.l
<abu[7]> @lib/android.l
<abu[7]> vip of course :)
<geri> yeah that one i remember
<geri> so many
<abu[7]> indeed
<geri> that's basically up to implementor? :D
<abu[7]> T
<abu[7]> In PilBox each app needs its own namespace
<geri> java vibes...
<geri> gotta wind down for today
<geri> enjoy the evening
<abu[7]> See you! ☺
geri has quit [Quit: ERC 5.5.0.29.1 (IRC client for GNU Emacs 29.4)]