Search found 5 matches

by ykm
Sun Nov 17, 2013 2:47 am
Forum: Common Lisp
Topic: Some basic lisp functions -trying to teach myself the basics
Replies: 12
Views: 26513

Re: Some basic lisp functions -trying to teach myself the ba

head about set-differrence?

Code: Select all

CL-USER> (set-difference '(1 2 3 4 5) '(3 4))
(5 2 1)
by ykm
Wed Oct 17, 2012 11:54 pm
Forum: Common Lisp
Topic: Adding element to a sorted list
Replies: 9
Views: 18269

Re: Adding element to a sorted list

Hi, Thanks to all of you for your responses. One thing I forgot to mention in the original question is that I am using this function in a loop and using the built-in sort after adding each element(as I needed the sorted list for the next iteration as well) sounded inefficient to me. Gohecca: Yes, in...
by ykm
Wed Oct 17, 2012 11:49 am
Forum: Common Lisp
Topic: Adding element to a sorted list
Replies: 9
Views: 18269

Adding element to a sorted list

Hi, I am trying to develop a function which does as mentioned in the subject line i.e adding an element to a list while maintaining the sort order. The following is what I have managed: (defun sort-push(lst n &key (test #'<) (key #'identity)) (labels ((rec (lst n acc) (if (null lst) (reverse (co...
by ykm
Wed Sep 26, 2012 12:57 am
Forum: Common Lisp
Topic: Convert integer to bit array and vice versa?
Replies: 8
Views: 25326

Re: Convert integer to bit array and vice versa?

Hi again, Following is the missing piece, a reverse function, converting the list obtained from the digit function, back to its number (defun reverse-digits(digits &optional (base 10) (power 0)) (if (null digits) 0 (+ (* (car digits) (expt base power)) (reverse-digits (cdr digits) base (incf pow...
by ykm
Wed Sep 26, 2012 12:46 am
Forum: Common Lisp
Topic: Convert integer to bit array and vice versa?
Replies: 8
Views: 25326

Re: Convert integer to bit array and vice versa?

Hi, A bit late, but I have developed a simple utility function to get the digits of a number in particular base (defun digits(n &optional (base 10)) (multiple-value-bind (q r) (floor n base) (if (and (zerop q) (zerop r)) nil (cons r (digits q base))))) CL-USER> (digits 10 2) (0 1 0 1) CL-USER> (...