freenode/#lisp - IRC Chatlog
Search
13:52:52
younder
Josh_2, Well one of Lisp's traditional uses has been to experiment with languages. So you'd expect a bit of weirdness.
13:53:38
Josh_2
most of what I have read in Let Over Λ I just can't see how they would be used practically
13:56:22
younder
Josh_2, Let over lambda is a bit weird. Most get their bearings with 'Practical Common Lisp' with Peter Seibel
14:54:17
Bike
let over lambda is pretty strange, yes. many of the things in there are in fact impractical
14:55:16
loli
defmacro! or w/e it is called, can be nice to use. Though I haven't used much outside of that
15:02:21
rumbler31_
is there something similar to #x and #b for decimal numbers? I have an interesting bug where I have set print base to 16 and I want to explicitly read a base 10 integer, this is proving hard to google
15:20:55
rumbler31_
so i have a usocket connect call where I defined the function that uses this in the repl after I changed print base
15:21:53
rumbler31_
the resulting connect port gets read into its base 16 version (that miraculously is a legal base 10 number) and that number is passed to the lower level socket open call
15:23:21
rumbler31_
I thought at first that it would be fixed by being explicit about the base of the number that I typed into the repl, #10rnumber seems to be what I originally asked
15:24:42
rumbler31_
I set print base to look at network byte data with plokami and then wrote a funciton in the repl to rebroadcast packets to a udp port
15:25:04
rumbler31_
print-base was already 16 when I wrote (defun once ((open socket host portnumber))
15:25:29
rumbler31_
so port number was read from decimal into hex, which happened to be a valid decimal number, then that number was passed to the lower level open call
15:27:05
rumbler31_
oops now i've run out of file handles for opening too many sockets and forgetting to close them lol
15:49:02
francogrex
I am disgusted by swig, language cffi and uffi are no longer support. makes me want to vomit
16:20:54
kinope
Hi! Quick question. Are Common Lisp's bitwise operations like 'logand' considered as performant as their C/C++ counterparts? I've seen this used as an optimisation where a bitmask that is a power of two is used to do modular arithmetic.
16:22:36
phoe
which means that you need to do a proper LDB or MOD for the compiler to notice "oh, I can optimize it into a single CPU instruction on a machine word"
16:26:17
pjb
kinope: if you want to learn something, try to write in C: (defun f (x) (if (< x 0) 1 (* x (f (- x 1))))) (defun main () (print (f 1000)))
16:26:41
pjb
kinope: then you can try to compare the performance of your C program and of this CL program.
16:32:17
_death
rumbler31_: I use a repl-specific pprint dispatch table for pervasive hex printing.. see https://github.com/death/slime/commit/fedcefab7e8378ea90979ff3697056dea092ae0a
16:35:05
kinope
ralt: unfortunately for me ECL doesn't do dissasemble, but I did just have a look at the source and it looks like logand is directly translated to C's bitwise and '&'. I can't find where mod is implemented just now though.
16:38:12
jackdaniel
the function mod is implemented in src/c/num_co.d, but the compiler may opencode it into something more efficient if it i.e knows that arguments are fixnums
16:38:17
kinope
pjb: I couldn't tell you about that operation on 10000 bits, Bit twiddling is not my forte
16:39:13
jackdaniel
regarding bitwise operations, their optimizations are in src/cmp/cmpopt-bits.lsp
16:44:11
pjb
kinope: (defun make-lots-of-bits (n) (map-into (make-array n :element-type 'bit) (lambda () (random 2)))) (let* ((n 10000) (a (make-lots-of-bits n)) (b (make-lots-of-bits n)) (c (bit-and a b))) (print a) (print b) (print c))
16:44:25
kinope
jackdaniel: I'm looking at an implementation of a lock-free data structure that I think is bit twiddling for the added performance. I'm just trying to figure out if i can get away with using just the standard 'mod' to the same effect.
16:44:55
_death
kinope: a tail recursive one would have something like (f (- x 1) (* x acc)) in the "induction step", i.e. calling itself would be the last operation
16:44:58
pjb
kinope: or: (defun make-int-with-lots-of-bits (n) (random (expt 2 n))) (let* ((n 10000) (a (make-int-with-lots-of-bits n)) (b (make-int-with-lots-of-bits n)) (c (logand a b))) (print a) (print b) (print c))
16:46:53
jackdaniel
it was a question of uneducated folk, but I don't think that confusing him more would make him ask better questions
16:47:42
phoe
pjb: answering a question with an equally idiotic answer doesn't help anyone, even if the original question is, in your opinion, idiot.s
16:48:57
pjb
phoe: the original questionw as a comparison of C and CL on logand. There is no more relevant than to write two programs, in C and in CL using logand.
16:48:58
kinope
I may give that a shot later pjb, but right now its 3am in the morning and I'm not set up for C development on my phone, haha.
16:50:13
phoe
pjb: the original question was about using modular arithmetic and its performance, since that's all what C and C++ are capable of unless one uses a bignum library, and your answer was about bignums, which do *not* use modular arithmetic, and therefore your bignum answer did not apply to it.
16:51:15
pjb
phoe: most modular arithemetic is used in cryptography, on numbers bigger than a long long.
18:06:39
_death
it's useful if you want to program FORTRAN in Lisp.. though there are better options like prog and &aux
18:12:12
enedil
I mean, I would try to understand id better, but now I'm writing for code to pass my class, due to covid we had "remote classes" - consultations by email, so now, I'm trying to make some code that works. My go-to functional language is OCaml and it wouldn't like this kind of solution too
20:39:02
pjb
dlowe: I prefer to use let rather than setf: (cond ((let ((result (compute-result))) (do-something-with result) result)) …) ; not the empty body.