ChanServ changed the topic of #picolisp to: PicoLisp language | Channel Log: https://irclog.whitequark.org/picolisp/ | Check also http://www.picolisp.com for more information
xkapastel has quit [Quit: Connection closed for inactivity]
xkapastel has joined #picolisp
ubLIX has quit [Ping timeout: 245 seconds]
xkapastel has quit [Quit: Connection closed for inactivity]
_whitelogger has joined #picolisp
<tankf33der> o/
<tankf33der> next week
<Regenaxer> Hi tankf33der!
<Regenaxer> OK :)
<Regenaxer> here all snow gone
<razzy> i want to add numbers to my list in order. 1 to first, 2 to second etc. do i need to walk through list with for, nth, till length? is there other way?
<Regenaxer> Yes, you need to traverse the list. I would start with 'seek'
<Regenaxer> or simply call 'sort' after 'push'ing the new element
<Regenaxer> perhaps even 'push1'
<Regenaxer> For short lists a (setq L (sort (cons 7 L))) is faster than a loop
<razzy> i want to add numbers to sorted list
<razzy> (for human purposes
<Regenaxer> Yes, thats what I talk about
<Regenaxer> You can 'sort' a (partly) sorted list
<razzy> i can think of seek use.
<Regenaxer> Try to 'bench' both version. The 'sort' one is a lot faster
<razzy> i do not get sort version
_whitelogger has joined #picolisp
<razzy> Regenaxer: missing some inc like in (seek '((X)(push 'X (inc (1)))) L)
<Regenaxer> OK, then I misunderstood the task
<Regenaxer> You talk about a list of lists?
<razzy> yop
<Regenaxer> Why "add numbers to my list in order. 1 to first, 2 to second"?
<Regenaxer> What does that mean? Gives a costant list?
<Regenaxer> ((1 1 1 1 1 1) (2 2 2 2) ...
<razzy> from ((x) (y) (z)) to ((1 x) (4 y) (3 z))
<razzy> so far (mapcan '((X)(push 'X (inc (1)))) a) not working
<Regenaxer> You know what 'mapcan' does? It concatenates the results!!
<Regenaxer> but your fun gives a number
<razzy> ah, i will think about it
<razzy> Regenaxer: this does with (for) https://ptpb.pw/1NcY
<Regenaxer> This is quite inefficient. You first traverse the list for the length, then traverse again for each item
<Regenaxer> Needs only a *single* traversal
<razzy> i agree it is ugly. it pains me. but it works
<Regenaxer> Try again!
<razzy> i am able to comunicate what i want :]
<Regenaxer> yeah
<Regenaxer> Try to avoid 'length' and 'nth' in general as much as possible
<razzy> my most favourite :D
<Regenaxer> yes, I noticed
<Regenaxer> but about the most inefficient thing to do in Lisp
<Regenaxer> OK, I help you:
<Regenaxer> (setq Lst (range 1 8))
<Regenaxer> (for ((I . L) Lst L (cdr L))
<Regenaxer> (push L I) )
<razzy> i would like version with mapcar, but i am unable to make it work :]
<razzy> yet
<Regenaxer> You need a separare var perhaps
<Regenaxer> (let I 0
<Regenaxer> (mapcar
<Regenaxer> '((X) (cons (inc 'I) X))
<Regenaxer> (range 1 8) ) )
<razzy> Regenaxer: imho not tha case, imho anonymous functions keep its inner state
<Regenaxer> Yes, like you suggested with (inc (0)), but this will not work if you call the code a second time, as (0) is then (8)
<Regenaxer> So keeping the state here is wrong
<Regenaxer> You need the state outside the anonymous fun, here in 'I'
<razzy> Regenaxer: i see.
<razzy> found a bigger problem.
<razzy> i cannot use push
<razzy> on single cell
<razzy> perhaps
<Regenaxer> If you need the list cells as in the above 'for' loop, then you can use 'map'
<Regenaxer> must go, bbl
<razzy> cons and push seem very similiar in function. exept i cannot use push on single cell. so push seem "subset" of cons. why there are 2 functions?
<Regenaxer> cons is push + set
<Regenaxer> uops
<Regenaxer> push is cons plus set ;)
<razzy> so cons is not destructive. ah. hard to remember that it is duality function
<Regenaxer> duality?
<Regenaxer> Push is basically (if you don't care about symbol conflict and muttiple args):
<Regenaxer> (de push (Var Val) (set Var (cons Val (val Var))))
<Regenaxer> for multi arg (de push (Var . @) (set Var (conc (args) (val Var))))
<Regenaxer> (not tested)
<razzy> i mean, similiar, complementary.
<Regenaxer> I think my example has the wrong order of values
<Regenaxer> (de push (Var . @) (while (args) (set Var (cons (next) (val Var)]
<Regenaxer> or so, not tested
xkapastel has joined #picolisp
xkapastel has quit [Quit: Connection closed for inactivity]
xkapastel has joined #picolisp
razzy has quit [Ping timeout: 240 seconds]
mtsd has joined #picolisp
ubLIX has joined #picolisp
alexshendi has joined #picolisp
xkapastel has quit [Quit: Connection closed for inactivity]
xkapastel has joined #picolisp
mtsd has quit [Quit: WeeChat 1.6]