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
theruran has joined #picolisp
calle has joined #picolisp
calle has quit [Ping timeout: 276 seconds]
calle has joined #picolisp
calle has quit [Quit: Leaving]
v_m_v has joined #picolisp
<v_m_v> Is there a better way to define flat-map https://pastebin.com/dzUDjJ53 ?
<Regenaxer> (mapcan '((C) (and (> C 2) (list (* C 2)))) (1 4 5))
<Regenaxer> No need to quote (1 4 5)
<Regenaxer> hmm, but the result is different ;)
<Regenaxer> What should it do?
<Regenaxer> Why do you get 40?
<v_m_v> I would like to bring map and filter together
<Regenaxer> Better than 'mapcan' is 'extract'
<Regenaxer> (extract '((C) (and (> C 2) (* C 2))) (1 4 5))
<Regenaxer> yes, mapcan or extract
<v_m_v> So if I am getting True in my lambda then I ma making some computations and put result to the list if not ..then I am "filtering" that number
<Regenaxer> s/is/or
<Regenaxer> mapcan concatenates
<Regenaxer> so NIL gives nothing
<Regenaxer> mapcan is the decades old way in all Lisps
<v_m_v> BTW is there an tail recursion in Picolisp?
<Regenaxer> you can emulate filter, mapcar etc with mapcan
<Regenaxer> You can of course tail recurse, but it will not optimise it into a loop
<Regenaxer> it is an interpreter
<Regenaxer> Yesterday: What is fold/reduce on a list?
<Regenaxer> what did you mean?
<v_m_v> I coudn't find foldl/foldr and reduce in PicoLisp
<Regenaxer> yes, my question is, what is it?
<Regenaxer> reduce is not needed
<Regenaxer> most funs take multiple args
<Regenaxer> again, reduce is a compiler issue
<Regenaxer> does not apply to an interpreter
<Regenaxer> but whaw is foldX ?
<v_m_v> https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29
<v_m_v> It is taking list, lambda and accumulator and then process the list using lambdas
<Regenaxer> Can you explain in short? I'm on the road walking
<Regenaxer> ok
<Regenaxer> Where is it needed?
<Regenaxer> a short example?
<Regenaxer> In any case this sounds like a compiler issue again, no?
<Regenaxer> Normally you can do such things in Pil directly
<Regenaxer> Without need of preprocessing
<v_m_v> hmm you don't need to preprocess it. at the end you are getting accumulated result
<Regenaxer> Example?
<v_m_v> like (foldr 1 (*) '(1 2 3)) => 6
<Regenaxer> Why not (apply * (1 2 3)) -> 6 ?
<Regenaxer> (apply * (2 3) 1)
<v_m_v> with fold you can make more complicated things.
<v_m_v> it is like apply with custom accumulator behaviour
<Regenaxer> I think in Pil you need 'let' then
<Regenaxer> (let A 1 (for ...
<v_m_v> i see. I can implement reduce and fold by myself.
<Regenaxer> Yes, but where would you need reduce?
<v_m_v> It is just simpler for me to use them (they are exists in almost all of the programming languages)
<v_m_v> reduce is like a fold without the "first element"
<v_m_v> for reduce the first element is the element from your list
<Regenaxer> Example?
<Regenaxer> Pil uses varargs in such cases
<Regenaxer> So the function does it directly
<Regenaxer> When is reduce really needed?
<v_m_v> Hmmm ok. Password strength validation. You have a list of lambdas. Each of those lambdas is validationg password requirement ...one is validating lenght..the second one ..special character etc. Each of those validator is returning T/F
<v_m_v> You can use reduce on such list with your password and get the final result
<v_m_v> I know that you can do it in the imperative way ...with for loop etc
<Regenaxer> would be a simple 'find' over a list of functions
<v_m_v> Reduce just make it simpler.
<v_m_v> I don't think so ...that you can use find for that case
<Regenaxer> (find '((Fun) (not (Fun X))) (list of funs ...
<v_m_v> I mean..you don't need reduce... Reduce is making the list reduction ... so it is helping you in some cases
<Regenaxer> ok
<v_m_v> It is also everywhere ...js, python, java...lisps, schemes
<Regenaxer> I'm sure I would have implemented it if I ever needed
<v_m_v> So it is easy for me to transport my code from one language to another.
<v_m_v> you don't "need" it :) it is just making things easier to deal with
<v_m_v> as a common concept between multiple languages. But I can easily implement it by myself :)
<Regenaxer> With "need" I mean it gets shorter ;)
<v_m_v> it is a part of "functional" programming I think. The basic concept in each functional programming book.
<v_m_v> But once again. in PicoLisp it is just a couple of lines.
<v_m_v> and then I can use it everywhere :D
<v_m_v> So no worries :)
<Regenaxer> But makes it slower
<v_m_v> I don't think so.
<Regenaxer> should be in kernel
<Regenaxer> well, you have another layer of interpretation
<v_m_v> Hmm in all of those languages abowe...reduce, fold etc are one of the fastest way of dealing with lists
<v_m_v> oh right...I forgot about that:/
<v_m_v> damn...
<v_m_v> Hmm I can do it in Rust/C then ...and attach it to PIL
<Regenaxer> I think the fastest is to do it directly
<Regenaxer> Iterate funs etc
<Regenaxer> I still don't see if reduce makes it simpler
<Regenaxer> at least the PW example
<Regenaxer> 'find' or a simple 'and' perhaps
<Regenaxer> The PW could be:
<Regenaxer> (fully '((Fun) (Fun PW)) Funs)
<Regenaxer> Is it shorter with reduce?
<Regenaxer> : (fully '((Fun) (Fun 3)) '(ge0 le0))
<Regenaxer> -> NIL
<Regenaxer> : (fully '((Fun) (Fun 0)) '(ge0 le0))
<Regenaxer> -> T
<v_m_v> what fully is doing?
<Regenaxer> The advantages of direct calls like 'fully' over compiler construct (macros etc) is that they can be reused in many ways
<Regenaxer> eg applied:
<Regenaxer> (apply fully '(((Fun) (Fun 0)) (ge0 le0)))
<Regenaxer> or 'mapcar'd and whatnot
<Regenaxer> Can you do that with a 'reduced' expression?
<beneroth> v_m_v, you are overthinking. "optimizations" from other languages mostly don't apply for picolisp
<Regenaxer> exactly
<beneroth> "most languages doing something" = either it's essential or sturgeons law applies
<Regenaxer> Same with recursion. Recursing over a non-recursive data structure (a linear list) is the wrong approach
<Regenaxer> Recursion is needed for trees
<beneroth> T, finite trees.
<Regenaxer> yep, hopefully ;)
<beneroth> recursion is for laziness :P
<Regenaxer> or academic books
<beneroth> which have the goal to be clever. clever is bad code, unless strictly necessary. hell all code is bad code unless necessary.
<beneroth> less code = less bugs = easier to change = easier to maintain.
<Regenaxer> right
<Regenaxer> And a loop is more clear in many cases
<beneroth> v_m_v, I think the question you wrote with (begin ..) is that not just how picolisp functions work by default? returning last result?
<beneroth> Regenaxer, nvm ;)
<Regenaxer> Ah, the 'begin' question?
<Regenaxer> no problem :)
<Regenaxer> As I said, it is 'prog' in pil probably
<Regenaxer> but very seldom needed in flow like above
<beneroth> well kinda...
<beneroth> aye
<Regenaxer> 'when' or 'unless' or 'cond'
<beneroth> just do the actual thing instead of overhead
<Regenaxer> T
<Regenaxer> I notice most newcomers to Pil overuse 'if'
<Regenaxer> I use 'if' *only* if I have if/else
<Regenaxer> oherwise 'and' or 'when' is better
<Regenaxer> In v_m_v's example there was (if (cond) (xxxx) NIL)
<Regenaxer> the NIL is implied anyway
<Regenaxer> (if (cond) (xxxx))
<Regenaxer> so we do (and (cond) (xxxx))
<Regenaxer> 'if' has an implied 'prog' for the "else" part BTW
v_m_v has quit [Remote host closed the connection]
<beneroth> Regenaxer, T
<Regenaxer> Hmm, not very nice, posing lots of questions and then vanishing
calle has joined #picolisp
calle has quit [Ping timeout: 272 seconds]
calle has joined #picolisp
calle has quit [Ping timeout: 276 seconds]
<beneroth> Regenaxer, aye
<Regenaxer> ;(
v_m_v has joined #picolisp
<v_m_v> guys PIL would work normally on arm64 right?
<beneroth> yes?
<beneroth> it's used on android for years
calle has joined #picolisp
<v_m_v> what is the reason behind (get (1 2 3 4) -2) and not getting NIL?
<v_m_v> and nother question: random element from list :D
<Regenaxer> v_m_v, negative indexes meaning CDRs are practical
<v_m_v> CDRs?
<Regenaxer> random elements? Look at @lib/simul.l
<Regenaxer> yes
<Regenaxer> : (get (1 2 3 4) -2)
<Regenaxer> -> (3 4)
<Regenaxer> v_m_v, please check the logs
<Regenaxer> We talked a lot to you but you just disawpeared
<Regenaxer> We don't want to waste our time, right?
<v_m_v> oh sorry. I've been logged out. This is the biggest issue of IRC :/
<v_m_v> Sometimes I am loosing some info
<Regenaxer> all right :)
<v_m_v> Hmmm I see now :)
<v_m_v> Ok.. there is one more thing which I can not crack by myself....Objects. I know how I can create them in PIL. But is there anything like a "self" in PIL? I mean if I have method and in that method I would like to run other method from the same class how I can pass "self" there ?
<v_m_v> Hmm I don't know If I am clear
<Regenaxer> I think I understand
<Regenaxer> it is the 'This' variable bound automatically
<Regenaxer> So accesses like (: var) work
<v_m_v> https://pastebin.com/fXhu0sRX this is how I use This?
<Regenaxer> yes, good
<Regenaxer> (let (position (: position) -> (let Position (: position)
<Regenaxer> though the 'let' is not really needed
<Regenaxer> Just (: position) is very efficient
<Regenaxer> so X is (: position 1)
<Regenaxer> And I would use 'when' here, as there is no "else" part
<Regenaxer> Perhaps: http://ix.io/3WL1
<Regenaxer> no!
<Regenaxer> Next try: http://ix.io/3WL2
<Regenaxer> the first 'let' is not needed
<Regenaxer> http://ix.io/3WL4
<Regenaxer> ah, forget that!
<Regenaxer> too late :)
<Regenaxer> http://ix.io/3WL5
<Regenaxer> (just having fun)
<Regenaxer> 'let?' is better: http://ix.io/3WL6
<Regenaxer> (car (cdr is (cadr
<Regenaxer> So we get http://ix.io/3WL9
<Regenaxer> If you want a board game, you can try https://software-lab.de/chess.tgz
<Regenaxer> or try it at https://picolisp.com/chess
<Regenaxer> Concerning OOP and other stuff, have you looked at https://picolisp-blog.hashnode.dev ?
<Regenaxer> Hmm, seems I'm talking into the wind. Anyway, tired. Will go to sleep. Good night! AFP
<v_m_v> sorry...it is taking me some time to process everything what you are writing :D
<v_m_v> I don't want to give you a feeling that I don't care....I am just trying to put all of that info into my queue :)
<v_m_v> I know Mia blog :D To be honest I am a big fan...specially of her last topics. Task was also quite important for me.
<v_m_v> There is a one thing which I think (in yours examples) could be not that optimal. You have removed my (let with Position (: position)
<v_m_v> But witout it each time when I need something from position I have to make (: position) so in many iterations my solution should be a slighty faster right?
v_m_v has quit [Remote host closed the connection]
v_m_v has joined #picolisp
<v_m_v> I've to change client...this one is disconnecting me to often :/
calle has quit [Quit: Leaving]