From: Robert H White
Subject: LISP question
Date: 
Message-ID: <64csi2$rn1$1@hecate.umd.edu>
Okay, quick question. I'm using Common LISP - is there a way to use 
wildcards in LISP?

Example: I want to count the number of words with ?'s in a list, (house 
cat r? mouse? joke net?) should return 3.

Is there any 'member' like command that can look in symbols for specific 
characters? Or do I have to convert the symbols to strings first?

Thanks in advance...

Rob
·······@mendron.com

From: Donald Fisk
Subject: Re: LISP question
Date: 
Message-ID: <346A00F8.4B05@bt-sys.bt.spamblock.co.uk>
Robert H White wrote:
> 
> Okay, quick question. I'm using Common LISP - is there a way to use
> wildcards in LISP?
> 
> Example: I want to count the number of words with ?'s in a list, (house
> cat r? mouse? joke net?) should return 3.
> 
> Is there any 'member' like command that can look in symbols for specific
> characters? Or do I have to convert the symbols to strings first?

To return (r? mouse? net?), you can use the function remove-if-not.   You
have to supply it with a function wildcard-p, which you'll have to define
yourself.   Refer to the chapter on strings in CLtL.   Then what you want
is simply (length (remove-if-not #'wildcard-p x)).

> Thanks in advance...

-- 
Le Hibou (mo bheachd fhe/in: my own opinion)
"What the ... This is Lambic!   Where's my culture of amoebic dysentery?"
			-- Gary Larson
From: Rainer Joswig
Subject: Re: LISP question
Date: 
Message-ID: <joswig-ya023180001211972346300001@news.lavielle.com>
In article <·············@bt-sys.bt.spamblock.co.uk>, Donald Fisk
<···········@bt-sys.bt.spamblock.co.uk> wrote:

> Robert H White wrote:
> > 
> > Okay, quick question. I'm using Common LISP - is there a way to use
> > wildcards in LISP?
> > 
> > Example: I want to count the number of words with ?'s in a list, (house
> > cat r? mouse? joke net?) should return 3.
> > 
> > Is there any 'member' like command that can look in symbols for specific
> > characters? Or do I have to convert the symbols to strings first?
> 
> To return (r? mouse? net?), you can use the function remove-if-not.   You
> have to supply it with a function wildcard-p, which you'll have to define
> yourself.   Refer to the chapter on strings in CLtL.   Then what you want
> is simply (length (remove-if-not #'wildcard-p x)).
> 
> > Thanks in advance...
> 
> -- 
> Le Hibou (mo bheachd fhe/in: my own opinion)
> "What the ... This is Lambic!   Where's my culture of amoebic dysentery?"
>                         -- Gary Larson

(flet ((count-symbols-with-char (symbols char)
         (count char
                symbols
                :key #'symbol-name
                :test #'(lambda (char string)
                          (find char string :test #'char=)))))
  (count-symbols-with-char
   '(house cat r? mouse? joke net?)
   #\?))

-- 
http://www.lavielle.com/~joswig/
From: Thomas A. Russ
Subject: Re: LISP question
Date: 
Message-ID: <ymig1p1vh84.fsf@sevak.isi.edu>
·······@osprey.smcm.edu (Robert H White) writes:

> 
> Okay, quick question. I'm using Common LISP - is there a way to use 
> wildcards in LISP?
> 
> Example: I want to count the number of words with ?'s in a list, (house 
> cat r? mouse? joke net?) should return 3.

(let ((list '(house cat r? mouse? joke net?)))
  (count-if #'(lambda (x) (find #\? (symbol-name x)
				:test #'char=))
            list))

==> 3

> Is there any 'member' like command that can look in symbols for specific 
> characters? Or do I have to convert the symbols to strings first?

Symbols don't have specific characters themselves.  The name of a
symbol, however, is a string which has specific characters.  In lisp,
symbols are objects with various fields, the symbol-name being merely
one of them.

Once that is done, you can look for string specific functions in the
strings chapter, or (in this case), find the function FIND in the
section on sequences.

FIND is a lot like member, except that it returns the object found,
rather than the remainder of a list starting with the object found.  I
suspect that it was the return value that causes the MEMBER function to
be limited to working only on lists rather than general sequences.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu