v_m_v has quit [Remote host closed the connection]
v_m_v has joined #picolisp
<beneroth>
pilog select/3 is a bit more difficult to get correctly at the beginning (and the documentation is very dense), but just ask here and we help you.
<beneroth>
pilog queries are very powerful
<v_m_v>
Hmm there are two things ...first if I have variable "timestamp" then how I can use it in select ? (select '+Event createdAt (timestamp . inf))
<v_m_v>
is not working
<v_m_v>
I have to unquote it right?
<Regenaxer>
I think not *this* select
<Regenaxer>
it is only for interactive use
<Regenaxer>
but yes, it does not evaluate
<v_m_v>
How I can fix this ?
<v_m_v>
I would like to have (select 'Event createdAt (timestamp . inf) origin eventOrigin)
<v_m_v>
but I didn't get it how I can have "and" in select
<Regenaxer>
Which one is the class?
<Regenaxer>
(select +Cls)
<v_m_v>
Event is the class
<Regenaxer>
(select +Cls nr 7)
<v_m_v>
so +Event should be
<Regenaxer>
(select nr nm foo bar +Cls nr 7)
<Regenaxer>
The 'select' *function* is not made for such
<v_m_v>
oh...
<Regenaxer>
I meant the Pilog select clause
<v_m_v>
So how I can make SQL kind of select ?
<Regenaxer>
see doc/select.html
<v_m_v>
it is debug mode only ?
<Regenaxer>
the select function yes
<Regenaxer>
it is just a convenience frontend
<Regenaxer>
for quick inspection of db stuff
<beneroth>
v_m_v, some pilog predicates and picolisp functions have the same name
<Regenaxer>
You cannot use in a program, because it does noy evaluate the args, and always outputs to tty
<v_m_v>
I see. So how I can make it in pilog ?
<Regenaxer>
So for complex queries either do it by hand with 'init', 'step', 'iter' etc. or use Pilog
<Regenaxer>
Pilog internally uses 'init' and 'step'
<v_m_v>
PIL will make my pilog queries fast?
<Regenaxer>
yes
<Regenaxer>
faster than 'filter' on a 'collect'
<Regenaxer>
'collect' fetches too many data perhaps
<Regenaxer>
Pilog select iterates many trees simultaneously
<Regenaxer>
if Timestamp and Origin are Lisp variables
<v_m_v>
why not (goal (quote .. ?
<v_m_v>
and why (cons Timestamp T) ?
<Regenaxer>
I think 'solve' calls 'goal' internally
<Regenaxer>
The cons gives a range
<Regenaxer>
if you pass a timestamp only, it will find exact values, not a range
<v_m_v>
hmm then what is T in that range ? It is some abstract variable ?
<Regenaxer>
T is bigger than any value
<Regenaxer>
See "Comparing" in doc/ref.html
<Regenaxer>
"As special cases, NIL is always less than anything else, and T is always greater than anything else"
<Regenaxer>
We saw that also in the above (collect 'nr '+Item 100 T)
<v_m_v>
Oh I see.
<v_m_v>
so you are saying that @Created is range between my timestamp and something Huge. @Orgin is origin ...then you are connected @Created to +Event's created and @Origin to +Event's origin and at the end you are putting rules which would be like a SQL's "where"
<v_m_v>
right ?
<Regenaxer>
yes, if "where" is a set of filter conditiins
<v_m_v>
it is really powerfull
v_m_v has quit [Remote host closed the connection]
v_m_v has joined #picolisp
rob_w has joined #picolisp
<v_m_v>
Do you have any examples when PiL is getting POST requests?
<Regenaxer>
POSTs happen all the time, whenever a button is pressed
<Regenaxer>
An application has nothing to do
<Regenaxer>
it gets the values in Globals or as 'http' properties
Regenaxer has left #picolisp [#picolisp]
Regenaxer has joined #picolisp
<Regenaxer>
if the variable starts with '*', it is taken as a global
<Regenaxer>
You must 'allow' these globals
<Regenaxer>
Concerning such values, the application then does not care whether the transaction is GET or POST
<Regenaxer>
But it can distinguish via the *Post global
<v_m_v>
Hmm I see, but I am using PiL as a REST API without the gui. So I need POST for creating. So I have (de myApiName (This) .... ) and you saying that all of the POST params I will find in This ?
<Regenaxer>
You call it as "!myApiName"?
<Regenaxer>
Then 'This' is just the first arg
<Regenaxer>
"!myApiName?foo"
<Regenaxer>
"!myApiName?foo&*Var1=abc&*Var2=+123"
<Regenaxer>
this works in POST and in GET
<v_m_v>
ok but the POST arguments are in the header not in the url
<Regenaxer>
POST can have further stuff in the body
<Regenaxer>
not in header, right
<Regenaxer>
Multipart post body
<Regenaxer>
one assignment per line
<v_m_v>
ok so it will be (de !sth (param1 param2 param2) and then I will make my post and param1 param2 param3 should be in the body right ?
<Regenaxer>
I think Mia's blog has lots of examples for allow
<Regenaxer>
hmm, or perhaps not yet?
<Regenaxer>
if not, then in the next days ;)
<v_m_v>
wait a second ...what do you mean by globals? They are separated per request right? There is no way that those variabled would be shared between users right ?
<Regenaxer>
They are local to the process
<Regenaxer>
Unless a session is started with (app), the child process terminates immediately
<Regenaxer>
But during its lifetime you can do something with the values
<v_m_v>
Ok, I have *Var1 in my allowed. But when I am seding my request by CURL (curl -X POST -d '*Var1=sth' http://localhost:8080/!rule.json I am getting an error that *Var1 is not allowed
<v_m_v>
probably I am making something stupid but PiL way of dealing with server is really strange :D
<Regenaxer>
I think you are very close
<Regenaxer>
What do you have in *Allow
<Regenaxer>
in repl?
<v_m_v>
(allowed NIL "!rule.json" *Var1 *Var2)
<Regenaxer>
looks good
<Regenaxer>
Is it set in the server?
<Regenaxer>
I would set it in the very beginning
<Regenaxer>
main.l or so
<v_m_v>
yes
<v_m_v>
on normal GET request from browser is fine. Only the post have *Var1 is not allowes
<v_m_v>
without -X POST you will not make POST ..as I think
<v_m_v>
:)
<v_m_v>
thx a lot
<v_m_v>
now I can hack the rest :)
<Regenaxer>
I'm sure you find it out :)
<v_m_v>
I have learn a lot today !!! :D
<v_m_v>
Thank you!!
<Regenaxer>
I forgot to mention that pil needs multipart
<Regenaxer>
that was the problem
<Regenaxer>
No, it does POST
<Regenaxer>
I just tried, could not resist ;)
<Regenaxer>
set a break *Post
<Regenaxer>
breakpoint, and
<Regenaxer>
: *Post
<Regenaxer>
-> T
<v_m_v>
I see. I wondering if it is even possible to make real REST API in PIL. Like GET /api/users - for all users POST /api/users (with params in the body) for creating a new user. GET /api/user/id/123 for getting user with ID 123.
<v_m_v>
I don't such examples in PIL community
<Regenaxer>
It supports only get and post
<Regenaxer>
what would be not possible?
<v_m_v>
there is no PUT, PATCH, DELETE?
<Regenaxer>
nope
<v_m_v>
Is there any reason why?
<Regenaxer>
and even POST is not needed
<Regenaxer>
except for binary data
<Regenaxer>
I do all with GET
<Regenaxer>
you can call any function or file
<Regenaxer>
so POST is redunndant
<v_m_v>
I see. But the rest is not fr possibilities ..it is for structure and third parties
<Regenaxer>
and PATCH, DELETE are even dangerous
<Regenaxer>
Ok, I understand
<Regenaxer>
then you need to extend @lib/http.l
<v_m_v>
I can deal with that but I know that for other people it would be a huge issue.
<Regenaxer>
If you allow also PUT, DELETE etc. you need another security structure too. A different server
<Regenaxer>
I never needed that
<Regenaxer>
What third party do you think of?
razzy has joined #picolisp
<razzy>
Good day i wish to all!
<Regenaxer>
Hi razzy!
<beneroth>
<v_m_v> I see. I wondering if it is even possible to make real REST API in PI
<beneroth>
WTF
<beneroth>
sorry to sound like a smug lisper.. but.. just roll your own http.l and do everything as you want it. no biggie.
<Regenaxer>
It is surely possible, by extending the server, but where do we need that?
<Regenaxer>
delete etc
<beneroth>
Regenaxer, when you wan to offer it to the client because the client is bound to certain conventions :)
<Regenaxer>
Current http.l is a plain application server
<beneroth>
client being not a classical browser but a program implemented natively or in JS bloat
<beneroth>
yep
<beneroth>
so if you want to run a form.l application, us standard http.l. If you do want something different, use cyborgars http.l implementation (easy to start with) or whatever.
<Regenaxer>
right
<razzy>
I have trouble recreating "How to add records to picolisp database" from Mia. I load everything like in tut.tgz than change (pool) and than try (request) and it complain about bad db file. should i webpaste log?
<beneroth>
webpaste code
<beneroth>
especially (pool)
<v_m_v>
*beneroth if I would need to write my own http.l to have patch and delete then I would just choose different lisp dialect with more possibilities. That was not the nicest answear :/
<beneroth>
yeah. well it's how I did it
<beneroth>
v_m_v, here, maybe you can use this. cyborgar even used it originally with websockets afaik http://www.itship.ch/web.l.tgz
<beneroth>
this version might contain some minor bugfixes from me (I think something about cookie handling or so)
<v_m_v>
I need websockets for live updates. http server for getting access into db.
<v_m_v>
I could use SQLite and Rust...or Python...but there are some things in PIL that are awesome and I would like to try. At the end if everything will fail then I will use it as a database for events.
<v_m_v>
Can I write macros in PiL ? I would like to have pipelines like in Elixir/OCaml can I write this?
<v_m_v>
beneroth: for easy ready to use libsocket lib.
<beneroth>
what is the effect you desire from macros?
<beneroth>
macros are rarely used in picolisp. instead it's one of the few Lisps which offer FEXPR, they are more powerful than macros but can not always be compiled, therefore compiled lisps stopped with them some decades ago.
<beneroth>
FEXPR is a function which gets its arguments un-evaluated, and can decide itself when/how it is evaluating them (e.g. rewriting them before evaluation)
<beneroth>
I don't know Elixit/OCaml pipelines, do you have an example?
<v_m_v>
instead or writing (fun1 (fun2 (fun3 "test"))) you are writing (-> "test" fun3 fun2 fun1 )
<v_m_v>
this is the simplest pipeline
<Regenaxer>
razzy, family needs a directory
<Regenaxer>
it creates several files
<razzy>
i see
<razzy>
thx
<Regenaxer>
Still should not crash
<Regenaxer>
razzy, can you debug?
<Regenaxer>
eg. with strace
<beneroth>
v_m_v, ok. You could implement the (->) function as FEXPR (though -> is already the name of a picolisp built-in function, so maybe use another name)
<v_m_v>
beneroth: I though that PIL is small language ...now I see that it is huge and powerfull :D
<Regenaxer>
I do not feel such a "pipeline" is readable
<v_m_v>
There is more things then in CLisp :D
<Regenaxer>
why hide the structure?
<beneroth>
v_m_v, though what if (fun3) takes 3 arguments? how do you decide in the pipelined notation what is an argument and what is a function?
<beneroth>
Regenaxer, I feel the same. this is confusing.
<Regenaxer>
T
<Regenaxer>
like 'setf'
<beneroth>
removing the clear AST structure
<v_m_v>
beneroth is it simple in Elixir you are passing the pipelined element and putting it as the first element in the next function
<Regenaxer>
it ignores Lisp syntax
<v_m_v>
there is also pipeline which is putting at the end
<razzy>
Regenaxer: now i cannot reproduce crash. just error message
<v_m_v>
Clojrue also have something like that.
<Regenaxer>
razzy, I see
<Regenaxer>
no worry
<v_m_v>
If you have pipeline and possibility of having something like a macro..then you can have "with" from Elixir which is the most beautifull thing which I have saw iny my software development life.
<beneroth>
v_m_v, so (->) is just a function which calls the second argument with the first argument, then calls all other arguments after another with the result of the previous call.
<v_m_v>
pipe opperator + pattern matching + try catch in a one clean contstruction
<Regenaxer>
All such macros make sense only in compiled code
<v_m_v>
I know that PIL is not a Clojrue but it will be more readable for us.
<beneroth>
so kinda a mix of quote, fill, apply and get all in one overloaded function
<v_m_v>
true...but still it can make it more readable.
<v_m_v>
true...I will write it tomorrow. Or try :)
<Regenaxer>
yes :)
<v_m_v>
It will make everything easier for me (I've came from pipe world...so this is how I am thinking)
<beneroth>
I think that kind of readability is subjective. Now you have to know all the different modes/context of (->) to be able to read code making use of it.
<v_m_v>
There were some research about pipe operators...
<beneroth>
when you say pipe world, I think of bash pipes | another pipe | next thing :)
<Regenaxer>
T
<v_m_v>
I need to search for them. They have prove that it is more readable because at the beggining you have the most important information...
<Regenaxer>
And still Pil code is a lot more concise and readable than CL or Clojure
<Regenaxer>
e.g. if I look at rosettacode
<v_m_v>
Scheme > PIL > Clojure > CL > Racket (in my oppinion when we are talking about readability)
<v_m_v>
Bit still even Racket is easier to read then Rust ;D
<Regenaxer>
Not sure about Scheme. I find it tedius
<beneroth>
well we can assure you that you can implement all this DSLs in picolisp easily
<beneroth>
we cannot assure you to agree on taste :P
<v_m_v>
about DSL..what is the best and easiest way of writing DSL in PiL ?
<Regenaxer>
a way?
<Regenaxer>
Pil is always a dsl
<beneroth>
I personally prefer when things do clearly one thing, and the meaning is not too much context depended. E.g. like C is much more readable than C++, as in C++ you can redefine almost everything. But then again C code is longer as it has to be more explicit.
<Regenaxer>
Perhaps a coil example is the source of the interpreter?
<beneroth>
v_m_v, easiest is to write DSL commands as functions, I find.
<v_m_v>
what do you mean by "commands as functions" ?
<Regenaxer>
v_m_v, have you looked at src/* ?
<Regenaxer>
most of pil is redefined
<Regenaxer>
so that it builds iyself
<Regenaxer>
itself
<Regenaxer>
isn't that a dsl?
<beneroth>
e.g. html DSL: (<a> '(href . "www.picolisp.com") "Link to PicoLisp Website") -> <a href="www.picolisp.com">Link to PicoLisp Website</a>
<v_m_v>
oh I see. I need to check how the html has been implemented
<v_m_v>
Thx
<beneroth>
@lib/xhtml.l
<beneroth>
primarily based on the (tag) fexpr
<Regenaxer>
It is a bit misleading to compare Scheme or CL or Clojure with pil
<Regenaxer>
Pil is more different than it seems
<Regenaxer>
I think it is closer to Forth
<beneroth>
yeah. the difference in compiled vs. interpreted, macros vs fexpr, big metadata for optimizations vs. few small elements to build with
<beneroth>
it looks more similiar than it is
<razzy>
in context of tut...family.l why (request (+Man)) return {new_symbol} but does not insert it into *DB?
<Regenaxer>
It *is* inserted
<Regenaxer>
but you provide no value
<Regenaxer>
thus no index
<Regenaxer>
thus not findable
<razzy>
hmm, i will work on it :]
<Regenaxer>
(request (+Man) 'nm "razzy")
<Regenaxer>
(db 'nm '+Man "razzy")
<Regenaxer>
v_m_v, you should attend next PilCon. We can talk about such philosophical issues
<Regenaxer>
it is on 20th
<v_m_v>
remote?
<Regenaxer>
yes
<Regenaxer>
Jitsi
<Regenaxer>
twice a month
<Regenaxer>
10th and 20th
<Regenaxer>
I think it is already since one year
<Regenaxer>
We planned a real PilCon last summer, but cancelled it due to Covid
<Regenaxer>
on 20th it is always 16:00 UTC
<Regenaxer>
(on 10th at 8:00 UTC)
<Regenaxer>
early date is early time :)
<razzy>
Regenaxer: can i look for symbols by {Symbol_ID_Number}? like (collect 'Symbol_ID '+Man)?
<Regenaxer>
This is not necessary, as {number} *is* the symbol
<Regenaxer>
or do you mean a real number? Then 'id'
<Regenaxer>
: (id 2)
<Regenaxer>
-> {2}
<razzy>
i mean symbol number. i just want to list all +Men regardless of name
<Regenaxer>
: (forall '+Man (qrintsp This))
<Regenaxer>
printsp
<razzy>
Regenaxer: thank you. :D i was not expecting special function :D
<razzy>
btw, winter is covid-locked but I would like to attend live PilCon in late summer. Covid will be ok in summer.
<Regenaxer>
'forall' is not really special, but normally not used in programs
<Regenaxer>
It iterates a whole DB file
<Regenaxer>
To get all men you better do (collect 'nm '+Man)
<beneroth>
Regenaxer, oh I didn't now 'forall, another pil21ism :)
<beneroth>
"a vulnerability that would allow an attacker to publish new versions of any npm package using an account without proper authorization"
<beneroth>
"This vulnerability existed in the npm registry beyond the timeframe for which we have telemetry to determine whether it has ever been exploited maliciously."