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
clacke has joined #picolisp
rob_w has joined #picolisp
Hunar has joined #picolisp
<Hunar> Hello:D   I have a question, there are many cool C libraries that are header only, how do I use those within picolisp? I tried compiling a tiny c file with one function in it that prints hello, I used (gcc -shared -o lib.o -fPIC lib.h) but It gave an error (invalid ELF header) when I entered (native "./lib.o" "hello").. while the same works if the
<Hunar> same file had the .c extension
<Regenaxer> Hi Hunar!
<Hunar> Hello Regenaxer :D
<Regenaxer> You mean calling functions with 'native'?
<Hunar> Yes, native uses a library file, but how can I use a header only library
<Regenaxer> hmm, what is "header only"?
<Regenaxer> no functions inside?
<Hunar> A library that you download and it only has a .h file, you import it and done, everything is inside it, no linking
<Hunar> It has the implementation in the .h file
<Regenaxer> If it has only a .h file, then there is no callable code in it
<Regenaxer> .h compiles to nothing I thought
<Regenaxer> only declarations
<Hunar> That's the intended method, but header-only libraries put everything in the .h file so the user only needs #include
<Regenaxer> yes, but nothing there to call with 'native'
<Regenaxer> I *read* the .h file to know how to call a lib
<Regenaxer> or even better a man page
<Regenaxer> But *compiling* only a .h makes no sense to me
<Regenaxer> .h is used at compile time
<Hunar> The (compiling .h) was my idea, i thought it would work
<Regenaxer> but normally does not generate any vode
<Regenaxer> What was your intention?
<Hunar> I'll go and search for an example library,  be right back :)
<Regenaxer> ok :)
<Hunar> Ok, that took some time... here is a header-only library that i just found     https://github.com/ilyak/linalg    the only file you need is just    linalg.h    ... In any C project you can just    #include "linalg.h"    and use all the functions inside it, you don't need a seperate .so file to link against,   how can i use that
<Hunar> particular library in picolisp? I need to somehow compile the .h file into a library right?
rob_w has quit [Ping timeout: 265 seconds]
rob_w has joined #picolisp
<Hunar> Wait, I just renamed the .h to .c and compiled with (gcc -shared -o lib.o -fPIC lib.h) and the created library works from pil :|
<Hunar> I want to confirm to myself that it works, but I haven't dug deep into (native) yet,     in the library above (linalg) there is the struct v2 which contains two (real)s,       sizeof returned 16,     how to convert this C call      v2 a = v2new(1,2)     into a native call? vnew takes two reals and returns v2, I'm currently here
<Hunar> (native "./linalg.o" "v2new" '(V (16 (100 . 2))) 1 2)   but it fails (Bad ffi)
<Regenaxer> Sorry, was interrupted
<Hunar> No problem :)
beneroth has joined #picolisp
<Regenaxer> hmm, fiPrep() in lib.c fails
<Hunar> what is fiPrep
<Regenaxer> a function in src/lib.c
<Regenaxer> Not sure atm
<Hunar> Not related, but yesterday I tried PilBox and opened demo/Notify .. the (Show Notification) button doesn't activate, I filled the two fields but the button is greyed out
<Hunar> I'll come back in an hour :)
<Regenaxer> You need to fill both fields, and then TAB or so
<Regenaxer> ie the second field input must be finished
<Regenaxer> Yeah, later, I'm on the phone
<beneroth> Good morning
<Regenaxer> Hi beneroth!
v_m_v has joined #picolisp
<Hunar> Ok, tab worked, but that would require a special keyboard
<Regenaxer> right, or just touch outside the input field
<Regenaxer> I recommend PentiKeaboard ;)
<Hunar> weird :| Why didn't that work before,
<Hunar> Good morning beneroth :)
<v_m_v> Hello all. What is the best way of writing tests in PiL ?
<razzy> Good day everyone!
<Regenaxer> Hi v_m_v!
<Regenaxer> The 'test' function
<Regenaxer> see @lib/test.l
<Hunar> Small question about native, passing a struct to    void test(struct mystruct *a)   (mystruct has one integer) is specified like this   '(V (4 I) -1)   but that doesnt work when the function is     void test(struct mystruct a)     what is the syntax for a function that takes struct by value?
<Regenaxer> it should be '(V (4 . I))
<Regenaxer> or '(V (4 . I) . 0) to init with zero
<Regenaxer> But this is test(struct mystruct* a)
<Regenaxer> A structure as a whole cannot be passed (i.e. copied)
<Hunar> Sorry I didn't get it :/     you mean if a library has     test(struct mystruct a)   then I cant call that function?
<Regenaxer> Not from pil
<Regenaxer> native does not copy structs
<Regenaxer> Are you really sure it is not *a ?
<Regenaxer> Normally structures are passed by pointer to C functions
<Hunar> I'm just testing stuff in my head:)  hopefully i don't see it in other people's codes
<aw-> v_m_v: i have a unit testing library written in picolisp as well: https://github.com/aw/picolisp-unit
<v_m_v> Hmm for readJson something like this (readJson "{\"token\": \"123\"}") just hanging my repl :D
<v_m_v> aw-: I will check it. Thx.
<Regenaxer> v_m_v, readJson reads from the current input channel, so it waits for you to type something
<v_m_v> oh...how I can just change some test to PIL structure?
<Regenaxer> You can stop it with ^C, then ^D to return to top level
<Regenaxer> 'packJson' takes an s-expr
<v_m_v> and what is taking jsonString and return s-expr ? :D
<v_m_v> packJson is not a part of a json.l right ?
<Regenaxer> packJson is here
<Regenaxer> hmm, perhaps a bit recently?
<Regenaxer> yes 16aug21
<v_m_v> packJson -- undefined :D
<Regenaxer> I'd recommend to fetch software-lab.de/pil21.tgz
<Regenaxer> 'parseJson' does the opposite
rob_w has quit [Ping timeout: 260 seconds]
razzy has quit [Ping timeout: 250 seconds]
razzy has joined #picolisp
<v_m_v> In PIL I have that feeling which last time I have felt when I was 8 :D I am building something from Lego blocks.
<Hunar> Regenaxer, I have another problem :/   I made a struct with   int x,y;   , I'm calling a function (with native) that returns a struct with the values x=4 & y=5..   when I call it like this  (native "./lib.o" "test" 'I)  it returns 4, but when i use  (native "./lib.o" "test" '(I I))  as suggested here
<Hunar> software-lab.de/doc/native.html#structRet     it crashes       Segmentation fault (core dumped)
rob_w has joined #picolisp
<Regenaxer> Hunar: Where does your C function allocate the structure? If it is on the stack, it is gone if your function returns, and pil crashes
<Hunar> Oh
<Regenaxer> Either pass a pointer to the struct into the function
<Regenaxer> or allocate it statically in the lib
<Hunar> I did this         value test(){   value a = {4,5};   return a;    }
<Regenaxer> try a global struct
<Regenaxer> struct foo ... a;
<Regenaxer> ...
<Regenaxer> in test do return &a;
<Regenaxer> or pass *in* a struct from native
<Regenaxer> native takes care to allocate the struct on the stack
<Regenaxer> then passes a pointer to the function
<Regenaxer> void test(struct x *a) { ... fill the struct ...}
<Hunar> I haven't encountered global struct before, I'll check it out :D   thanks
<Regenaxer> best is to let 'native' do it
<Regenaxer> Pass in the struct
<Regenaxer> can be uninitialized
<Regenaxer> '(V (4 . I))
<Regenaxer> '(V (8 I I)) for two ints
<Regenaxer> each 32 bits
<Hunar> I'll try it :)
<beneroth> <v_m_v> In PIL I have that feeling which last time I have felt when I was 8 :D I am building something from Lego blocks.
<beneroth> perfect. stratified design. powerful.
<beneroth> (not that we agree with Eric on all topics, but some he explains well)
Hunar has quit [Quit: Client closed]
razzy has quit [Ping timeout: 246 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 268 seconds]
razzy has joined #picolisp
<v_m_v> This is my query: https://pastebin.com/3H2cFBdE How I can add new field "content" there? I am getting (@Content) but it is empty even if it is not
<Regenaxer> You should take care of the naming conventions
<Regenaxer> here Upper case locally bound symbols
<v_m_v> ok, I have uppercased them
<v_m_v> :)
<v_m_v> But how I can add another field to that query
<v_m_v> This is the thing which I don't understand in Pilog :/
<Regenaxer> You are scanning two indexes now
<Regenaxer> Why do you write (not (== DbOrigin NIL)) ?
<Regenaxer> (if DbOrigin
<Regenaxer> 'not' is the same as (== NIL ..)
<Regenaxer> So it seems you are still thinking Scheme ;)
<Regenaxer> Anyway, "add another field" means one more index?
<v_m_v> I have that field in my database but that query is not returning it :/
<v_m_v> I thought that if I have @Event then all of my @Event fields would be returned
<Regenaxer> The problem is rather that the query returns too much, as a filter for 'origin' is missing
<Regenaxer> (same @Origin @Event origin) ?
<Regenaxer> or (head ... or (part ..., depends on the relation
<v_m_v> the relation is +Link
<Regenaxer> good, then (same ...
<Regenaxer> each index being traversed needs a filter clause
<v_m_v> (same @Origin origin) ?
<Regenaxer> to filter out hits from the other indexes
<Regenaxer> yes, (same @Origin @Event origin)
<Regenaxer> the origin propert of @Event
<Regenaxer> *property
<Regenaxer> But this does not explain why certain values are not found
<Regenaxer> It is a (+Ref +Link), right?
<Regenaxer> must be an index
<Regenaxer> does (collect 'origin '+Event) return something?
<v_m_v> Not it looks like this: https://pastebin.com/k02BuhnX
<v_m_v> Of course. It is returning a couple of elements
<Regenaxer> ok
<Regenaxer> looks all right on a first glance
<Regenaxer> this is the problem: (same @Origin @Event DbOrigin)
<Regenaxer> Pilog does not know of DbOrigin
<Regenaxer> you must unify it first
<Regenaxer> @DbOrigin DbOrigin
<Regenaxer> ....
<v_m_v> I see :D
<v_m_v> how about showing field "content" ?
<v_m_v> It should be shown by default?
<Regenaxer> Show where?
<v_m_v> sorry ...returning
<v_m_v> From that query I am getting list of lists ((@CreatedAt 1 . T) (@Origin . {37} ) (@Event . {D13})) ... Oh ..wait ...
<Regenaxer> In the result list? I would do that outside of Pilog
<v_m_v> I see...
<v_m_v> I've got result ...he have gave me (@Event . {D13}) as a result ...
<v_m_v> :D
<Regenaxer> once you have the object, accessing properties is easier in Lisp
<v_m_v> Now I need to get fields from that (@Event. {D13}) right?
<Regenaxer> yes
<v_m_v> How I can get fields of {D13} ....by (get ?
<Regenaxer> (for X (solve ...) (with (cdr X) ... (: content)
<Regenaxer> I think 'pilog' is better than 'solve' here
<Regenaxer> (pilog '(...) (with @Event ... (: content) ...
<Regenaxer> pilog avoids building a huge list first
<Regenaxer> it iterates directly over the results
<Regenaxer> Look at the reports sales.l and inv.l in the app demo
<Regenaxer> not inv.l but inventory.l
<v_m_v> Hmm Ok...but how I can directly get fields and results from {D13} ...
<Regenaxer> (get '{D13} 'content) or (; '{D13} content)
<Regenaxer> I prefer (with '{D13} (: content))
<v_m_v> why?
<Regenaxer> usually you access more properties
<v_m_v> (PiL is so complicated and powerfull ...but at the end is so well thought)
<Regenaxer> thx :)
<v_m_v> You have created it ? :D
<Regenaxer> I would say I discovered it. All ideas were around already
<aw-> v_m_v: Regenaxer is the author of PicoLisp
<v_m_v> wow...You have a lot of my respect sir :D
<Regenaxer> no reason :)
<v_m_v> So, one day you have woked up and thought "Yes...I will create a new Lisp ...with Prolog inside...database inside...and it will be minimalistic and powerfull"?
<Regenaxer> haha, no, it evolved slowly
<Regenaxer> I wrote other Lisps before
<Regenaxer> and Pil is also in its 4th version
<Regenaxer> original on a Mac II in 1988
<v_m_v> I was born in 1987 ...
<Regenaxer> :)
<v_m_v> So, Mia is related to you?
<Regenaxer> yes, one of my daughters
<v_m_v> That explains a lot....so this is how she is getting all of the PIL knowledge :D I thought that she have access to somekind of domcumentation which I can not find :D
<Regenaxer> In fact I never taught her Pil
<Regenaxer> She found out all by herself
<aw-> Regenaxer: i'm almost at 7 years with PicoLisp now :O
<Regenaxer> Just that I pre-read the articles
<Regenaxer> cool!
<Regenaxer> time flies
<aw-> you were still writing the arm 64-bit version
<Regenaxer> yes, it started in 2012 iirc
<v_m_v> I thought that I can use PIL on arm 64 by default
<Regenaxer> so pil64 was version 4
<Regenaxer> 3 was pil32
<Regenaxer> if we neglect side-versions like mini and ersatz
<aw-> v_m_v: it has gone through a few iterations, now you've got it through LLVM
<Regenaxer> aw-, have you heard anything from Geo?
<Regenaxer> he felt silent
<aw-> Regenaxer: i talked to him on LINE a few months ago
<aw-> he has a new job at a terrible company so he's probably overworked now
<Regenaxer> I see
<beneroth> aw-, thx for the update :/
<beneroth> aw-, so we started around the same time, or maybe me a bit earlier than you (but not much)
<beneroth> I gladly remember Regenaxer going "ARM64 is terrible, not sure if I get it working ever" then two weeks later "finished. best picolisp implementation yet. ARM64 is great!" :D
<Regenaxer> true, arm64 showed to be a much better CPU
<v_m_v> Hmm I have my record in DB ..lets say {31} now I would like to get '((field1 . "field1Value) (field2 . "field2Value)) how I can do this
<v_m_v> ?
<Regenaxer> You want to build this list, or access items inside it?
<Regenaxer> i.e. an assoc list
<v_m_v> I would like to get that list ..because it is the easiest way to return Json from my API :D
<Regenaxer> ok
<v_m_v> but firsts of all I need to get assoc list from my db record
<Regenaxer> (mapcar '((S) (cons S (get This S))) '(field1 field2 ....))
<Regenaxer> or (getl Obj), but that is (val . key)
<v_m_v> still fine ...getl woudl be fine :D
<v_m_v> thx
v_m_v has quit [Remote host closed the connection]
rob_w has quit [Remote host closed the connection]
<razzy> I used to create pil log with ./pil | tee picolisp.log but now it prints lots of whitespace characters. I do not know what is wrong
<razzy> I have also trouble with forall, consider tut.tgz, (collect 'nm '+Man) works. (forall '+Man (! println This)) does nothing.
AndroUser has joined #picolisp
<razzy> new version of pil does not help.
aw- has quit [Ping timeout: 268 seconds]
<AndroUser> Can I dereference/set native pointers within Pil? for example (setq P (%@ "malloc" 'P 4)) Can i see what is at the adress within P? I tried (adr P) but didn't get what i want
<AndroUser> Oh, my name got lost in this client, i'm Hunar
anjaa has quit [Remote host closed the connection]
<razzy> AndroUser: ussually ther is no need for that.
<AndroUser> So there isn't a way?
<razzy> AndroUser: (adr 'P) gives some adress
<razzy> as new-user, i think is impossible to change adress doue to GC. but you can move value into different cell with different adress.
<AndroUser> I compared it with this in my head, (setq A 7) (setq B (adr 'A)) now B holds the pointer to A's value, if you look at B and P they look the same .. BUT while (car (adr B)) returns A's value (car (adr P)) doesn't
<razzy> AndroUser: i see A B declarations. i do not see where P came from
v_m_v has joined #picolisp
AndroUser has quit [Read error: Connection reset by peer]
Hunar has joined #picolisp
<Hunar> P is a pointer to an integer that I got from calling a native library
<razzy> Regenaxer: i did not see user hook in debugger. is it still in progress? is it on hold? can i help? will it be PilCon topic?
<razzy> Hunar: hmm, i am sorry. i cannot help you.
<Hunar> No problem :D I'll be waiting for the final yes/no answer fron Regenaxer
<v_m_v> hmm (events (((createdAt 123) (origin ((name "Test1") (id 1))) (content "321") (id 1)))) is not wrognly formatted to get nice JSON from printJson ?
Hunar has quit [Read error: Connection reset by peer]
<Regenaxer> razzy, sorry, I did not put the hook to the repul
<Regenaxer> it is quite involved
<Regenaxer> It must be *inside* 'repl'
<Regenaxer> So many places in the pil interpreter need to be modified
<v_m_v> I have (events ((createdAt 123) (origin (name "Test1")) (content "321") (id 1))) and I would like to get {"events": [list of events]} by printJson ...what I am doging wrong ? I am getting [events, {event content}, {event2 content}]
<Regenaxer> I forgot a little about arguments to the Json functions, but I think there is one nesting too much
<Regenaxer> (events (createdAt 123) (origin (name "Test1") ...
<Regenaxer> So 'cons' instead of 'list'
<v_m_v> yes but I would like to have a list of events ..not {"events": {"createdAt": ....}} but {"events": [{}. {} {} ]}
<Regenaxer> Not sure if this is doable. There was some "array" flag argument iirc
<v_m_v> So I can not have a list of elements?
<Regenaxer> I don't remember atm ;)
olaf_h has joined #picolisp
<Regenaxer> Seems this feature is gone
<Regenaxer> If I look into printJson in pil64, it uses a T flag
<olaf_h> hi all - pilbox question: get 'Not Implemented' - howto explore, which pil cmd is not implemented?
<olaf_h> used: out pack prinl glue list
<olaf_h> want to write a string to local file in pilbox app
<beneroth> v_m_v, there are also at least 2 other json libs (not contained in picolisp distro). maybe check out the one from -aw https://github.com/aw/picolisp-json
<beneroth> differences are mainly personal taste, and sometimes implementation details / features
<beneroth> olaf_h, sorry no idea.
<beneroth> bbl
<Regenaxer> mom, on tel
<olaf_h> no hurry ... enjoy the evening
<olaf_h> beneroth: no problem, me neither :-)
<v_m_v> is there any package manager for PiL?
<olaf_h> do you mean sth like pip for python?
<olaf_h> then: no
<olaf_h> because there are no packages to manage, i guess
<v_m_v> So to "install package" I need to copy the files into my project?
<Regenaxer> ok, done
<Regenaxer> Sorry olaf_h, had phone calls here all the time
<Regenaxer> I do not understand the not implemented issue
<Regenaxer> in pilbox runs the same pil
<Regenaxer> so all should be there
<beneroth> v_m_v, yeah. copy file is the way to go
<olaf_h> v_m_v: yes, I think you would have to put the desired json lib file into the lib dir of your pil21 instance
<beneroth> v_m_v, and you should read the code before you use it. but then again you should do that in every other language too. should.
<olaf_h> Hi Regenaxer, thanks for thinking, yes i tried the mentioned functions, no issue with them.
<beneroth> no package manager is still better than NPM security nightmare :D
<Regenaxer> ah, in http?
<Regenaxer> all right then
<beneroth> I attempted once to make a package manager.. even a universal one, as the topic should be kinda universal, very similar in all languages. but it's a big mess. not really needed in picolisp world at the moment. so my attempt is frozen for the moment.
* beneroth is now really away
<olaf_h> Rengeaxer: i have a simple <post> form file with a few fields and want to write field value into file when <submit>ting
<Regenaxer> cu beneroth!
<beneroth> bbl :)
<olaf_h> perhaps (app) handling is required in pilBox - no <post>-only form possible?
<Regenaxer> So (gui '(+Button) "Write" '(out "file" (prinl (val> (field 'x))))) ?
<Regenaxer> post only is possible
<Regenaxer> without session
<Regenaxer> For example 7fach.de/sushi works this way
<Regenaxer> Registration for a course
<olaf_h> on my desktop and termux android pil21 the form works fine, but not when using in pilBox
<olaf_h> i will strip down the file to minimal form with 1 field and see, what I did the false way
<Regenaxer> PilBox has a session already
<Regenaxer> it is always in a session
<Regenaxer> So no reason to worry with clumsy <post>
<Regenaxer> I mean clumsy because you have to handle lots of variables manually for a non-session post
<Regenaxer> it is basically old-style CGI
<olaf_h> hmm yeah, i understand, but for little forms i prefer <post>-only and have not to care about session timeouts and so
<Regenaxer> It is all done by PilBox
<Regenaxer> This is a single-button App: http://ix.io/3Fh0
<olaf_h> yeah, thank you. I see, simply copying my file as used on desktop pil was no good idea - does not fulfull requirements for pilBox App - e.g. (html ....) not required, but (menu ....) used and title string is missing too .....
<olaf_h> Thanks, Regenaxer, i will split the code and try again
<Regenaxer> Yes, 'menu' should be called as a minimum
<Regenaxer> so that the PilBox env stays around
<Regenaxer> Absolute minimum: http://ix.io/3Fh2
<olaf_h> the minimal-form example and the gui Button Write line above are perfect for my use case, thanks a lot
<Regenaxer> :)
v_m_v has quit [Remote host closed the connection]
olaf_h has quit [Quit: Leaving]
<razzy> Regenaxer: I have also trouble with forall, consider tut.tgz, (collect 'nm '+Man) works. (forall '+Man (! println This)) does nothing.
<Regenaxer> Strange, works here
<razzy> Regenaxer: Side issue, maybe you have idea. I used to create pil log with ./pil | tee picolisp.log but now it prints lots of whitespace characters. I do not know what is wrong.
<Regenaxer> Probably terminal control chars
<Regenaxer> from readline()
<Regenaxer> Does (forall '+Person ...) work?
<razzy> Regenaxer: i downloaded clean new pil21, and forall still return NIL
<razzy> Regenaxer: person works
<Regenaxer> ok, sorry, later
<razzy> Regenaxer: +Entity +Woman +Man does not work. Thank you for help, i know where to look. no worry, no time pressure.
<razzy> i can create or delete external symbol. can i modify external symbol via E/R interface?
<Regenaxer> Sorry, busy today ;)
<Regenaxer> yeah, 'forall' directly accesses the DB file fr|m 'dbs'
<Regenaxer> So +Entity surely will not work
<Regenaxer> but for subclasses like '+Man' in can be improved perhaps
<Regenaxer> Cool! Easy to fix
<Regenaxer> Done
<Regenaxer> Released it
<Regenaxer> Thanks razzy! lease try it
<Regenaxer> *Please
v_m_v has joined #picolisp
v_m_v has quit [Remote host closed the connection]
<beneroth> razzy, ensure you got the order of the parent classes right, +Entity should always be at the end
<beneroth> the order matters
<beneroth> cu
beneroth has quit [Quit: Leaving]
<razzy> Regenaxer: yup, new pil works. Thank you. Can i modify external symbol via E/R interface?
<razzy> not a problem if no.
<Regenaxer> Great! :)
<Regenaxer> bbl
<razzy> I want to erase +Joint. Only way I know, is to search external symbol and erase +Joint via properties.
<Regenaxer> ret
<Regenaxer> Nothing special with +Joint
<Regenaxer> just put>
<Regenaxer> 'put>' takes care to maintain both sides of the joint
Regenaxer has left #picolisp [#picolisp]
Regenaxer has joined #picolisp
aw- has joined #picolisp