From: Eric Moss
Subject: using result of values-list on LWL
Date: 
Message-ID: <3C354E35.AA1E8F3B@alltel.net>
Hi all,

I downloaded a regex package from digitool's contrib directory, and it
behaves ok.  But when I try to use the results I have trouble:

CL-USER 1 > (setq foo (re:regexec "foo_protected.h" "_protected"))
	#((3 13))

CL-USER 2 > (setq bar (aref foo 0))
	(3 13)

CL-USER 3 > (values-list bar)
	3
	13

CL-USER 4 > (subseq "foo_protected.h" (values-list bar))
	"_protected.h"

CL-USER 5 > (subseq "foo_protected.h" 3 13)
	"_protected"


... and for good measure ...

CL-USER 6 > (subseq "foo_protected.h" (values-list '(3 13)))
	"_protected.h"

CL-USER 7 > (destructuring-bind (a b) '(3 13)
		(subseq "foo_protected.h" a b))
	"_protected"


It appears that the second value returned by values-list is being
ignored in lines 4 and 6.  Is this proper behavior?  If so, is
destructuring-bind (a la line 7) the best way to get the behavior of
line 5?

Thanks for pointers,

Eric

From: Steven M. Haflich
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <3C355CA7.D5744152@pacbell.net>
Eric Moss wrote:

> CL-USER 3 > (values-list bar)
>         3
>         13
> 
> CL-USER 4 > (subseq "foo_protected.h" (values-list bar))
>         "_protected.h"
> 
> CL-USER 5 > (subseq "foo_protected.h" 3 13)
>         "_protected"

> CL-USER 7 > (destructuring-bind (a b) '(3 13)
>                 (subseq "foo_protected.h" a b))
>         "_protected"
> 
> It appears that the second value returned by values-list is being
> ignored in lines 4 and 6.  Is this proper behavior?  If so, is
> destructuring-bind (a la line 7) the best way to get the behavior of
> line 5?

Yes.  See ANS 3.1.2.1.2.3 which explains that the "primary value" of
evaluating each argument subform in a function call is passed to the
function.

How to destructure this list is mostly a question of style, as the
generated code is not likely to be much different unless you do
something really obscure.

However, you could very simply write: (apply #'subseq "..." bar)
probably this is what the authors of this regexp api would have
intended.

If you _want_ a really obscure way to avoid destructuring, consider
using multiple-value-call.  Then reject using multiple-value-call as
being a dangerous habit (because when you use it, you have to make
sure that _every_ argument subform only returns the exact number of
values you expect, and many operators are either unspecified about
multiple values, or have careless implementations that leak extra
return values).
From: Kalle Olavi Niemitalo
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <87ofka8swz.fsf@Astalo.y2000.kon.iki.fi>
Eric Moss <········@alltel.net> writes:

> CL-USER 6 > (subseq "foo_protected.h" (values-list '(3 13)))
> 	"_protected.h"
[...]
> It appears that the second value returned by values-list is being
> ignored in lines 4 and 6.  Is this proper behavior?

Yes, it is.  In a function form, only the primary value of each
subform (other than the first one, which selects the function)
becomes an argument.  See CLHS 3.1.2.1.2.3 Function Forms.

> CL-USER 7 > (destructuring-bind (a b) '(3 13)
> 		(subseq "foo_protected.h" a b))
> 	"_protected"
[...]
> If so, is destructuring-bind (a la line 7) the best way to get
> the behavior of line 5?

You could instead do:

  (apply #'subseq "foo_protected.h" '(3 13))

I might prefer destructuring-bind with meaningful variable names,
though.  I am not familiar with LispWorks but it seems to me that
re:regexec returning #((3 13)) and subseq accepting 3 13 is only
a coincidence and re:regexec could as well have been defined to
return #((3 . 13)); because the functions use separately defined
formats for ranges in strings, I'd interpose a conversion even
though the formats appear to be identical at the moment.

However, the functions aren't likely to change, so I may be just
being superstitious.
From: Thomas A. Russ
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <ymiy9jdnayv.fsf@sevak.isi.edu>
Eric Moss <········@alltel.net> writes:

> 
> Hi all,
> 
> I downloaded a regex package from digitool's contrib directory, and it
> behaves ok.  But when I try to use the results I have trouble:
> 
> CL-USER 1 > (setq foo (re:regexec "foo_protected.h" "_protected"))
> 	#((3 13))
> 
> CL-USER 2 > (setq bar (aref foo 0))
> 	(3 13)
> 
> CL-USER 3 > (values-list bar)
> 	3
> 	13
> 
> CL-USER 4 > (subseq "foo_protected.h" (values-list bar))
> 	"_protected.h"
> 
> CL-USER 5 > (subseq "foo_protected.h" 3 13)
> 	"_protected"
> 
> 
> ... and for good measure ...
> 
> CL-USER 6 > (subseq "foo_protected.h" (values-list '(3 13)))
> 	"_protected.h"

As expected.  Only the first value is used, so this is equivalent to the
following forms:

   (subseq "foo_protected.h" (first '(3 13)))
   (subseq "foo_protected.h" 3 nil)

> CL-USER 7 > (destructuring-bind (a b) '(3 13)
> 		(subseq "foo_protected.h" a b))
> 	"_protected"
> 
> 
> It appears that the second value returned by values-list is being
> ignored in lines 4 and 6.  Is this proper behavior?

Yes.  You are calling a function and only the main returned value is
used.

> If so, is
> destructuring-bind (a la line 7) the best way to get the behavior of
> line 5?

Probably.

Although another option would be to exploit the way apply spreads a list
of the last set of arguments:

(apply #'subseq "foo_protected.h" '(3 13))   =>  "_protected"

This lets you have slightly cleverer code, but I would expect that the
destructuring bind would be faster in most implementations, as well as
being a bit clearer, especially with suitably renamed variables:

(destructuring-bind (start end) '(3 13)
  (subseq "foo_protected.h" start end))

> Thanks for pointers,
This is Lisp.  We don't do pointers :)

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Kalle Olavi Niemitalo
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <878zbd3x5w.fsf@Astalo.y2000.kon.iki.fi>
···@sevak.isi.edu (Thomas A. Russ) writes:

> This is Lisp.  We don't do pointers :)

There was an ACM journal called Lisp Pointers.
From: Thomas F. Burdick
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <xcvzo3sr4uv.fsf@apocalypse.OCF.Berkeley.EDU>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> ···@sevak.isi.edu (Thomas A. Russ) writes:
> 
> > This is Lisp.  We don't do pointers :)
> 
> There was an ACM journal called Lisp Pointers.

And where is it now? ;)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: ········@acm.org
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <0gIZ7.115359$Ad5.5042629@news20.bellglobal.com>
···@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> Kalle Olavi Niemitalo <···@iki.fi> writes:
> 
> > ···@sevak.isi.edu (Thomas A. Russ) writes:
> > 
> > > This is Lisp.  We don't do pointers :)
> > 
> > There was an ACM journal called Lisp Pointers.
> 
> And where is it now? ;)

Garbage collected?
-- 
(reverse (concatenate 'string ··········@" "enworbbc"))
http://www3.sympatico.ca/cbbrowne/rdbms.html
"Surely if the world can't get any other benefit from the existence of
Microsoft, at least people should stop arguing that popularity has any
connection with merit!" -- Brian Harvey <··@anarres.CS.Berkeley.EDU>
From: Thomas F. Burdick
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <xcvvgegr4bn.fsf@apocalypse.OCF.Berkeley.EDU>
········@acm.org writes:

> ···@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> > Kalle Olavi Niemitalo <···@iki.fi> writes:
> > 
> > > ···@sevak.isi.edu (Thomas A. Russ) writes:
> > > 
> > > > This is Lisp.  We don't do pointers :)
> > > 
> > > There was an ACM journal called Lisp Pointers.
> > 
> > And where is it now? ;)
> 
> Garbage collected?

Hmm, probably.  It must have been a weak reference.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Kent M Pitman
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <sfw3d1kh1ss.fsf@shell01.TheWorld.com>
···@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Kalle Olavi Niemitalo <···@iki.fi> writes:
> 
> > ···@sevak.isi.edu (Thomas A. Russ) writes:
> > 
> > > This is Lisp.  We don't do pointers :)
> > 
> > There was an ACM journal called Lisp Pointers.
> 
> And where is it now? ;)

Read my anti-ACM rants at Deja News.  Search may be for "lisp pointers",
"ethics", "pay", and "acm"... 
From: Dr. Edmund Weitz
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <m3ell4s9dc.fsf@bird.agharta.de>
Kent M Pitman <······@world.std.com> writes:

> Read my anti-ACM rants at Deja News.

Deja News has been acquired by Google almost a year ago... :)

Edi.

PS: But, yes, entering <http://www.deja.com/> or
<http://www.dejanews.com/> will bring you to the right place.
From: Eric Moss
Subject: Re: using result of values-list on LWL
Date: 
Message-ID: <3C366FD7.BF9053E7@alltel.net>
Thanks for the help. :)

Even when the subtleties trip me up, I still love lisp.

Eric