zsh-users
 help / color / mirror / code / Atom feed
* revisiting passing arrays to functions
@ 2016-10-20 19:32 Filipe Silva
  2016-10-20 21:04 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Filipe Silva @ 2016-10-20 19:32 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 527 bytes --]

I searched through the archives and found this message about passing arrays
to functions: http://www.zsh.org/mla/users/2011/msg00967.html

Basically it says that it is not very comfortable:

% deref() { print ${(P)1}; print ${(P)1[-1]}; }
% array=(there once was a hacker named dave)
% deref array
there once was a hacker named dave
dave


You have to dereference the array first.

But that was in 2011. Is that changed? Do we have a way to pass zsh
arrays to a zsh function in a comfortable way?


thanks in advance.


Filipe

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

* Re: revisiting passing arrays to functions
  2016-10-20 19:32 revisiting passing arrays to functions Filipe Silva
@ 2016-10-20 21:04 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2016-10-20 21:04 UTC (permalink / raw)
  To: zsh-users

On Oct 20,  5:32pm, Filipe Silva wrote:
}
} I searched through the archives and found this message about passing arrays
} to functions: http://www.zsh.org/mla/users/2011/msg00967.html
} 
} But that was in 2011. Is that changed? Do we have a way to pass zsh
} arrays to a zsh function in a comfortable way?

Please define "comfortable"?  (I guess I should ask PWS that.)

The semantics of the (P) expansion flag have been improved, so that for
example in 5.2 it works more sensibly with nested substitutions and also
with associative arrays, which was practically impossible before.  

However, there's been nothing done to enable, for example, passing an
array as a pointer, because shell functions do not have named/typed
argument call signatures.  It's still necessary to pass the name of
the array in a positional parameter and then apply (P) to that, with
all the corresponding consequences around scoping of the name, e.g.,
possible clashes with locals declared in the function.


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

end of thread, other threads:[~2016-10-20 22:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-20 19:32 revisiting passing arrays to functions Filipe Silva
2016-10-20 21:04 ` Bart Schaefer

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).