libera/#commonlisp - IRC Chatlog
Search
20:26:16
pjb
HamzaShahid: (defun all-bit-combinations (n) (if (zerop n) '(()) (let ((rests (all-bit-combinations (- n 1)))) (mapcan (lambda (bit) (mapcar (lambda (rest) (cons bit rest)) rests)) '(0 1))))) (mapcar #'all-bit-combinations '(0 1 2 3)) #| --> ((nil) ((0) (1)) ((0 0) (0 1) (1 0) (1 1)) ((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1))) |#
20:28:32
pjb
HamzaShahid: this is one way. But another is: (defun all-bit-combinations (n) (loop for word from 0 below (expt 2 n) collect (integer-to-list-of-bits word n))) with (defun integer-to-list-of-bits (n width) (loop for i below width collect (if (logbitp i n) 1 0))) (all-bit-combinations 3) #| --> ((0 0 0) (1 0 0) (0 1 0) (1 1 0) (0 0 1) (1 0 1) (0 1 1) (1 1 1)) |#
20:31:15
pjb
nij-: yes, but you're advised not to change the parameters on which the dispatching has been done.
20:31:48
pjb
if your generic function has &key &rest or &optional, you may add parameters to call-next-method (pass the mandatory ones first).
20:32:49
pjb
HamzaShahid: also, why use list of bits? You could use bit-vectors instead. (defun integer-to-list-of-bits (n width) (loop with result = (make-array width :element-type 'bit :initial-element 0) for i below width when (logbitp i n) do (setf (aref result i) 1) finally (return result))) (all-bit-combinations 3) #| --> (#*000 #*100 #*010 #*110 #*001 #*101 #*011 #*111) |#
20:33:41
pjb
HamzaShahid: perhaps you could even use 2D arrays of bits? (make-array '(8 3) :element-type 'bit :initial-contents (all-bit-combinations 3)) #| --> #2A(#*000 #*100 #*010 #*110 #*001 #*101 #*011 #*111) |# ?
20:38:11
HamzaShahid
Ooooh cool thanks everyone, so turns out my solution is the worst but I will still present it :)
20:49:32
HamzaShahid
Used this at the end: (loop :for i :below (expt 2 (1- rows)) :collect (loop :for j :below 3 :collect (if (logbitp j i) 1 0)))
21:04:30
pjb
HamzaShahid: if you want to go thru a string you can do (defun integer-to-list-of-bits (n width) (map 'list (lambda (ch) (if (char= #\1 ch) 1 0)) (format nil "~VB" width n))) (integer-to-list-of-bits 9 5) #| --> (0 1 0 0 1) |#
21:08:07
pjb
HamzaShahid: or, using functions like you: (map 'bit-vector (compose parse-integer string) (format nil "~V,'0B" 5 9)) #| --> #*01001 |#
21:10:18
pjb
I've used the macro com.informatimago.common-lisp.cesarum.utility:compose, but you may use the function (alexandria:compose #'parse-integer #'string).
21:56:19
nij-
In a function I'd like to check if a statement is true or not, but I don't want to do it always, as it will slow down the system.
22:02:56
pjb
nothing implementation independent let you do that. You have to make your own flag and test.
22:03:16
pjb
nij-: in general, the question is whether you want this test to be made at compilation-time or at run-time.
22:04:21
pjb
nij-: at compilation-time you may use a feature and #+with-assertions (assert expression) Then you can write: (progn (declaim (optimization (safety 3))) (pushnew :with-assertions *features*)) before compiling.
22:04:54
pjb
nij-: at run-time: (defvar *with-assertions* nil) (when *with-assertions* (assert expression)) Then at run-time you may (setf *with-assertions* t).
22:14:41
bike
note that safety is a syntactic property, so it'll just be the safety at compile time, not at run time
22:14:53
pjb
You could do: (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *optimizations* '()) (setf *optimizations* '(optimization (safety 3))) (proclaim *optimizations*))) to save the current optimization. But you'd have to remember doing that everytime, everywhere.
22:44:15
bike
it's an earlier version of common lisp that had some operator for interrogating environments, which some implementations support as an extension
22:45:09
bike
https://github.com/Zulu-Inuoe/trivial-cltl2 https://github.com/alex-gutev/cl-environments declaration-information can be used to see what safety is
22:51:00
bike
common lisp is "common" because it was an attempt to unify about a million different lisps, including maclisp.
6:30:03
Josh_2
I have a print-object method specialized on a class X that uses ~T, I am trying to now have another print-object for a class Y that has an instance of X within it and I'm using ~S to display it, but how can I tabulate all of the output for X?
6:31:00
Josh_2
I use ~T in my print-object for Y to try and tabulate the display of instance X then only the first line is tabulated, I want to move all of the output over 10 spaces
8:16:12
dnhester90
I'm stuck in ASDF system definition failing me. I've tried reading and following examples from other projects to no avail...
8:18:41
dnhester90
Ah! @beach, how are you? I haven't been here for a while because I was busy with non lisp things, finally I'm back at it, and you helped me a lot a few years ago. Thank you!
8:20:09
dnhester90
Do you know any good guides (besides the official docs) for learning ASDF? I tried reading through the official docs but it wasn't so helpful in trying to debug my issue of a circular dependency...
8:22:30
beach
To simplify your ASDF system definition, remove the :DEPENDS-ON and just say :SERIAL T at the top. If it is then still circular, then there is a circular dependency not between components, but between systems. Also, restart your image to make sure there is no stale stuff.