freenode/lisp - IRC Chatlog
Search
21:00:08
asarch
How is better when you have an if-else with several lines of code? Is it (if (foop) (progn ...) (progn ...))?
21:05:04
asarch
Well, this is a simply condition to initialize the OpenGL scene: if (antialias) { /* do the operations for anti-alias */ } else { /* do operations for a normal rendering */ }
21:37:36
aeth
The only time you need not null or not not or whatever to get the actual value t is if you're storing the value.
21:39:42
aeth
because a lot of the time the truthy value could be anything, including e.g. a database connection that disconnects in a finalizer (and you just added a reference if you store it)
21:54:21
stylewarning
yes it's equivalent to (if x ...) but I think sometimes the emphasis is good to bring you from the type (OR NULL X) to the type BOOLEAN.
21:55:06
stylewarning
(you get used to it when you program in a strictly typed language for a little while, which I think is positively hygienic for Lisp code)
22:31:03
aeth
asdf_asdf_asdf: if that's a question, that means an integer that is at least 3, but it does nothing because you didn't actually declare any variable to be of that type like e.g. (let ((x 42)) (declare (type (integer 3) x)) x)
22:31:44
aeth
The syntax is a bit awkward. Most people with declaration-heavy code write (or use) macros to generate it
23:29:53
dim
phoe: as you said you're interested in contributing to pgloader, I made myself a Pull Request rather than just pushing on master as I would usually do, so that you can review some CL refactoring of the code: https://github.com/dimitri/pgloader/pull/970
23:30:22
dim
it's moving some copy/pasted parts into a generic function API with a common implementation, now that I have 3 copies of the same thing lying around
23:31:03
dim
if you feel like reviewing that PR is useful for you, let me know, otherwise I'll just squash-merge it ;-)
23:40:31
dim
as you see fit, there's no timing that I care very much about here, and it's only if you find it fun/interesting of course
0:24:33
mr_yogurt
is my emacs not indenting correctly or is the else part of an if supposed to be indented less than the then part
0:26:30
no-defun-allowed
in elisp, IF is defined like (defmacro if (test then &body else) ...) when in CL it is (defmacro if (test then else) ...)
1:09:22
anamorphic
In ACL there's a feature of the inspector that shows the objects that reference the object you're inspecting. Is there anything like that for SBCL or CCL?
1:20:58
no-defun-allowed
Typically, you just mark a trace with a bit in mark-sweep, or you just copy it.
1:21:22
no-defun-allowed
And the data wouldn't be around till you GC too, and in the case of copying it would be invalidated quickly.
1:22:50
no-defun-allowed
Then I think there would be another mark step needed too, but this is above my pay grade.
1:22:50
p_l
no-defun-allowed: special region that isn't GCed with normal algorithm (for example ZL:DEFRESOURCE or essentially a large unboxed array)
1:23:01
aeth
It would be cool if it was more than just working with the heap. It would be fun to see what objects have "42" in them.
1:25:05
anamorphic
I can't put much on the heap to really try it out. It's the "express" edition of ACL and has memory limits
1:25:50
aeth
You have to pay close attention, but I'm sure you can notice that sort of thing. And 700 definitely
1:26:04
White_Flame
ah. Well, my guess is that it's a heap scan. SBCL has a heap scanner, but maybe not something to detect references like that
1:26:28
aeth
It's weird when you make yourself pay attention to lag, e.g. move your mouse one pixel and see the delay.
1:29:13
p_l
of course this varies, these days I might move from happy go lucky to "stop blocking the isle you ......" in 700msec ;)
1:29:42
anamorphic
Oh cool, CCL does seem to have something similar: map-heap-objects, find-references ...
4:26:33
no-defun-allowed
Also, numbers with decimal parts will never be perfect squares, so you could test for that too, but 8.99999 is getting uncomfortably close to 9 for single floats.
4:28:51
beach
gabbiel: I think you need to follow the advice of no-defun-allowed and only work with integers.
4:32:37
no-defun-allowed
Sorry I didn't mention what isqrt did, it only handles positive integers and gives you the (lower) closest integer to the square root of that number.
4:34:59
no-defun-allowed
Your initial definition for perfect-square-p is also incorrect as you forgot to do something with the square root (eg floor it) to make its square not the number you started with, gabbiel.
4:36:20
aeth
gabbiel: Convert floats to integers with truncate (or any of the other similar functions). Use multiple-value-bind like this: (multiple-value-bind (n remainder) (truncate n) ...)
4:36:29
beach
gabbiel: Try something like (defun perfect-square-p (n) (let ((root (isqrt n))) (= n (* root root))))
4:36:58
aeth
gabbiel: if the remainder isn't 0 (or use some epsilon e.g. 0.01 or something) then it cannot pass anyway
4:37:43
aeth
but e.g. 43f0 or 43d0 will have 0.0f0 or 0.0d0 respectively as their remainders, so they are potential candidates, as 43
4:38:55
aeth
If you use truncate, you actually have to check for closeness to both 0 and 1 if you're not doing an exact zerop on the remainder. round will be closeness to 0 on either side (positive and negative), and the others will all have their own quirks.
4:41:27
aeth
The real question there, though is if you only want to count 1d0 or if you do want to count 0.99999999d0 as 1
4:41:55
aeth
Naturally, doing the latter is going to complicate things, and probably have two cases, for when you're very close above and very close below.
4:43:00
aeth
I guess round probably is the simplest because there the second value is the diff between the old value and the new value.
4:47:59
aeth
I think it would look something like this, if you're going the zerop route: (defun perfect-square-p (n) (let ((n (ctypecase n (integer n) (float (multiple-value-bind (n* remainder) (truncate n) (if (zerop remainder) n* nil))) (number nil)))) (if n (= (expt (isqrt n) 2) n) nil)))
4:48:58
aeth
If you're doing the more complicated route and you want to count 0.99999999d0 as 1, then you have to replace TRUNCATE with ROUND and do a more complicated check than ZEROP on the remainder. Something like (< (abs remainder) epsilon)
5:09:25
aeth
gabbiel: if you were going to cover 0.999999 you'd need to break up the floats into each different kind of float because they'd all have a different optimal epsilon there. You could even use some multiple of short-float-epsilon, single-float-epsilon, double-float-epsilon, and long-float-epsilon as your epsilons.
5:09:41
aeth
You'd probably want to do the order single-float double-float long-float short-float and unfortunately SBCL will warn you about deleting unreachable code for the latter two cases because in SBCL short-float is single-float and long-float is double-float
5:14:09
gabbiel
seems complicated. but it would be useful for computed values which are meant to be 1, but come 0.99999
5:14:31
gabbiel
for now, I think I'll do the truncate implementation, and maybe later I'll do the round version
5:32:04
gabbiel
this is weird, I ended up with this https://pastebin.com/wK7xN2TS:, but 63.9999999999 still passes the predicate
5:47:10
beach
gabbiel: I really, really think you should stick to integers, and not trying floating point numbers, because you seem to lack some understanding in how they work.
5:48:50
no-defun-allowed
I agree with beach here, it'd be much less work to just use integers, remembering there are no non-integer perfect squares.
5:52:29
gabbiel
I got the cases like 9.0 where it should work, I don't think I require the cases like 0.9999999
5:55:34
gabbiel
yeah I haven't dealt much with floats, and never read the standard on floats/doubles
5:56:37
no-defun-allowed
You might want to skip through a video like https://www.youtube.com/watch?v=jsLiDQyyBXk where the loss of precision in floating point numbers has an effect in a game.
5:57:38
no-defun-allowed
The calculation here that goes wrong could be something like (+ (float (expt 2 21)) 0.1). If you evaluate that, you'll notice the 0.1 seemingly isn't added.
5:59:10
White_Flame
single precision tracks 7.22 decimal digits; double precision tracks 15.95 decimal digits
5:59:14
no-defun-allowed
If you keep incrementing that 0.1 slowly, you'll notice that past 0.15 it jolts up to 2097152.3. This is why you see the video jump between positions, and is also (although, with numbers scaled down) why you can't get 0.9999999 to not "equal" 1.0.
6:07:31
gabbiel
somebody here talked about a cl library where decimal arithmetic was precise but I forgot the name
7:52:24
aeth
well, nothing is perfectly precise unless you have symbols for things like "pi"... but even then you'd probably quickly wind up with stuff like 23434/3495935*pi as your numbers
8:02:27
pjb
aeth: there's an infinite number of trancendantal numbers. So you would need to express your numbers as vectors of rationals of infinite size.
8:07:16
aeth
pjb: I'm assuming this system wouldn't be able to represent all numbers, but would be able to represent some like pi and e, which would probably be good enough for most calculations.
8:07:53
saturn2
any number that you thought up without taking infinite time can be represented with finite space
8:09:07
pjb
aeth: square roots are often irrational. And they can often be encountered in real problem as solutions of equations.
8:09:23
pjb
aeth: so already you'd need an infinite number of the square roots of all prime numbers…