[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: power set (Re: Modified keypad keys)
From: |
Juri Linkov |
Subject: |
Re: power set (Re: Modified keypad keys) |
Date: |
Mon, 01 Oct 2012 12:27:43 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu) |
> As an alternative to the recursive definition, I've also been using
> this iterative bitwise version (which I translated into Elisp from the
> C program at http://rosettacode.org/wiki/Power_set#C):
Often a C version doesn't translate nicely to Lisp when translated
literally. If you prefer an iterative version instead of recursive,
you could look at the Common Lisp section of
http://rosettacode.org/wiki/Power_set#Common_Lisp
and find the following short iterative version:
(defun powerset (xs)
(loop for i below (expt 2 (length xs)) collect
(loop for j below i for x in xs if (logbitp j i) collect x)))
There is no `logbitp' function in Emacs, but you could use a replacement
like this:
(defun logbitp (j i) (> (logand i (lsh 1 j)) 0))