freenode/lisp - IRC Chatlog
Search
11:47:16
phoe
makomo: https://gitlab.common-lisp.net/alexandria/alexandria/merge_requests/15/diffs ?
12:01:46
dmiles
i have some code tyhat works on linux but not yet complete for windows.. whake sort of condition should i throw?
12:37:23
beach
dmiles: Conditions are not "thrown" in Common Lisp. They are "signaled". THROW is a Common Lisp function that does something entirely different.
14:46:57
MichaelRaskin
Will it be compatible with all parts of ASDF that people actually know how to use (which are less numerous than the _other_ ones…)
14:47:51
jackdaniel
(i.e it is good enough to fool quicklisp and load systems which doesn't abuse asdf method specializations)
14:48:13
MichaelRaskin
Maybe if it doesn't work for complicated cases, we can finally get the dependency graph between definitions to become acyclic
14:51:13
jackdaniel
speaking of gross ends of asdf: when I load system with cffi-libffi in dependencies it is not properly cached for the first time
14:51:40
jackdaniel
second load makes it load fine. at least on ecl, I would guess that it works fine on sbcl
16:11:52
skidd0
I have a question regarding hash-tables and setf. Here is a paste: https://pastebin.com/jeSMZxRJ
16:12:29
skidd0
i'm trying to understand why I cannot use setf on a symbol i've defined in a let scope
16:16:00
makomo
i'm assuming the problem is that the value within the hash table itself isn't updated
16:18:12
phoe
skidd0: if you understand what SYMBOL-MACROLET is, replace LET with SYMBOL-MACROLET and your code will work again
16:18:31
White_Flame
a "place" is a syntactic construct, so a "place" of (gethash key table) when written will update the table. A "place" of VALUE will set the variable VALUE
16:19:40
White_Flame
skidd0: in the 2nd case, you ar setting the "variable". That's what (setf value foo) does
16:21:31
skidd0
i see. I had thought setf set the 'place' the variable value 'came from'. I'm not sure why I thought that
16:22:38
phoe
SYMBOL-MACROLET would just replace VALUE with the proper form, in this case, (GETHASH ... ...)
16:22:55
White_Flame
macros in general can let you pass around "places" because they deal with source code constructs, whose shape define the place
16:23:39
phoe
oh right, places aren't first class constructs in Lisp, since you cannot pass them to functions or return them from functions or operate on them
16:23:56
phoe
there is a workaround called a locative - it is an object that can get the value from a place and set the value to a place
16:24:04
pjb
phoe: however, you can make first class objects to let you manipulate places: closures!
16:26:26
phoe
this returns you a pair of functions - one, zero-arg, is a getter, the other, one-arg, is a setter
16:27:16
phoe
a traditional CLOS reader is one-arg, as it requires an instance, and a writer is two-arg as it needs an instance and a newval.
16:27:42
White_Flame
(list (lambda () (aref *array* 14)) (lambda (val) (setf (aref *array* 14) val)))
16:27:46
phoe
locatives don't require instance arguments; whatever instances are required are baked into the locative at the moment it is created.
16:28:49
White_Flame
hardware locatives were generally a 1-word slot in memory, like a pointer. But a getter/setter lambda pair could do things like access bits packed in an integer or other non-word sized values
18:30:10
makomo
flip214: it's mainly because of the examples i think. i could remove one of them, but i think both are good demonstrations
18:31:35
flip214
well, I'm afraid that this huge text block won't be read - or that people stop reading after the first 3 lines, or that people only read the last few lines. pick your poison ;/
18:32:10
makomo
well, should that really matter? those who want to understand what once-only does will read it :-)
18:32:43
makomo
hm, maybe i could remove the first example, since the second one showcases the most general usage?
18:41:17
makomo
or rather, https://gitlab.common-lisp.net/alexandria/alexandria/blob/master/macros.lisp#L27
18:46:53
tfb
makomo: I think that so long as the first few lines gives some kind of clue about what the thing does the doc string can be as long as you like within some kind of sanity limit (don't make the machine page...)
18:49:06
tfb
makomo: so, in particular I find the new docstring confusing in its first few lines (sorry)
18:50:33
makomo
tfb: take a look at the previous version https://gitlab.common-lisp.net/alexandria/alexandria/blob/e8fbeb9bc62f78efd8a5fe6bd044be32a8b84c88/macros.lisp#L27
18:52:06
makomo
in particular, it doesn't accurately distinguish between evaluating an INITFORM and the corresponding EXPR-i (which happens within the expansion)
18:52:44
tfb
makomo: OK, so I'm too tired to make a detailed comment, but I prefer the first two lines of the old version but probably not the remainder of it, on the grounds that the first two lines (really first paragraph) is what I would read to remind myself what it did.
18:54:52
makomo
i see what you're getting at, but it's hard to think of a combination of the two that won't be inaccurate
18:55:36
tfb
if you like & can wait (I need to go eat in a few minutes) I will try to meld them but it will be tomorrow (UK time).
18:55:50
makomo
and it's hard to distinguish between the two levels of evaluation without explicitly introducing some names for the parts of the result
18:57:57
tfb
OK, I will try. PS sorry to pop up, criticize your doc string & vanish, that's kind of rude of me: I wasn't thinking.
19:01:40
tfb
hmm, can you not authenticate to gitlab.common-lisp.net via github? It thinks you can but then makes bad noises
19:03:50
makomo
but it's nothing complicated. KeePassXC for example has a TOTP implementation that you can use
19:06:35
tfb
makomo: OK, I know why: 'email has already been taken': I already *have* an account, if I could remember it :-)
21:55:57
oni-on-ion
slime-highlight-edits is fairly cool. but how do i clear them without toggling the mode ?
21:58:24
Baggers
this might be a goofy question but what would be the suggested way to implement signed modular arithmatic of sized integers in cl? With unsigned integers I can use (ldb (byte ~size~ 0) ~expression~). Bonus points for approaches the implementation can recongnise and reduce to machine instructions (on two's complement machines)
22:08:24
Baggers
phoe: well the bonus part would probably be. But if the main bit is possible within the standard then that would be more interesting
22:13:25
pfdietz
Baggers: what exactly do you mean? Out of the box, Lisp's integer operations are the mathematical ones, so if you can express what you want with ordinary math functions CL can do it. Now, *efficiently*...
22:17:20
Baggers
I've had a touch to drink so 'exact' might not be in my current wheelhouse. What I'm asking is, given as desire to compute the result of (for example) addin two 8 bit signed integers where where the rest is an unsigned integer that wraps on overflow. How would you recommend doing it in cl. I asked assuming there were different ways of doing it and, not being versed in everything in the spec there might have been coo
22:18:01
Baggers
'rest is an unsigned integer that' should have been 'result is an 8 bit unsigned integer that'
22:33:52
aeth
This seems to do it: (defun foo (x y) (declare (type (signed-byte 4) x y)) (- (mod (+ x y (expt 2 3)) (expt 2 4)) (expt 2 3))) (loop :repeat 20 :for i := 0 :then (foo i 1) :do (print i))
22:34:31
aeth
Baggers: what I did looks like 5 instructions instead of 1 in SBCL but looks pretty fast. Obviously, it needs to stay within the fixnum size to stay fast
22:34:32
Baggers
pjb: I expect I'm mucking up the terms. By modular arithmatic I mean the numbers wrap, by signed i was meaning i'm interested in signed integers rather than unsigned ones
22:35:40
pjb
Baggers: you seem to have some misconception about what is a number, and what is a modular number. Notably you don't seem to be quite clear on the difference between a modular number, and a representant of that number.
22:36:46
aeth
alternatively you can convert on either side of the calculations, e.g. (defun ub32-to-sb32 (number) (declare (type (unsigned-byte 32) number)) (multiple-value-bind (quotient remainder) (truncate number (expt 2 31)) (- remainder (* quotient (expt 2 31)))))
22:37:02
aeth
that will be more expensive for one calculation but if you do e.g. 100 that conversion probably will win
22:39:05
aeth
or wait, that's what you're doing anyway, so that's faster than my old conversion function
22:40:38
Baggers
pjb: quite likely. I'm happy for you to restate the problem in a precise way if you fancy
22:42:00
Baggers
pjb: I took the term 'modular arithmatic' from the sbcl manual and I assumed that combining that with something to clarify I was only interested in signed integers would be enough. Clearly not though
22:42:08
pjb
Baggers: well, the question is whether you really want just modular arithmetic (in which case, just use MOD), or if you want to find the representants in some integer interval?
22:42:59
pjb
Baggers: Also, notice that in C, modular arithmetic is only specified for unsigned integers. For signed integers, the behavior is implementation dependent.
22:44:10
Baggers
pjb: indeed, which is why I didnt ask for C's behaviour as that would only confuse things.
22:46:35
pjb
Baggers: so if the question is to find representants in the range (- (expt 2 (/ p 2))) .. (- (expt 2 (/ p 2)) 1): (defun signed-representant (n modulo) (if (<= (expt 2 (- modulo 1)) n) (- n (expt 2 modulo)) n)) (signed-representant 61 6) #| --> -3 |# assuming the modulo you're interested in are powers of 2.
22:47:39
pjb
yes. (defun signed-representant (n p) (if (<= (expt 2 (- p 1)) n) (- n (expt 2 p)) n)) or (defun signed-representant (n modulo) (if (<= (truncate modulo 2) n) (- n modulo) n))
22:50:31
Baggers
pjb: 'just use mod' is a fairly poor answer when the question was about sized integers. You address this in the code it seems. The reason I asked was that maybe there were more cool tricks people knew than the basic shit I knocked together, seeing different approaches can be helpful
22:51:57
pjb
"what would be the suggested way to implement signed modular arithmatic of sized integers in cl"
22:52:22
Baggers
pjb: ok, maybe I should have asked about mimicking x86s add instruction (where wrapping is defined for signed and unsigned)? But in my mind that distracted from the problem
22:53:44
pjb
Baggers: well, that's yet another question. X86 and most processors use 2-complement representation for negative numbers. This is a trick that means the same circuits can be used to process signed integers or unsigned integers.
22:54:52
aeth
Baggers: maybe ask in #sbcl if it's possible to get several of the obvious ways to do the calculation optimized in SBCL
22:54:54
pjb
The only thing is that the processor computes flags that can be used in different combinations when you want to test signed integers or unsigned integer, notably to test the overflow.
22:55:13
Baggers
and there is exactly why I didnt use that example. We are off on an x86 specific distraction
22:55:36
pjb
If you want to simulate the behavior of X86 add instruction, the best is to read the x86 reference manual. They are very precise about it.
22:59:34
pjb
Baggers: now about integer size, one problem is that in CL, integers are all of infinite size. 2-complement is used to represent them, but on an infinite length. Negative integers are prefixed by an infinite number of 1s, and positive integers by an infinite number of 0s.
23:00:52
aeth
pjb: eh, not quite. integers are infinite size, but you can work with subtypes... it's just that you have to stay within the subtype yourself
23:01:18
Baggers
so, let's assume there is some integer thing which wraps at 127 back around to -128. What would me to call that so I can ask a question is a palatable way?
23:02:50
Baggers
aeth: i know, but pjb wants to talk about things a very specific way, so I'm asking what works for them
23:03:00
aeth
pjb: well, yes, and they are probably all represented as fixnums or bignums, unless in something like an array with an element-type, or perhaps a struct with a typed slot
23:03:46
aeth
(and I know that SBCL does a weird thing where (signed-byte 64) and (unsigned-byte 64) aren't necessarily bignums in certain restricted circumstances)
23:04:59
aeth
I think the real issue, though is, "Can we get the compilers to optimize the high level into the low level here?" It would reduce the 5 or so instructions into fewer instructions if it's possible.
23:05:08
pjb
(defun signed-representant (n modulo) (if (<= (truncate modulo 2) n) (- n modulo) n)) (signed-representant (modular+ -100 60 128) 128) #| --> -40 |#