freenode/#lisp - IRC Chatlog
Search
20:22:37
macbug
i tried to ask a question in #clnoobs but no answe, is it ok if i post eustion here?
20:23:55
macbug
hi, i'm trying to code a function with generates a random number, this random number should be between two given numbers.
20:25:11
Xach
macbug: if start and end are 10 and 20, what is the range? the range is what you want to give to random.
20:26:22
macbug
i have tried to give end the value of 100 and start a value of 1. The problem is that it always returns 45 or 93.
20:27:21
pjb
macbug: now newbies go to #clschool, because some people thought #clnoobs was demeaning to newbies.
20:28:35
pjb
macbug: in the same lisp image, the pseudo-random number generator will generate other values.
20:33:03
sjl_
that's what I would expect. You bind the random number to a variable, but the body of your LET is empty, so it just returns NIL.
20:33:29
sjl_
I don't see how it could be returning 45 or 93 or anything aside from NIL as it's currently written
20:33:43
pjb
(defun random-between (start end) (+ start (random (- end start)))) (loop repeat 10 collect (random-between 50 100)) #| --> (82 74 94 81 87 79 75 90 50 56) |#
20:33:49
Xach
sometimes when i have a problem like that it is because i have renamed something but forgotten to use the new name.
20:40:44
macbug
it will take me a while to understand this new funtion but atleast i can continue to work on my game, thx. I'll ask questions in #clschool from now.
20:47:09
pjb
macbug: there's nothing strange to understand here, but that when you add S to a number between A and B, you get an number between S+A and S+B.
20:47:52
pjb
macbug: so if you want start=S+A and end=S+B with and A=0, then start=S and end-start=B.
23:45:42
rpg
I know I should know this but... where is the iterate library hosted these days? the project page on common-lisp.net still points at a darcs repo
23:47:04
rpg
Xach: Thanks! I wish someone would fix the iterate project page, or if not just kill it.
23:47:39
aeth
rpg: you can find the source Xach uses here: https://github.com/quicklisp/quicklisp-projects/search?utf8=%E2%9C%93&q=iterate&type=
0:31:46
buffergn0me
rpg: You can email Erik Huelsmann to get added to the iterate group on c-l.net (and ask for an account if you don't have one already), and edit the page. I'm not in the group or else I would make the edits for you.
0:38:09
asarch
MarI/O - Machine Learning for Video Games: https://www.youtube.com/watch?v=qv6UVOQ0F44
0:59:42
asarch
Is this the programmer used for that? https://en.wikipedia.org/wiki/Artificial_neural_network
0:59:55
_death
looks like it compares the mario sprite against the other sprites (abs. diff. for each pixel)
1:03:21
_death
asarch: it has a population of neural networks that are optimized using a genetic algorithm
1:03:33
no-defun-allowed
ANNs are semi-magic things that wannabe data analysts throw at everything to solve problems
1:04:12
_death
asarch: their longer the game runs (i.e. the greater the frame number reached), the fitter the network
1:10:49
no-defun-allowed
tldr: do some matrix multiplication crap, pass it to some kind of scalar function, then to train it somehow do it backwards
1:26:48
aeth
Quite a few things on the computer can be summed up as "matrix multiplication crap" and quite a few more things can (and maybe should) be done with matrices.
1:27:15
aeth
The whole point of mathematical objects like matrices are to be abstract in a generally useful way.
1:30:41
aeth
It's a bit unfortunate that most of the time matrices are going to be CFFIed (and often then sent to the GPU) and thus have to be flat (and probably allocated via static-vectors). CL comes pretty close to basically just having matrices built in with its n-dimensional array system, only really lacking e.g. stuff like * and + working directly on them.
1:32:15
aeth
Although I guess technically you'd then want column vectors, not regular 1D arrays, and (make-array '(4 1)) probably isn't going to look nice.
1:40:11
aeth
If you want to do GPU computing from Common Lisp, you probably want to use an s-expression language that runs on the GPU, just like you probably want your SQL/HTML/CSS/JS/XML/etc. in a sexpy format, too. There are several, but I don't think any are complete (I could be wrong). I'd personally lean more toward a unique DSL than a compatible subset of CL, but people have attempted both.
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