freenode/#lisp - IRC Chatlog
Search
1:53:12
moldybits
(defun foo () (case (read) (bar 42))) doesn't work when you read from a different package than it was defined it >_<
1:57:15
dlowe
(let ((*package* (find-package "MYPACKAGE"))) (read)) will intern any unqualified symbols into MYPACKAGE
2:00:50
aeth
Or you can intern the result, e.g. (intern (symbol-name :foo)) ; converts from a keyword
2:06:30
buffergn0me
WRT algebra on arrays being a thing more computer programmers should do, Common Lisp has very good support for that because CL arrays were designed with a lot of influence from APL
2:07:42
aeth
buffergn0me: Well, CL has decent support for 1D arrays... With nD arrays you have to write a lot of your own things, but at least you have the basics, like... the presence of actual nD arrays of nearly every useful numerical type.
2:09:16
aeth
Interestingly, 0D arrays have a practical use: boxes. (make-array '() :element-type 'double-float :initial-element 0d0) ; it's implementation specific, but this can remove the box on the double-float, and will in SBCL
2:10:01
aeth
buffergn0me: You can pass in a 0D array and mutate that instead of returning an unboxed numeric type (Not just double-float, also 64-bit signed/unsigned as well as various complex types, if the implementation supports it in :element-type and if the implementation removes boxing)
2:11:14
buffergn0me
The advantage I was thinking about is that operations that reduce/expand the dimensions of an array can stay in the domain of arrays when dealing with scalars. That eliminates a lot of special-case code
2:11:50
buffergn0me
aeth: Thank you for that tip, I am definitely going to add it to my collection of techniques
2:12:15
aeth
(defun foo (a) (declare ((simple-array double-float ()) a)) (incf (aref a)) a) (disassemble #'foo) ; just make sure not to accidentally return (aref a) and always return a and it should be non-consing
2:12:39
aeth
of course it's implementation-specific, but I don't see why implementations where that currently doesn't work can't add that trick
2:19:53
buffergn0me
Do you have any favorite libraries for array programming with Common Lisp? I have it in mind to play with https://github.com/phantomics/april when I have the time, but that goes way too far away from Lisp
2:20:09
aeth
buffergn0me: Oh, and I think another use of 0D arrays is to (near-)directly translate C code that uses (iirc, it has been a while) &foo
2:22:13
aeth
buffergn0me: I mostly write my own code, but it's mostly games/graphics-related so it has simplifying assumptions like 4x4 matrices.
2:23:41
aeth
The simplifying assumptions allow me to do things like compose functions that return multiple values with functions that set from multiple values, e.g. here: https://gitlab.com/zombie-raptor/zombie-raptor/blob/3f7549a14b0cbe558c97eb5e2c4ea7e02f3fcc7e/util/array.lisp
2:25:44
aeth
buffergn0me: With that, I can do things like this: (let ((m (make-array '(4 4) :element-type 'double-float :initial-element 0d0)) (v (make-array 4 :element-type 'double-float :initial-contents '(1d0 2d0 3d0 4d0)))) (setf (array-row-of-4 m 2) (array-of-4 v)) m)
2:31:27
aeth
Going too far beyond 4 I wouldn't want to do a complete loop unroll. Probably looping in 4's could work.
2:41:58
aeth
It's probably better to write an array-capable version of #'replace for larger, arbitrary things, actually.
3:01:08
verisimilitude
Displacement doesn't work as nicely as it could with n-dimensional arrays, though.
5:09:37
aeth
for 2D (probably the most common after 1D), just selecting a row and a start and an end works for most cases
6:43:18
karlosz
its wrong to assume that array elements are initialized to 0 without specfiying initial element or initial contents right?
6:45:41
beach
"If initial-element is not supplied, the consequences of later reading an uninitialized element of new-array are undefined unless either initial-contents is supplied or displaced-to is non-nil."
6:46:22
karlosz
right, i was beginning to self doubt myself because the sbcl internals make that assumption somewhere in make-hash-table
6:49:04
karlosz
an array is created but implicitly assumed to be initialized to zero which was causing problems for me