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
teddydd has quit [Ping timeout: 256 seconds]
tooDumbToFLENG has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
aw- has quit [Remote host closed the connection]
aw- has joined #picolisp
alexshendi has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
<razzy> good morning to everyone.
<razzy> Regenaxer: you are great help and picolisp is best i could find. I do not want to annoy you or over-use you.
<Regenaxer> Good morning razzy! No worry :)
alexshendi has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
rob_w has joined #picolisp
rob_w has quit [Remote host closed the connection]
rob_w has joined #picolisp
alexshendi has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
alexshendi is now known as tooDumbToFleng
rob_w has quit [Remote host closed the connection]
rob_w has joined #picolisp
razzy has quit [Ping timeout: 256 seconds]
tooDumbToFleng has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
alexshendi is now known as tooDumbToFleng
cranium has joined #picolisp
razzy has joined #picolisp
teddydd has joined #picolisp
<razzy> tankf33der: do you want to chat about advent solutions? do you want to chat about automated pull-input and submit?
rob_w has quit [Remote host closed the connection]
tooDumbToFleng has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
Hunar has joined #picolisp
<Hunar> Hello :)    I have two questions: 1. is there a shorter function for   (setq L (append L (3)))  .. and when looping through a list, that contains lists   (setq L '( (1 2) (3 4)))  (for A L ...    how can I append to the sublists during the looping, i.e resulting in something like  '( (1 2 3) (3 4 5)), curentyly the varaibel A is
<Hunar> refering to (car (1 2 3)) instead of (1 2 3)
<Regenaxer> You can use 'append' or 'conc' and to append a new cell you must build it
<Regenaxer> Same during looping
<Regenaxer> The question is destructive or non-destructive
<Hunar> destructive
<Hunar> based on the values in each sublist, I modify the current sublist .. the next loop will use the newly modified sublists
<Regenaxer> yes, so a for loop or mapping function
<Regenaxer> is the list populated in any position?
<Regenaxer> if so, you can simply conc
<Regenaxer> (for X L (conc X (list 3)))
<Regenaxer> 'push' is easier and more efficient, but gives reverse order
<Regenaxer> (let L (need 5) (map '((X) (push 3 X)) L) L)
<Regenaxer> There are tousand ways, depending on the concrete situation
<Hunar> I might be doing it wrong, let me show you what I want,           (setq Graph (A B C))   A B C are lists, then I want this to happen      (setq A (ad A B)) (setq B (ad B C) over and over again a number of times
<Hunar> the list is variable, so it might be (A B) or (A B C D ..etc)
<Regenaxer> (setq Graph (A B C)) makes no sense. You mean (setq Graph '((a b c) (d e f) (g h i))) ?
<Regenaxer> One loop can be:
<Regenaxer> : (setq Graph '((a b c) (d e f) (g h i)))
<Regenaxer> -> ((a b c) (d e f) (g h i))
<Regenaxer> $: (map '((L) (conc (car L) (cadr L))) Graph)
<Regenaxer> -> (g h i)
<Regenaxer> : Graph
<Regenaxer> -> ((a b c d e f g h i) (d e f g h i) (g h i))
<Regenaxer> You mean that?
<Hunar> I think that works for me :) but I'll have to try it.. I'll be back in an hour   thanks
<Regenaxer> great :)
aw- has quit [Quit: Leaving.]
razzy has quit [Ping timeout: 256 seconds]
wineroots has joined #picolisp
alexshendi is now known as tooDumbToFleng
<Regenaxer> The above 'conc' in a loop will probably give problems, as the lists are modifying each other
<Hunar> Regenaxer, my problem was very easy if I used index math like how I would do it in C.. But I tried SOOO hard to not use index math and failed :(   here is the result using index math that works, its a program that guesses the next number in a sequence, to quickly solve the stupid viral facebook posts http://ix.io/3GT5
<Regenaxer> So 'append' is better
<Regenaxer> Also, in pil21 there is a more elegant way:
<Regenaxer> : (setq Graph '((a b c) (d e f) (g h i)))
<Regenaxer> -> ((a b c) (d e f) (g h i))
<Regenaxer> $: (map '((L (X Y)) (set L (append X Y))) Graph Graph)
<Regenaxer> -> (g h i)
<Regenaxer> : Graph
<Regenaxer> -> ((a b c d e f) (d e f g h i) (g h i))
<Regenaxer> Anyone here understands the trick?
<Regenaxer> Well, I would avoid 'nth' if possible
<Regenaxer> It traverses the list too often
<Regenaxer> And: (until (=1 (length ... is *never* a good idea
<Regenaxer> Awfully slow for long lists
<Hunar> I tried avoiding it
<Regenaxer> Better do (while (cdr ...
<Hunar> I wanted to avoid the first sublist, but still access it .. how can I do that without index math?
<Regenaxer> Mapping funs?
<Hunar> yes
<Regenaxer> You go with 'I' increasing
<Regenaxer> so it is one linear traversal, no?
<Regenaxer> Like you did with the mapcar above. Very good
<Hunar> yes linear, I traverse it while looking at two sublists and saving the result in the second one.. BUT this new sublist must be visible to the mapping function when It continues the traversal
<Regenaxer> Cant you pass it like in (mapcar - (cdr L) L) ?
<Regenaxer> So passing three lists?
<Regenaxer> (I did not analyze your code completely)
<Regenaxer> BTW, what is the purpose of that code?
<Hunar> It finds the next number in the sequence.. so in that particular example if someone said (5 10 55) what number comes next.. this program would calculate the next 7 numbers
<Regenaxer> (set (nth S I) (ad V (get S (dec I))))
<Regenaxer> isn't (nth S I) the cell where V is in?
<Hunar> Yes, but when I replace it with V it doesn't replace the sublist
<Regenaxer> Still the indexing is not needed I think
<Regenaxer> You map the list and access *this* cell and the *previous* one?
<Hunar> (setq A '((1) (2)))      here this doesn't do what I want   (for I A (set I (3)))
<Hunar> yes
<Regenaxer> Let me check
<Hunar> use last item from *this* sublist and *previous* sublist, then save the result in *this* sublist.. but at this point the next time the mapping function should use the newly modified sublists
<Regenaxer> wait
<Regenaxer> Is it something like:
<Regenaxer> (map '(((V) L) (set L (ad V (car L)))) S (cdr S))
<Regenaxer> better exchange the args
<Regenaxer> (map '((L (V)) (set L (ad V (car L)))) (cdr S) S)
<Regenaxer> So 'L' maps (cdr S)
<Regenaxer> 'V' always has the prev. value
<Regenaxer> The first cell is skipped
<Regenaxer> And, as I said above, please avoid (until (=1 (length ...
<Regenaxer> it hurts! ;)
<Hunar> Ok :) I'll try to remember .. the (map above didn't work as I want
<Regenaxer> But I think it is the right way
<Regenaxer> in principle
<Regenaxer> Can you debug?
<Regenaxer> You are on pil21, right?
<Hunar> Before the code in question, the value of S is  ((40) (5 45) (5 10 55))    my code turns S into    ((40) (5 45 85) (5 10 55 140)) which is correct, but your code makes this         ((40) (40 85) (40 85 140))  which the (last (last S)) IS correct, and the next iterations is also correct :).. the only difference is that it doesn't
<Hunar> contain the whole sequence, I'll have to build it myself with other code
<Regenaxer> Destructuring bind for function args works only in pil21
<Hunar> You'll have to teach me de structuring bind after this problem :) is there a wiki?
<Regenaxer> Hmm, probably not
<Regenaxer> So 'S' is ((40) (5 45) (5 10 55)) ?
<Regenaxer> I try here
<Hunar> yes
<Regenaxer> hmm, where is the differenve?
<Hunar> your code IS doing the right thing :) the difference is just that after each loop my code keeps the results in (last S) while your code only has the last result and discards the previous results, no problem I can print them in each loop instead
<Regenaxer> ok :)
<Hunar> now to the new binding syntax :)
<Regenaxer> yes
<Regenaxer> It is fully implemented in 'let'
<Regenaxer> but for function calls, a 1-dim list is supported
<Regenaxer> (de f (A (B . C) D) ...
<Regenaxer> (f 1 (2 3 4) 5)
<Regenaxer> A = 1
<Regenaxer> B = 2
<Regenaxer> C = (3 4)
<Regenaxer> D = 5
<Regenaxer> or:
<Regenaxer> (de f (A (B C) D) ...
<Regenaxer> (f 1 (2 3 4) 5)
<Regenaxer> A = 1
<Regenaxer> B = 2
<Regenaxer> C = 3
<Regenaxer> D = 5
<Regenaxer> To 'let' you can pass arbitrarily nested patterns
<Regenaxer> But for speed reasons, function params don't support that
<Hunar> So in the code above there was     '((L (V)) ...   isn't that the same as '((L . V) ...  ?
<Regenaxer> no, '(((L . V)) ... would be a function for a single arg
<Regenaxer> L is the CAR
<Regenaxer> V is the CDR of each arg
<Regenaxer> Example:
<Regenaxer> (map '((X (Y . Z)) (println X Y Z)) (1 2 3) (4 5 6))
<Regenaxer> (1 2 3) 4 (5 6)
<Regenaxer> (2 3) 5 (6)
<Regenaxer> (3) 6 NIL
<Hunar> You said     '(((L . V))    but I said   '((L . V)   i.e a regular vararg  .. is that the same as  '((L (V)) ?
<Regenaxer> Ok, no, '((L . V)  is a partial FEXPR
<Regenaxer> The first arg is evaluated into 'L'
<Regenaxer> the rest is non-evaluated in 'V'
<Hunar> Oh, my mistake
<Regenaxer> ups
<Regenaxer> afp, bbl
<Hunar> Ok this is cool.. This definitely requires a wiki with lots of examples :)
<Hunar> (ups afp bbl)  I only understood bbl
<Regenaxer> ret
<Regenaxer> :)
<Regenaxer> "ups" is "oops"
<Regenaxer> and "afp" is "away from Penti"
<Hunar> :D
<Hunar> Should setq also have this binding?
<Regenaxer> Could be useful in many places, but for setq I think it is overkill
<Regenaxer> setq is not often used
<Regenaxer> And you always can do explicit accesses
<Regenaxer> (setq A (car L) B (cadr L) C (cddr L))
<Regenaxer> (setq A (++ L) A (++ L) C L)
<Hunar> T
<Hunar> When you say things like  (until (=1 (length ... is *never* a good idea     I feel like I'm using a fragile slow old computer that single lines cost too much time :) however its good practice to be aware of those situations, most python programmers think otherwise (do whatever is easy and hope computers get fast enough that it doesn't matter)
<Hunar> .. But the problem is if I didn't find this chat and didn't talk to you I would never find these issues :( maybe one day somebody creates a program that takes a pil file and spits out your (never do this) suggestions when It detects the problems
<Regenaxer> It is more hbw one thinks about we data we handle
<Regenaxer> (length Lst) is always something to avoid
<Regenaxer> especially in a loop
<Regenaxer> I saw also people do (if (=0 (length Lst))
<Regenaxer> instead of simply (ifn Lst
<Regenaxer> So it is the way how we think about List structures
<Hunar> T :)
<Regenaxer> Or, someone here posted recently (if (not (== NIL X)) :)
<Regenaxer> for a compiler it does not matter
<Regenaxer> but for the interpreter it is a lot of work
<Regenaxer> Every function call is a large overhead
<Regenaxer> 'not' and '==' are both functions
<Regenaxer> Also checks for longer pieces
<Regenaxer> (> 3 (length Lst)) (cdddr Lst)
<Regenaxer> (> 99 (length Lst)) (nth 99 Lst)
<Regenaxer> nth traverses only 99 cells while length always traverses all
<Regenaxer> above is wrong
<Regenaxer> (> 99 (length Lst)) (nth 100 Lst) right?
<Regenaxer> (the old off-by-one difficulty beneroth mentioned sometimes)
<Hunar> I don't know if array starting at 0 or 1  is better for reducing off-by-one errors
<Regenaxer> For arrays 0 is more natural
<Regenaxer> especially in C
<Regenaxer> pointer arithmetics
<Regenaxer> But for Lists I feel 1-based more intuitive
<Hunar> So far I'm liking the starting at 1  .. but for modulo math its very uncomfortable, I have to dec and inc constantly
<Regenaxer> yeah, depends
<beneroth> Regenaxer, T @ starting with 0 or 1
<beneroth> Lisp: index/element position. C: offset
<Regenaxer> yes
<Regenaxer> Hunar, your holiday today?
<Hunar> Yep :)
<Regenaxer> :)
<Hunar> pil's performance is very impressive compared to all the other interpreted languages that i've seen   I once did a benchmark  pil was 2.3 times slower than C and 5.5 times slower than C with -O3 flag .. python was 5 times slower than pil, lua 7.4 times slower than pil,  and sbcl was 1.024 times faster than pil
<Regenaxer> Thanks, very interesting
<Hunar> I don't know how dependable is my results.. I talked about it here, check to see the codes   https://www.reddit.com/r/Common_Lisp/comments/quba6m/how_does_cl_computing_this_instantly/
<Regenaxer> Ackermann (like Fibonacci) can be sped up by uisig memoization
<Regenaxer> i.e. 'cache' in pil
<Regenaxer> (I think Mia wrote about cache'd fibo in one article)
<Hunar> I was now aware of optimization at that time :)    I have to check cache now, I'm interested
<Hunar> I think in (doc 'cache)  the example is from Mia then
<Regenaxer> yes, exactly
tooDumbToFleng has quit [Quit: -a- Connection Timed Out]
<Regenaxer> http://ix.io/3GTH
<Hunar> :)
alexshendi has joined #picolisp
<Hunar> I don't understand the usage of cache :(   ackermann takes two functions X Y  what should the (cache   arguments be? I tried (cache '(NIL) X Y ...  which was wrong
<Hunar> sorry ... takes two arguments*
<Regenaxer> I would use (cons X Y) as key
<Hunar> Aha, now I get what it needs :)
<Regenaxer> hmm, cache does not help much it seems
<Regenaxer> 'ack' is weird ;)
<beneroth> Hunar, oh thanks for letting us know about your benchmark :D
<Hunar> I was about to say the same, mine is taking almost 2GB of ram and rising but still hasn't found (ack 4 2)   while the optimized code found it instantly
<beneroth> I'm surprised that Python was so much worse than pil.
<Regenaxer> Yeah, with cache it takes lots of ram
<Hunar> beneroth no problem :) I hope it's useful since the data was only from one program
<beneroth> in practice, it makes well sense to compare python and pil - but actual performance for a real application is probably hard to compare, depends a lot. much python is just wrapped C/C++.
<Hunar> Yeah it varies alot, sometimes python is 100times slower than C for some reason
<beneroth> I feel this is a quite unfortunate property for a language/stack: having high performance variability and surprise behavior changes when scaling up. Java had/has the same problem (there caused mainly by hidden casting, I believe)
<beneroth> pil has a more reliable behavior I think
<Hunar> I also think pil is more reliable
alexshendi has quit [Quit: -a- Connection Timed Out]
alexshendi has joined #picolisp
<Hunar> Question for tomorrow maybe .. how does the garbage collector trigger? I did   (prog (setq A (range 1 50000000)) NIL) which took 943MB of my RAM, then thought (setq A NIL) would trigger the garbage collector but it didn't
<Regenaxer> It triggers in 'cons' and all other functions that create cells
<Regenaxer> Only when the last cell in the free list is used, gc runs
<Regenaxer> you can call it manually with (gc)
<Regenaxer> Or (gc 100)
<Hunar> I just did both, it's still holding the memory :/
<Regenaxer> Also note that the allocated heap will not shrink. The 43MB
<Regenaxer> yes, it just builds a huge free list
alexshendi is now known as tooDumbToFleng
tooDumbToFleng has quit [Quit: -a- IRC for Android 2.1.59]
<Regenaxer> you can free unused heap blocks with (gc 0)
<Hunar> Ah :D thanks
<Regenaxer> but it frees only heap blocks which have not a sigle cell
<Regenaxer> In your case it will free most blocks
<Regenaxer> as they were just allocated
<Hunar> :) Good night everyone
<Regenaxer> Good night Hunar!
<Regenaxer> o/
<Regenaxer> I retire too
Hunar has quit [Quit: Client closed]
<beneroth> Good night :)
beneroth has quit [Quit: Leaving]
cranium has quit [Quit: Leaving]