From: WoodHacker
Subject: Map routines
Date: 
Message-ID: <1159796364.455579.92940@i3g2000cwc.googlegroups.com>
This seems like a simple question, but....

Is there way of exiting a map routine (such as MAPHASH) once you've
found the value to want.   I don't
necessarily want to use RETURN-FROM because I want to stay in the
function the map is in.    I'm using
SBCL.

Bill

From: Bill Atkins
Subject: Re: Map routines
Date: 
Message-ID: <m2r6xqrg0l.fsf@weedle-24.dynamic.rpi.edu>
"WoodHacker" <········@comcast.net> writes:

> This seems like a simple question, but....
>
> Is there way of exiting a map routine (such as MAPHASH) once you've
> found the value to want.   I don't
> necessarily want to use RETURN-FROM because I want to stay in the
> function the map is in.    I'm using
> SBCL.
>
> Bill

(block foo
  (maphash (lambda (x)
	    (when (... x)
	      (return-from foo x)))
	   hash))
From: Thomas F. Burdick
Subject: Re: Map routines
Date: 
Message-ID: <xcvk63hmgqk.fsf@conquest.OCF.Berkeley.EDU>
Bill Atkins <······@rpi.edu> writes:

> "WoodHacker" <········@comcast.net> writes:
> 
> > This seems like a simple question, but....
> >
> > Is there way of exiting a map routine (such as MAPHASH) once you've
> > found the value to want.   I don't
> > necessarily want to use RETURN-FROM because I want to stay in the
> > function the map is in.    I'm using
> > SBCL.
> >
> > Bill
> 
> (block foo
>   (maphash (lambda (x)
> 	    (when (... x)
> 	      (return-from foo x)))
> 	   hash))

Or even

  (block nil
    (maphash (lambda (x) ... (return x)) hash))
From: Ari Johnson
Subject: Re: Map routines
Date: 
Message-ID: <m2k63iybnt.fsf@hermes.theari.com>
"WoodHacker" <········@comcast.net> writes:

> This seems like a simple question, but....
>
> Is there way of exiting a map routine (such as MAPHASH) once you've
> found the value to want.   I don't
> necessarily want to use RETURN-FROM because I want to stay in the
> function the map is in.    I'm using
> SBCL.

Is there any particular reason you are using MAPHASH instead of
GETHASH for this?  CL doesn't seem to specify an order that MAPHASH
will process entries in the hash table, so I hope you aren't relying
on any particular ordering to process all the entries "up to" the one
you are looking for.

Someone else has already shown you how to do what you say you want.  I
am just wondering if you really want to do it.
From: WoodHacker
Subject: Re: Map routines
Date: 
Message-ID: <1159822711.581775.26540@c28g2000cwb.googlegroups.com>
Ari Johnson wrote:
> "WoodHacker" <········@comcast.net> writes:
>
> > This seems like a simple question, but....
> >
> > Is there way of exiting a map routine (such as MAPHASH) once you've
> > found the value to want.   I don't
> > necessarily want to use RETURN-FROM because I want to stay in the
> > function the map is in.    I'm using
> > SBCL.
>
> Is there any particular reason you are using MAPHASH instead of
> GETHASH for this?  CL doesn't seem to specify an order that MAPHASH
> will process entries in the hash table, so I hope you aren't relying
> on any particular ordering to process all the entries "up to" the one
> you are looking for.
>
> Someone else has already shown you how to do what you say you want.  I
> am just wondering if you really want to do it.

The hash holds class data.   I'm looking for a match value in a class
that is not the map key.
I guess using return-from as indicated will work fine.   It just seems
there should be a way to
break out of the map.

Thanks...
From: GP lisper
Subject: Re: Map routines
Date: 
Message-ID: <slrnei37i1.fln.spambait@phoenix.clouddancer.com>
On 2 Oct 2006 13:58:31 -0700, <········@comcast.net> wrote:
>
> I guess using return-from as indicated will work fine.   It just seems
> there should be a way to break out of the map.

So what do you think 'return-from is doing??

-- 
Reply-To email is ignored.

-- 
Posted via a free Usenet account from http://www.teranews.com
From: Rahul Jain
Subject: Re: Map routines
Date: 
Message-ID: <8764f12mci.fsf@nyct.net>
"WoodHacker" <········@comcast.net> writes:

> This seems like a simple question, but....
>
> Is there way of exiting a map routine (such as MAPHASH) once you've
> found the value to want.   I don't
> necessarily want to use RETURN-FROM because I want to stay in the
> function the map is in.    I'm using
> SBCL.

Use LOOP instead.

http://www.lisp.org/HyperSpec/Body/sec_6-1-2-1-6.html

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist