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
pfd has joined #picolisp
rob_w has joined #picolisp
<Hunar> Hello :) what is an easy way to turn this (0 1 2) into '((1 0 0) (0 1 0) (0 0 1))
<Hunar> (rot) would have been great if it also accepted the number of rotations
<abu[m]> Hi Hunar! You can do (do 3 (rot L)), but I still don''t understand the question
<abu[m]> How (0 1 2) -> '((1 0 0 ...
<Hunar> I have a long list of numbers, i want to convert each number into a list, where only the nth element is 1 according to the number
<Hunar> numbers are from 0 to 9
<Hunar> (append (need N 0) (1) (need (- 9 N) 0))
<Hunar> I think this is what I need
<abu[m]> Less efficient, but perhaps simpler: (de f (N) (mapcar format (chop (bin (** 2 (dec N))))))
<abu[m]> Instead of '**' better '>>'
<abu[m]> (** 2 3) is (>> -3 1)
<Hunar> I tried your code, the list size should always be 10, your's changes, and needs a reverse I think
<abu[m]> Ah, I thought shorter lists are better
<abu[m]> Anyway 'bin' is too expensive
<Hunar> Ok, I'll use the append then :) seems like the simplest. thanks
<abu[m]> A small speed up is to use 'conc' instead of 'append'
<Hunar> I'm doing something that will stress PicoLisp arithmetic speed
<abu[m]> Avoiding garbage
<Hunar> a list of 60000 items, each item is 28*28 numbers, each iteration needs multiple matrix multiplications
<Hunar> i.e 60000 by 784 nested list
<abu[m]> Another small improvement: (de f (N) (prog1 (need 10 0) (set (nth @ (- 11 N)) 1)))
<abu[m]> Ah, yes, matrices. That's why the zeroes and ones.
<Hunar> I'm going to torture picolisp :) bbl
<abu[m]> β˜ΊπŸ‘
<beneroth> so we get soon some benchmark on vector/matrix number crunching in pil? :D
<beneroth> it should be inherently worse than specialized software because of the random access cell memory we have. but then there might be surprises :D
<abu[m]> Probably, yes. Also number crunching is not something Pil is good at
<beneroth> on purpose
<abu[m]> right
<beneroth> universal programming language is somewhat an oxymoron
<abu[m]> the data structures
<beneroth> yeah
<beneroth> but the data structures in pil are best for quick development and changes of business/user application which can change often because of unclear requirements or changes in processes
<abu[m]> very true
<beneroth> math is not changing that much, so it right to apply specialization and optimization for the specific case there
<beneroth> right tool for the right task etc. yaddayadda
<abu[m]> ☺
<beneroth> and I think we have this reasonably covered with the nice FFI and CLI wrapping in pil
<abu[m]> Hunaris doing tests, so it is fine. For production there are probably optimized C-libs available
<beneroth> same thinking as the microservice proponents use.. allow different languages and specials software but make it work together
<beneroth> abu[m], true. then again the current hype of python is 1) it's use in teaching 2) the wrappers for the many C-libs that they have available
<beneroth> pil will not compete on 1) anytime soon. but 2) might be feasible if someone implements those wrappers, should be comparable less work in pil than it was in python to create those wrappers
<abu[m]> and less parentheses ;)
<beneroth> then again pil can easily just call the python
<beneroth> "1958 John McCarthy and Paul Graham invent LISP. Due to high costs caused by a post-war depletion of the strategic parentheses reserve LISP never becomes popular"
<beneroth> very funny :D
<beneroth> of course they leave out the "German school of lisp"
<abu[m]> hihi
<beneroth> I don't remember where I found that sentence aimed at pil, but it was funny :D
<abu[m]> You responded to that article, somewhen in 2012 or so
<abu[m]> It recently showed up again in HN
<abu[m]> last week or so
<beneroth> oh wow
<beneroth> so I was looking into pil already in 2012?
<beneroth> yeah right
<beneroth> 2011 or 2012 I've found pil I think
<abu[m]> hmm, maybe I'm wrong with that year
<Hunar> Hi beneroth, the matrix code that I use doesnt use random access (in pil at least), my final goal is for the user to choose pil or something like fortran to see the difference :)
<beneroth> according to my git I started my first picolisp learning project in Dec 2013
<Hunar> I have a problem abu my picolisp is inconsistent, same file run multiple times, it crashes in some and runs in others
<beneroth> Hunar, yes. but the picolisp memory model is random access with everything cells. which is more flexible but not as compact as e.g. binary arrays
<abu[m]> Heisenbug πŸ˜‰
<abu[m]> What crash is it? Stack overflow?
<beneroth> Hunar, multiple loads of the same file into the same process (without stopping/starting pil each time) or truly independent runs which fail sometimes?
<beneroth> do you use namespaces? :D
<Hunar> run, ctrl-c, run .. I made a video but its very slow to upload
<abu[m]> Try to 'traceAll' to see where it crashes
<abu[m]> ah, and a core! So use 'lldb' and then "bt"
<abu[m]> $ lldb -c core
<abu[m]> or 'gdb'
<abu[m]> I prefer lldb recently
<Hunar> I tried to insgall lldb, my package manager is frozen for some reason
<Hunar> where is core :/
<abu[m]> In the working directory where you started the process
<abu[m]> The video says "core dumped", so I assumed you have "ulimit -c unlimited" set
<abu[m]> $ find -name core
<Hunar> Cant find it.. bbl when I find it with google
<Hunar> found it, its a .zst file (never worked with core dumps before)
<abu[m]> What is .zst for?
<Hunar> my core dumps are saved in /var/lib/systemd .. i cleared that folder and ran the program, coredump appeared there. its the only file there has a .zst extention
<abu[m]> I see
<abu[m]> Should be fine then
<abu[m]> So $ lldb -c core, and then "bt" for backtrace
<abu[m]> The first entry is interesting
<abu[m]> Often in 'gc'
<Hunar> "Unable to find process plug-in for the core file"
<abu[m]> Strange. Which Linux is this?
<Hunar> manjaro*
<Hunar> manjari (its based on archlinux)
<abu[m]> Perhaps: $ lldb -c <core> /path/to/bin/picolisp
<abu[m]> but normally lldb knows that from the core
<Hunar> still same error. I did traceAll, i think i found the place (pow) receives NIL as first argument for some reason
<Hunar> but why only some times.. my random values are seeded
<abu[m]> Sometimes it is not NIL but a number?
<Hunar> when it crashes it got NIL, otherwise it recieves normal numbers and continues
<abu[m]> Strange that 'pow' crashes on NIL. Here it returns NIL.
<Hunar> This pil is kinda old, should I investigate now or update first (22 9 7)
<Hunar> I have many machines, I forget to update
<abu[m]> The native calls did not change recently
<abu[m]> September is fine
<Hunar> let me replace it with normal multiplication, it's (pow N 2.0)
<Hunar> that fixed everything .. there must be something with pow
<abu[m]> I'm not sure what pow does with NIL. 'native' passes it as an empty string
<abu[m]> So the floating point lib may choke
<abu[m]> (* N N) returns NIL without problem if N is NIL
<Hunar> (load "@lib/math.l") (pow NIL 2.0) (bye) put this in a file, run $pil file.l multiple times, sometimes it crashes
<abu[m]> yes, as I said, it passes a pointer to an empty string (a pointer to a null byte)
<abu[m]> So it is kind of random what pow does, as it expects a double or float
<abu[m]> The pointer may look like a float or not
<Hunar> Hmm, I have to investigate why i'm getting NIL passed to it :)
<abu[m]> And each invocation gets a different memory address for the process space, so the pointer differs each time
<abu[m]> You should find the place which generates a NIL argument
<Hunar> yes :) back to debugging
<beneroth> (pow (or Value (quit "NIL found"))) -> debugging repl -> (bt)
<beneroth> well the generation might happen quite somewhere else
<beneroth> Hunar, the picolisp builtin math like e.g. (+) abort and return NIL when a NIL is passed to them
<beneroth> maybe such a mistake? that happened to me before.
<beneroth> (+) does not handle NIL as 0, and rightly so
<abu[m]> BTW, there is also ~(assert N)
<beneroth> right!
<abu[m]> Hunar: Try (mapc trace (who 'pow))
<Hunar> It IS generated much earlier in the code, I'm trying to narrow it down :)
<abu[m]> The above trace plus (trace 'pow)
<abu[m]> Then you see the one who calls pow with NIL
<beneroth> probably better trace the calls which put the values into your list/data structure :)
<beneroth> but that could be calls which are used all over the place anyway >.<
<Hunar> found it :) it was entirely my fault
<abu[m]> Congrats :)
rob_w has quit [Ping timeout: 256 seconds]
rob_w has joined #picolisp
pfd has quit [Quit: Client closed]
pfd has joined #picolisp
pfd has quit [Quit: Client closed]
rob_w has quit [Ping timeout: 260 seconds]
hrberg has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
hrberg has joined #picolisp