Search found 117 matches

by Warren Wilkinson
Mon Jan 07, 2019 5:15 pm
Forum: Common Lisp
Topic: Converting signed to unsigned: help, Lisp is in my way!
Replies: 6
Views: 5563

Re: Converting signed to unsigned: help, Lisp is in my way!

Many years later, here is a better way:

Code: Select all

;; Signed 16 to unsigned 16.
(deposit-field -3000 (byte 16 0) 0)
;; result: 62536

;; Signed 14 to unsigned 14.
(deposit-field -3000 (byte 14 0) 0)
;; 13384

;; Signed 8 to unsigned 8
(deposit-field -128 (byte 8 0) 0)
;; 128
by Warren Wilkinson
Sat Apr 20, 2013 12:14 pm
Forum: User Groups and Conferences
Topic: Lispers in Calgary (Alberta, Canada)
Replies: 2
Views: 10715

Re: Lispers in Calgary (Alberta, Canada)

I have a watch on this thread ;-)

We don't often meet. It's more like a once a year thing --- usually at a pub.
by Warren Wilkinson
Thu May 19, 2011 10:54 pm
Forum: Common Lisp
Topic: Convert integer to bit array and vice versa?
Replies: 8
Views: 16188

Re: Convert integer to bit array and vice versa?

There is also bit logic:

Code: Select all


(boole boole-ior #xFF00 #x00FF) ==> #xFFFF
(boole boole-and #xFF00 #x00FF) ==> 0

(ldb (byte 4 0) #xABCD) ==> #xD
(ldb (byte 4 4) #xABCD) ==> #xC
(ldb (byte 4 8) #xABCD) ==> #xB
(ldb (byte 4 8) #xABCD) ==> #xA

(ash #x00F0 8) ==> #x0F00
(ash #x00F0 -8) ==> #x000F

by Warren Wilkinson
Wed Apr 27, 2011 10:01 pm
Forum: Common Lisp
Topic: horn clause lisp
Replies: 4
Views: 2461

Re: horn clause lisp

Gugamilare has the right idea. Basically take your implication (==> a b) and turn it into (or (not a) b) form. Then simplify it as much as possible. If it simplifies to 1 positive literal and 1 or more negative literals, then it is a horn clause. This might help you get started. (defun simplify (sta...
by Warren Wilkinson
Wed Apr 20, 2011 10:11 am
Forum: The Lounge
Topic: Average Lisp age?
Replies: 36
Views: 64208

Re: Average Lisp age?

Denis: If you're looking for an interesting AI project, I noticed the other day that there doesn't seem to be a good open-source grammar checker. It must be hard though, otherwise Emacs would integrate with one.
by Warren Wilkinson
Mon Apr 18, 2011 11:19 pm
Forum: Common Lisp
Topic: Preventing lifetime analysis
Replies: 6
Views: 1815

Re: Preventing lifetime analysis

Here is one idea. Make a big array of pointers to foreign data elements. Then make your CLOS objects hold an index into this rather than an actual pointer. When the CLOS object is freed, the finalizer just pushes the index number onto a todo list. Then, at some safe-point in the code, you go through...
by Warren Wilkinson
Thu Mar 24, 2011 11:32 pm
Forum: Scheme
Topic: Generating a list?
Replies: 6
Views: 10658

Re: Generating a list?

Here is some Lisp code that computes (almost) what you want. It might be good enough. (defun color (N color) (if (zerop color) 0 (let ((N (truncate N 2))) (+ (* (boole boole-and 1 color) N) (color N (ash color -1)))))) (loop for i from 1 to 256 collecting (color 256 i)) (128 64 192 32 160 96 224 16 ...
by Warren Wilkinson
Tue Mar 22, 2011 11:49 pm
Forum: Scheme
Topic: Generating a list?
Replies: 6
Views: 10658

Re: Generating a list?

Here is one solution. But see below for a better one. (flet ((score (list i) (apply #'min (mapcar #'(lambda (elem) (abs (- elem i))) list)))) (defun next (list) ;; Add a value that is MOST different from every other element. (caar (sort (loop for i from 0 upto 16 unless (member i list) collect (cons...
by Warren Wilkinson
Thu Mar 17, 2011 12:49 pm
Forum: Common Lisp
Topic: Alternative (MACROEXPAND ...)
Replies: 4
Views: 3413

Re: Alternative (MACROEXPAND ...)

If you are using emacs, does C-c C-m [macroexpand-1 the form] do what you need? You can run it again inside expanded code to expand nested macros.
by Warren Wilkinson
Tue Mar 15, 2011 7:35 pm
Forum: Common Lisp
Topic: a very simple function
Replies: 3
Views: 1166

Re: a very simple function

Another way is to use rplacd [ or (setf (cdr ...) ...)] on the last element of the list to destructively set it to (list N).