freenode/#lisp - IRC Chatlog
Search
16:17:53
Inline
understanding the machinery is a thing but modeling your domain is another thing....
16:20:13
Josh_2
Theres a digital copy that I have but It's not very good quality, looks like someone did a bad job scanning the book into a digital format
16:21:12
djeis[m]
There's nothing enforcing referential transparency, but there's nothing stopping it either.
16:40:15
moldybits
Josh_2: is that a different book? i thought it was Object-Oriented Programming in Common Lisp
17:36:39
mrcode_
is there a way to declare a type so that it maps to uint32_t to take advantage of a natural wrap-around once it goes beyond uint32_max ?
17:38:10
Bike
however, if you wrap your arithmetic in logand the complier might take care of it (sbcl does, at least)
18:02:18
mrcode_
what's a good idiomatic way to convert a list of character codes gathered during a loop collect (code-char ...) into a string type ?
18:04:54
mrcode_
i actually have a list of codes and with collect (code-char elem) i end up with a list of characters, but ultimately, i'd like a string
18:19:16
_death
perhaps you could just use with-output-to-string, map-into with a string, or (setf aref)...
19:16:14
dlowe
because unless it's ascii-only, iterating over the bytes will probably not do what you want
22:12:46
semz
Does shadowing a CL function via FLET etc conflict with the standard? If no, is there a way to disable the warnings for it?
22:26:34
specbot
Constraints on the COMMON-LISP Package for Conforming Programs: http://www.lispworks.com/reference/HyperSpec/Body/11_abab.htm
22:28:37
|3b|
it could break macros (or special forms implemented as macros) or compiler macros that expect the official definitions, so not really a good idea anywayy
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.