[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: How to use constants in a case key form ?

William James

1/1/2016 11:32:00 PM

John Thingstad wrote:

> It is the trivial to check for duplicates and lookup key
>
> (defun duplicate-value-check ()
> (let* ((values (loop for v in (cdr *enum*) by #'cddr collect v))
> (sorted-values (sort values #'<))
> (position (mismatch sorted-values
> (remove-duplicates sorted-values))))
> (when position
> (let ((index (nth position sorted-values)))
> (error "key ~A has a value ~D duplicated"
> (nth (* index 2) *enum*) (nth index sorted-values))))))

Testing with ABCL:

(setq *enum* '(a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 2))
(duplicate-value-check )

CL-USER(3): Debugger invoked on condition of type SIMPLE-ERROR:
key C has a value 3 duplicated


It should have been:
key i has a value 2 duplicated

As usual, we see that although worshippers of CL (COBOL-Like) have
no real programming ability, they are so arrogant that they don't
even bother to test their code.

Do not ever make the mistake of hiring a worshipper of CL.
Do not ever make the mistake of paying for code written in CL.

MatzLisp (Ruby):

def dup_check plist
dups = plist.each_slice(2).group_by{|k,v| v}.select{|k,v| v.size > 1}
unless dups.empty?
puts "!! Duplicates found: !!"
dups.each{|k,v|
puts "Value #{k} shared by #{v.map(&:first)}"}
end
end

dup_check %w(a 2 b 3 c 4 d 5 e 6 f 4 g 8 h 9 i 2)
===>
!! Duplicates found: !!
Value 2 shared by ["a", "i"]
Value 4 shared by ["c", "f"]

dup_check %w(a 2 b 3 c 4 d 5 e 6 f 444 g 8 h 9 i 222)
==>nil

--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...
2 Answers

Kaz Kylheku

1/2/2016 2:08:00 AM

0

On 2016-01-01, WJ <w_a_x_man@yahoo.com> wrote:
> ... have no real programming ability, they are so ...

Such words require a URL to your ultra-reliable project of awesome
scope. Evidence is lacking that you've ever written anything that
couldn't be scribbled on a napkin.

Barry Margolin

1/2/2016 4:20:00 PM

0

In article <20160101180100.948@kylheku.com>,
Kaz Kylheku <kaz@kylheku.com> wrote:

> On 2016-01-01, WJ <w_a_x_man@yahoo.com> wrote:
> > ... have no real programming ability, they are so ...
>
> Such words require a URL to your ultra-reliable project of awesome
> scope. Evidence is lacking that you've ever written anything that
> couldn't be scribbled on a napkin.

PLEASE stop feeding our resident troll. Put him in your killfile so you
can ignore him like the rest of us have learned to do.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***