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
aw- has joined #picolisp
v_m_v has joined #picolisp
v_m_v has quit [Remote host closed the connection]
v_m_v has joined #picolisp
beneroth has quit [Ping timeout: 256 seconds]
razzy has quit [Ping timeout: 240 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 256 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 268 seconds]
razzy has joined #picolisp
v_m_v has quit [Remote host closed the connection]
<Nistur> mornin' all
<Regenaxer> Hi Nistur!
aw- has quit [Ping timeout: 240 seconds]
v_m_v has joined #picolisp
<v_m_v> How I can build an query for my database where with "limit" for the first 100 results?
<Regenaxer> This is not an issue of the query itself, but how many results you fetch
<Regenaxer> A query is always unlimited
<v_m_v> and how i can put that limit there? I can not find example with select so probably select would not be a perfect choice here
<Regenaxer> A query is *built* with 'goal'
<Regenaxer> Then you call 'prove' as often as you need
<Regenaxer> In the GUI you do that automatically with a +QueryChart
<Regenaxer> it fetches as many results as needed for the first page
<Regenaxer> then you can scroll down etc.
<Regenaxer> 'pilog', 'solve' are convenience functions, actually not often used. Only in reports
<Regenaxer> but (pp 'pilog) gives you an idea
<Regenaxer> You can do (let Q (goal ...) (do 20 (prove Q) ...
<v_m_v> oh...
<v_m_v> I need to read more about that. So, pilog would opimise the result right ?
<Regenaxer> Not the 'pilog' function. It is 'select' which builds a kind of query that tries to search multiple indexes in an optimal way
<v_m_v> there is not that much of documentation and examples around pilog.
<Regenaxer> yeah, unfortunately
<v_m_v> so, can I mix select with (do 20 ) ?
<Regenaxer> But it is basically only 'goal' and 'prove'
<Regenaxer> (let Q (goal '((select (@X) ...))) (do 20 (prove Q) (bind ...
<Regenaxer> select is only needed if you search many indexes
<Regenaxer> a single index is easier with 'db'
<v_m_v> hmm https://pastebin.com/VBAbn4iM so in my example it would be (do 20 (proce Events)) ?
<Regenaxer> (? (db nm '+Address "foo" @A))
<Regenaxer> Moment, phone
<Regenaxer> done
<Regenaxer> uh, I must first fix your indentation, cannot read ;)
<v_m_v> is really that bad :D
<Regenaxer> Don't worry, it is legal. Just my habit :)
<Regenaxer> ok, so you use 'solve', this immediately tuilds a list of all results, not useful for large DBs
<Regenaxer> btw (if (not (== X NIL)) Y NIL) why so complicated
<Regenaxer> simply (and X Y) ?
<Regenaxer> (if X Y NIL)
kuao has joined #picolisp
kuao has quit [Client Quit]
<Regenaxer> You *never* need to check something for NIL with '=='
<Regenaxer> and 'not' is almost never needed
<Regenaxer> (if (not X) ... is (ifn X
<Regenaxer> 'not' is a function call and thus expensive
<v_m_v> :)
<v_m_v> thx
<v_m_v> how can I change it to something with limit ?
<Regenaxer> I write a dummy code
<Regenaxer> Perhaps this? http://ix.io/3N8Z
<Regenaxer> (not tested)
<Regenaxer> The 'do' loop runs maximally 20 times
<Regenaxer> If 'prove' is done, the (NIL ) clause will also terminate it
<Regenaxer> i.e. 'prove' returns NIL if no more results to find
<v_m_v> why (NIL (prove Q) and that strange binding at the end?
<Regenaxer> (NIL (prove Q)) I tried to explain above
<Regenaxer> and 'bind' is convenient here
<Regenaxer> the result of 'prove' is an association list
<Regenaxer> so you can 'asoq' or 'get', or just pass it to 'bind'
<Regenaxer> 'get' as you used is is probably faster
<Regenaxer> but if there are more variables, 'bind' is more readable
<v_m_v> so bind is like "let" ?
<Regenaxer> yep
<v_m_v> is there any difference between bind and let?
<Regenaxer> yes, 'let' does not evaluate the symbols
<Regenaxer> 'bind' is more flexible
<v_m_v> ok but you are binding @ what that means?
<v_m_v> you are not using @ later
<Regenaxer> '@' is bound to the result
<v_m_v> it is working like an accumulator here?
<Regenaxer> All flow functions bind '@' automatically
<Regenaxer> (while (line) (println @))
<Regenaxer> (when (foo) (doSomething @))
<Regenaxer> same as (let X (foo) (when X (doSomething X]
<Regenaxer> This '@' binding is used in PicoLisp heavily
<v_m_v> Oh...now I see.
<v_m_v> Damn. I am working with Rust everyday...sometimes I am just to stright and simple to understand the magic and beauty in PL.
<v_m_v> BTW your code is working!
<Regenaxer> oh, cool :)
<v_m_v> How about performance....? Should I be carefull with goal and prove? Can I measure somehow the "cost" of such query? (like in Postgres)
<Regenaxer> Yeah, goal and prove are more expensive than direct 'fetch' or also 'db' and 'collect'
<Regenaxer> You can measure with 'bench'
<Regenaxer> (bench (do 10000 (...)))
<Regenaxer> (....) is the query, or the query packed into a function
<v_m_v> I can not even count how many screenshots I have from our previous conversations :D Thx :D
<Regenaxer> :)
<Regenaxer> you can access this irc at https://libera.irclog.whitequark.org/picolisp
v_m_v has quit [Remote host closed the connection]
clacke has quit [Remote host closed the connection]
v_m_v has joined #picolisp
v_m_v has quit [Remote host closed the connection]
<Nistur> alright, time to do more of this "website" stuff
<Nistur> Regenaxer: another quick annoying question - how does httpGate work, the first field - can I put a domain in there? I've been setting up philippgeyer.co.uk but I was considering nistur.com to the same server, although with a different site. If I put nistur.com at the start of a line in names, does that 'just work'
<Nistur> ?
<Regenaxer> httpGate works strictly locally
<Regenaxer> it has no idea of domains
<Regenaxer> The name in the first column is translated to the port in the second
<Nistur> ok, so there's no way I could get one server to host two different pil sites on two different domains?
<Regenaxer> I think you can do what you want
<Regenaxer> for example, picolisp.com and 7fach.de are operated by one single httpGate process
<Regenaxer> also tcgfpulse.com and pulse.tcgfsupplychain.com
<Regenaxer> The outsi
Regenaxer has left #picolisp [#picolisp]
Regenaxer has joined #picolisp
<Regenaxer> oops
<Nistur> :D
<Regenaxer> the outside hostname does not matter
<Nistur> I thought I'd scared you off with my stupid question :P
<Regenaxer> nope, a Penti mistype ;)
<Regenaxer> so if you have philippgeyer.co.uk
<Nistur> so they're running on the same server at, say, 8080?
<Regenaxer> then https://philippgeyer.co.uk/foobar maps to a port for foobar
<Nistur> I can't have philippgeyer.co.uk on 8080, and nistur.com on, for example, 8081
<Regenaxer> httpGabe listns at 443
<Regenaxer> then foobar can be anything
<Regenaxer> 8080
<Regenaxer> or 500
<Regenaxer> 5000
<Regenaxer> something above 1024
<Regenaxer> if foobar runs at 5000
<Regenaxer> then both philippgeyer.co.uk/foobar and nistur.com/foobar go to the same pil server process
<Nistur> hmmmm
<Regenaxer> Try picolisp.com/wiki or 7fach.de/wiki
<Regenaxer> You can decide *in* the server
<Regenaxer> by looking at *Host
<Regenaxer> it will contain the hostname the client requested for
<Nistur> ok, I'm going to try to understand everything you just said :D
<Regenaxer> ok
<Regenaxer> httpGate is just a proxy
<Regenaxer> translating names to ports, and doing SSL
<Nistur> ok, I was hoping it would also translate domains to ports :P
<Regenaxer> I have something like that, but it is not httpGate
<Regenaxer> It translates name,2fach.de to 7fach.de/name
<Regenaxer> not very useful
<Regenaxer> 2fach -> 7fach :)
<Regenaxer> For example, try "sushi.7fach.de"
<Regenaxer> it goes to 7fach.de/sushi
<Regenaxer> Is this what you want?
<Regenaxer> or "ticker.picolisp.com"
<Regenaxer> goes to "https://picolisp.com/ticker"
<Regenaxer> This translation is done by the "default" server in the "@" line
<Nistur> hmmm, what I was hoping was that httpGate I'd have two entries, one would be, say, @ 8080 web /home/web/sites/philippgeyer.co.uk... and then the next would be nistur.com 8081 web /home/web/sires/nistur.com
<Nistur> s/sires/sites/
<Nistur> so if you'd try to load nistur.com it would connect to the server at 8081, which is hosting from /home/web/sites/nistur.com and otherwise the fallback is to load my current site
<Regenaxer> What does 8080 mean? The port httpGate is listening at?
<Nistur> good question, I just copied that from the beginning of my names file
<Nistur> I assumed it was the port, but you're right, the port is --server 8080 at the end
<Regenaxer> It should listen at 80 or 443
<Regenaxer> yes
<Regenaxer> I usually start one at 443 or two at 80 and 443
<Regenaxer> then the local ports don't matter
<Regenaxer> I start at 2000 and go upwards for every application
<Nistur> yeah, the ports don't matter
<Nistur> I just used 8080 from the example
<Regenaxer> good
<Nistur> I have two httpGate instances, at 80 and 443
<Regenaxer> Perfect
<Regenaxer> so the domain names dont matter here
<Regenaxer> if you want to map to different apps depending on the domain, then write a little frontend
<Regenaxer> which looks at *Host and redirects
<Nistur> I'll have a play with that then
<Regenaxer> Here is the one I use:
<Regenaxer> http://ix.io/3NaA
<Regenaxer> the line in the names config is
<Regenaxer> http://ix.io/3NaB
<Regenaxer> so just 7fach.de or picolisp.com etc. go to that app
<Regenaxer> the config file for that (called 7fach/dns) is:
<Regenaxer> http://ix.io/3NaD
<Regenaxer> That's all
<Regenaxer> As you see, the dispatch server looks at the *Host global
<Regenaxer> (let Dom (mapcar lowc *Host)
<Regenaxer> then it strips off "www" and looks into the *DNST idx tree to find the app
<Regenaxer> (redirect (caar @))
<Nistur> ok, I think I understand your thing, you're doing a redirect, so going to phone.picolisp.com will redirect to https://picolisp.com/phone, and I'd have to figure out how to, rather than redirect, point it at a different root
<Regenaxer> What do you mean with "root" here? Another root server (hardware)#
<Regenaxer> Would be no problem
<Regenaxer> We could redirect phone.picolisp.com to nistur.com/foobar
<Nistur> no, I just want two instances of pil running, one with the cwd in /home/web/sites/nistur.com hosting that site, then one in /home/web/sites/philippgeyer.co.uk hosting that one, and then some way for it to map the domain to those two servers... so how about... I create a third one which is the @ and I put the other two as apps under nis/ and phg/ respectively, then the @ decides, rather than redirecting
<Nistur> like yours does, to proxy to the ports they're running on?
<Regenaxer> this main.l does not handle ports, just domains
<Regenaxer> the ports are then handled by httpGate
<Regenaxer> eg. phone to 2010 or so
<Nistur> yes, so when main.l gets a request for nistur.com/test it goes "right, do a request to 127.0.0.1:8081/test, and send that back instead"
<Regenaxer> you can throug out some stuff from that main.l
<Regenaxer> ogging stuff
<Regenaxer> yes, this should do too
<Nistur> I could even load names and, if I use the domain as the app name, then can use the same data to do the lookup. Hrmmm
<Regenaxer> right
<Nistur> thanks :) I think I know what I need to do, I'll not do it yet, I still need to write more content for my first website, but hopefully I should get most of that done in a couple of days, and I can have a poke at this
<Regenaxer> great :)
<Nistur> I'll probably have more dumb questions when I try it :D But at least I now know what I want to do properly
<Regenaxer> Please ask, no problem!
<Regenaxer> It is also good for me to dig out this old stuff
<Regenaxer> I did it years ago and did not think about it any more
<Regenaxer> I just noticed that main.l and the dns file is less and less used
<Regenaxer> I told all new users to do 7fach.de/name
<Regenaxer> instead of name.7fach.de
<Nistur> :)
<Nistur> I am beginning to think that maybe I shouldn't write a few paragraphs on every project I've worked on :P
<Nistur> it's 'only' 19 before my current job
<Nistur> but that's still tiring me out
<Nistur> (also, while I'm technically not using much more than the most basic functionality of the webserver, I've still put it at the top of the list of credits :P https://philippgeyer.co.uk/credits.html )
<Regenaxer> I think this is fine the way it is
<Nistur> This is meant to be an extension of my CV, so the CV has a brief list of all the projects, this is just for if a prospective employer wants to know more about what I did on those projects. I used to have this on nistur.com and it led to far more enjoyable interviews...
<Regenaxer> ah, I see
<Regenaxer> yeah, then better keep it concise
<Nistur> yup, that's the plan :P I'm trying my best. Some projects I'm struggling to say more than a couple of sentences, some I'm struggling to stop writing :P
<Regenaxer> :)
beneroth has joined #picolisp
<beneroth> I fully agree and have kinda the same principles. I think Regenaxer agrees too. Check it out, e.g. razzy :)