zsh-users
 help / color / mirror / code / Atom feed
* passing arrays
@ 2003-01-19 22:34 Le Wang
  2003-01-19 22:50 ` Zefram
  0 siblings, 1 reply; 5+ messages in thread
From: Le Wang @ 2003-01-19 22:34 UTC (permalink / raw)
  To: Zsh users list

Hi all.

Is it possible to pass an array into a function and
have the function return an array?

--
Le

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing arrays
  2003-01-19 22:34 passing arrays Le Wang
@ 2003-01-19 22:50 ` Zefram
  2003-01-19 23:01   ` Le Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Zefram @ 2003-01-19 22:50 UTC (permalink / raw)
  To: Le Wang; +Cc: Zsh users list

Le Wang wrote:
>Is it possible to pass an array into a function and
>have the function return an array?

The arguments to a function are an array, accessible through the
$1/$@/$argv parameters.

A function directly returns only a numeric status.  To return any
other information, it must either assign to a parameter or generate
output (which can be captured using $(...)).  The parameter assignment
technique is usually to be preferred, because it doesn't need to make any
system calls and it's easier for handling arrays.  We already have some
mechanisms where the shell calls a user-defined function and receives
a string or array return code in the parameters $REPLY or $reply;
I suggest that where you need string or array returns you use these
parameter names to do it.

-zefram


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: passing arrays
  2003-01-19 22:50 ` Zefram
@ 2003-01-19 23:01   ` Le Wang
  2003-01-20 11:46     ` Borzenkov Andrey
  0 siblings, 1 reply; 5+ messages in thread
From: Le Wang @ 2003-01-19 23:01 UTC (permalink / raw)
  To: Zsh users list

 --- Zefram <zefram@fysh.org> wrote: > Le Wang wrote:
> >Is it possible to pass an array into a function and
> >have the function return an array?
> 
> The arguments to a function are an array, accessible
> through the
> $1/$@/$argv parameters.

hmm.  I figured as much.

Here is an extension of the problem.  Say I have a
bunch of functions that operate on $PATH, how would I
generalize it so that it works with any $PATH like
variable?

--
le

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: passing arrays
  2003-01-19 23:01   ` Le Wang
@ 2003-01-20 11:46     ` Borzenkov Andrey
  0 siblings, 0 replies; 5+ messages in thread
From: Borzenkov Andrey @ 2003-01-20 11:46 UTC (permalink / raw)
  To: 'Le Wang', 'Zsh users list'


> Here is an extension of the problem.  Say I have a
> bunch of functions that operate on $PATH, how would I
> generalize it so that it works with any $PATH like
> variable?
> 

Hmm ... have you noticed that every your question needs at least one reply
that requests clarification what you really mean? No offence intended :)

Returning to your question - if 

foo "$path[@]"

does what you need I do not see any reason why

foo "$bar[@]"

does not. If the question is, how to get a pair of variables like path/PATH
- it is done with typeset,

typeset -T FOO foo

creates an array foo and "colon array" FOO.

-andrey


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: passing arrays
  2003-01-20 14:23 more interactive menu completion Le Wang
@ 2003-01-20 14:34 ` Le Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Le Wang @ 2003-01-20 14:34 UTC (permalink / raw)
  To: Zsh users list

 --- Borzenkov Andrey <Andrey.Borzenkov@siemens.com>
wrote: > 
> > Here is an extension of the problem.  Say I have a
> > bunch of functions that operate on $PATH, how
> would I
> > generalize it so that it works with any $PATH like
> > variable?
> > 
> 
> Hmm ... have you noticed that every your question
> needs at least one reply
> that requests clarification what you really mean? No
> offence intended :)

None taken.  I will strive to refine my problem
descriptions.  

My problem is as follows:

I currently have:

addToPath () {...}

and I use it as:

addToPath ~/bin/scripts

I would like to have

addToPathVar () {...}

and use it as:

addToPathVar CLASSPATH ~/java/lib

--
Le

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-01-20 14:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-19 22:34 passing arrays Le Wang
2003-01-19 22:50 ` Zefram
2003-01-19 23:01   ` Le Wang
2003-01-20 11:46     ` Borzenkov Andrey
2003-01-20 14:23 more interactive menu completion Le Wang
2003-01-20 14:34 ` passing arrays Le Wang

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).