William James
1/22/2016 11:27:00 PM
Marco Antoniotti wrote:
> "Vassili Bykov" <vassili@objectpeople.com> writes:
>
> > David Cooper wrote in message <3659C27D.7FF151E0@genworks.com>...
> > >Stig Hemmer wrote:
> > >>
> > >> I was just writing a couple of functions for converting from hash to
> > >> alist and vice versa.
> > >>
> > >> I'm wondering what to name these functions. Is it customary to use
> > >> "hash-to-alist" or "alist-from-hash" or something else?
> > >>
> > >
> > >You could get cute and name them hash2alist and alist2hash
> >
> > Cute would be hash->alist, like in Scheme.
> >
>
> Nope! The '->' is not CL style.
This is indicative of some of the traits of worshippers of CL (COBOL-Like).
1. All of them are grovelling conformists and lickspittles.
2. None of them have any taste.
3. They will do anything, no matter how idiotic, mindless, and perverse,
to vent their hatred for and envy of Scheme, which they perceive as a
heresy and a rival religion.
4. All of them are, at best, morons.
5. They behave as a pack of hyenas.
Do not ever make the egregious mistake of hiring a worshipper
of CL (COBOL-Like).
Do not ever make the egregious mistake of paying for software
written in CL (COBOL-Like).
> 'alist-to-hash-table' and
> 'hash-table-to-alist' seem more sensible.
To say that something is more sensible to an imbecile is
to damn that something.
>
> ;;; Just a start...
>
> (defun alist-to-hash-table (alist &key (test #'eql))
> (let ((new-ht (make-hash-table :test test)))
> (loop for assoc in alist
> do (setf (gethash (car assoc) new-ht) (cdr assoc)))
> new-ht))
MatzLisp (Ruby):
Hash[*[[:foo,2],[:bar,3]].flatten]
==>{:bar=>3, :foo=>2}
Another way:
table = Hash.new
[[:foo,2],[:bar,3]].each{|k,v| table[k]=v}
>
> (defun hash-table-to-alist (ht)
> (let ((new-alist ()))
> (loop for k being each hash-key in ht
> do (setf new-alist (acons k (gethash k ht) new-alist)))
> new-alist))
>
> ;;; The USING clause does not work well in CMUCL.
{:foo=>2, :bar=>3}.to_a
==>[[:foo, 2], [:bar, 3]]
--