freenode/#lisp - IRC Chatlog
Search
23:37:01
mrcode_
dlowe, pjb was asking about the classic unsigned fixed width integer wraparound, where you can do 0x4 - 0xfffffffa = 0xa
23:38:23
mrcode_
is there a good intro somewhere on the web on how to create a custom stream type that works with read-line, read-sequence, etc ? afaik those are not CLOS methods but just regular functions?
23:40:06
pjb
There's an example https://github.com/informatimago/lisp/blob/master/clext/pipe-article-en.txt
23:41:09
mrcode_
briefly looked at flexistreams and my enthusiasm quickly dissipated ;) the link above seems more approachable
23:42:08
pjb
mrcode_: notice that if you really need Z/2^n, or in general Z/p, you can easily implement it defining your own plus minus times divide operations. Or shadowing CL:+, CL:-, CL:* and CL:/, your own modular-arithemtic:+ modular-arithemtic:- modular-arithemtic:* modular-arithemtic:/ etc.
23:43:26
pjb
stylewarning: ℤ = the set of integers. ℤ/p = the set of integers modulo p ; usually, processors provide various modulo p that are a power of 2, like, 2^8, 2^16, 2^32, and now 2^64.
23:46:03
aeth
huh? Isn't { 0, 1 } just the type bit? I mean it's probably actually a fixnum internally... except when it's stored in a bit vector or an n-d array containing bits, and potentially a typed slot in a struct
23:48:34
stylewarning
pjb: you need to review the notion of a quotient and the notion of equivalence classes. Maybe what you’re trying to say is CL doesn’t have the equivalence relation built in as a standard function.
23:49:08
pjb
stylewarning: I'm just saying that CL doesn't implement modular arithmetic, if you want it you have to implement it yourself.
23:49:28
stylewarning
There are 3 elements in the group Z/3. The symbols 0, 3, 6, ... are all representations of the same element.
23:50:09
stylewarning
Z/3 algebraically doesn’t define a representation. It just is a system for describing algebraic laws
23:50:52
stylewarning
You are free to fix a transversal of Z/3 with elements of Z, that’s fine, but that’s an arbitrary choice.
23:51:14
aeth
stylewarning is right, technically you can just do all of the operations, and do MOD at the end to reduce to the simplified result because all of those numbers are equivalent...
23:51:46
stylewarning
aeth: all the MOD provides is a canonical representation. So in some sense, you don’t even need MOD.
23:52:18
stylewarning
But MOD makes it easy to check if two integers fall in the same equivalence class.
23:52:39
mrcode_
stylewarning: the point is to avoid work. you have the CPU doing this for free without thinking about it.
23:53:59
Bike
like i said, types don't influence operations. and CL sticks with integers. but you can define your own 1+ function.
23:54:12
Bike
and if you declare it inline and the compiler cooperates it'll probably be nice and quick
23:54:31
mrcode_
stylewarning: experimenting with some low latency networking code, figuring out what's feasible and what's not
23:54:48
no-defun-allowed
iirc SBCL and CCL exploit overflowing arithmetic if you write (mod ... #.(expt 2 32)) or something like that?
23:54:56
aeth
mrcode_: if you do (mod (1+ #xffffffff) (expt 2 32)) and have the proper declarations if it's a variable and not a constant, then SBCL will do the efficient result that you think it should be doing if you disassemble your function to check.
23:55:23
aeth
that goes for every power of 2, including potentially (expt 2 64) even though that's larger than fixnum
23:55:24
stylewarning
mrcode_: Ok, so you’re not so concerned with the rings of numbers, you just care about things living in CPU registers.
23:56:54
aeth
well, I'm actually not sure if it's every power of 2 (haven't tested it) but it certainly works for the common ones like 2 4 8 16 32 64
23:57:07
stylewarning
mrcode_: you might consider stealing my WITH-MODULAR-ARITHMETIC macro: https://github.com/stylewarning/lisp-random/blob/master/number-theoretic-transform.lisp#L208
23:57:10
no-defun-allowed
the AND mask is shifted left one as that's what SBCL fixnums do, but that's basically how to get bit magic happening
23:57:41
mrcode_
yes, I was just expressing my surprise that I have to go with the (logand ...) approach and I get the desired behavior on the assembler level. someone already suggested the modular arithmetic transform/optimizer in sbcl will work in some circumstances
23:58:21
aeth
more than some circumstances, I use it extensively and I prefer that it's explicit because having a bignum is imo a much better default for when I'm not expecting it than having it wrap
23:59:01
stylewarning
There’s a bunch of other modular arithmetic goodies in there, like a fixed width multiplier that doesn’t overflow.
9:50:23
frgo
I am trying to tell ASDF where it can find sources for a system - I am using AllegroCL and ASDF 3.2 .
10:08:38
frgo
well, that's not really a viable option in this case. I am using AllegroCL's stock CLX which comes as a single CLX.fasl file. I have downloaded the sources seprately - but there is no "link" between them.
10:10:53
beach
I don't get it. Are you saying that you can neither control where you put the CLX code, nor put a symbolic link in the directory where ASDF looks for systems, to the directory where you downloaded CLX?
10:12:22
LdBeth
beach: frgo means how to use ACL’s CLX to replace regular CLX as a dependency for certain ASDF systems
10:12:57
frgo
CLX.fasl sits in a predefined directory - I cannot change that. The source sits in another directory. I now want to tell ASDF that the source directory of the system CLX is in my chosen directory.
10:14:52
frgo
I do not use ASDF to load the fasl file. I use (require :clx) and AllegroCL loads its stock CLX.
10:15:48
LdBeth
You just edit the asd file of the project that requires CLX to omit CLX as dependency
10:18:50
frgo
I need to debug AllegroCL's stock CLX. As I downloaded the sources into a directory outside of the AllegroCL installation directory I now need a way to tell ASDF where to find the sources.
10:19:47
ck_
and you're sure that they are compatible? I didn't even know that Allegro offered its sources for download
10:23:15
ck_
but if the implementations differ, how can you sensibly debug one with the sources of the other?
10:32:42
ck_
if you have the sources for that CLX, won't compiling those yourself solve your problem?
10:34:12
beach
frgo: OK, so you want to use a CLX version that is not the one you get by your REQUIRE.
10:34:23
frgo
Now, I want to use SLIME's fantastic M-. capability to find the sources when I am in a backtrace.
10:35:06
frgo
I do have the compiled CLX.fasl file. That comes with a stock installation of AllegroCL.
10:35:46
frgo
Franz Inc provides the sources as a separate download. I downloaded the source separately.
10:38:58
frgo
I thought that I could use ASDF to make the system's fasl and sources to "find each other",
10:39:35
frgo
Now that you mention it - well, I then tried to use the wrong approach to solve that problem.
10:44:11
ck_
I have never tried to augment an existing fasl file with the source information. Aren't those references byte-positions to a specific file?
10:51:15
beach
frgo: SLIME asks SWANK to evaluate a call to FRAME-SOURCE-LOCATION which is implementation specific.
10:51:52
beach
frgo: I suspect the source location, if present at all, must be in the fasl file for it to work.