* Re: Implement a key-value deserialization or something similar
[not found] <CAKc7PVB19jOGwcsu5bL2zGuEioJXM9LuT009WDzZdg2eNobmQA__43171.2364581928$1473108546$gmane$org@mail.gmail.com>
@ 2016-09-06 0:20 ` Daniel Shahaf
2016-09-07 8:05 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Shahaf @ 2016-09-06 0:20 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh Users
Sebastian Gniazdowski wrote on Mon, Sep 05, 2016 at 22:47:11 +0200:
> Hello,
> I'm wondering how to best implement a parameter $x, say $7 – I mean a
> last parameter to a parameter-rich function – that would serve as "put
> various key-data things here to stop adding more parameters"? Possible
> call could be: afunction param1 param2 ... "MYDATA=1 OTHERDATA=true"
Like this:
% local -A reply=(mydata 1 otherdata true)
% () { echo ${${(P)7}[otherdata]} } {1..6} reply
true
Or you could adopt the Perl convention:
() {
local -A args=( "$argv[@]" )
} mydata 1 otherdata true
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Implement a key-value deserialization or something similar
2016-09-06 0:20 ` Implement a key-value deserialization or something similar Daniel Shahaf
@ 2016-09-07 8:05 ` Bart Schaefer
2016-09-07 18:26 ` Sebastian Gniazdowski
[not found] ` <CAKc7PVCjCwmGdZk+mKUK2YCps2zufeUv4-=WO_yfr=fJ8PtNwQ__7689.56577308035$1473272898$gmane$org@mail.gmail.com>
0 siblings, 2 replies; 7+ messages in thread
From: Bart Schaefer @ 2016-09-07 8:05 UTC (permalink / raw)
To: Zsh Users
On Sep 6, 12:20am, Daniel Shahaf wrote:
} Subject: Re: Implement a key-value deserialization or something similar
}
} Like this:
}
} % local -A reply=(mydata 1 otherdata true)
} % () { echo ${${(P)7}[otherdata]} } {1..6} reply
} true
}
} Or you could adopt the Perl convention:
}
} () {
} local -A args=( "$argv[@]" )
} } mydata 1 otherdata true
To more explicitly state what I think what Daniel is means with his
second example, the notion is that you can string key-value pairs
along in the argument list as ordinary arguments as long as you know
how many of the leading arguments are meaningful. E.g. if your
function takes four arguments, you can extend it like this:
FnOf4() {
local -A rest=( $argv[5,-1] )
argv[5,-1]=()
print -l "The positional args:" $*
if [[ -n $rest[foo] ]]; then
print -l "The foo arg:" $rest[foo]
fi
}
% FnOf4 these are positional and foo bar become rest
The positional args:
these
are
positional
and
The foo arg:
bar
If you don't know how many arguments will precede the "rest" pairs,
use a flag value such as "--" (that must not appear in the "rest"):
FnOfN() {
integer mark=$argv[(I)--]
local -A rest=( $argv[mark+1,-1] )
argv[mark,-1]=()
print -l "The positional args:" $*
if [[ -n $rest[foo] ]]; then
print -l "The foo arg:" $rest[foo]
fi
}
% FnOfN a batch of positional args and -- foo bar become rest
Daniel's first example amounts to setting this up in the caller and then
passing the name of the "rest" hash as $argv[-1], rather than passing
all the key-value pairs as positionals.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Implement a key-value deserialization or something similar
2016-09-07 8:05 ` Bart Schaefer
@ 2016-09-07 18:26 ` Sebastian Gniazdowski
[not found] ` <CAKc7PVCjCwmGdZk+mKUK2YCps2zufeUv4-=WO_yfr=fJ8PtNwQ__7689.56577308035$1473272898$gmane$org@mail.gmail.com>
1 sibling, 0 replies; 7+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-07 18:26 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 904 bytes --]
On 7 September 2016 at 10:05, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> On Sep 6, 12:20am, Daniel Shahaf wrote:
>
> To more explicitly state what I think what Daniel is means with his
> second example, the notion is that you can string key-value pairs
> along in the argument list as ordinary arguments as long as you know
> how many of the leading arguments are meaningful. E.g. if your
> function takes four arguments, you can extend it like this:
>
Yes, realized that after multiple hints, however still needed the
"concatenated string" data too, because much is to be passed. Single entry
looks like this (fixed columns skipped) and consists of in this case two
triples:
unit /Users/sgniazdowski/workspace/QtZekyllManager/libgit2
:MAKEFILE:1:CMAKELISTS:1: project
/Users/sgniazdowski/workspace/QtZekyllManager
:GIT:1:MAKEFILE:1:CMAKELISTS:1:PRO:1:
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Implement a key-value deserialization or something similar
[not found] ` <CAKc7PVCjCwmGdZk+mKUK2YCps2zufeUv4-=WO_yfr=fJ8PtNwQ__7689.56577308035$1473272898$gmane$org@mail.gmail.com>
@ 2016-09-07 22:52 ` Daniel Shahaf
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Shahaf @ 2016-09-07 22:52 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh Users
Sebastian Gniazdowski wrote on Wed, Sep 07, 2016 at 20:26:31 +0200:
> On 7 September 2016 at 10:05, Bart Schaefer <schaefer@brasslantern.com> wrote:
> > On Sep 6, 12:20am, Daniel Shahaf wrote:
> > To more explicitly state what I think what Daniel is means with his
> > second example, the notion is that you can string key-value pairs
> > along in the argument list as ordinary arguments as long as you know
> > how many of the leading arguments are meaningful. E.g. if your
> > function takes four arguments, you can extend it like this:
> >
>
> Yes, realized that after multiple hints,
Sorry I wasn't clear. I'd have been happy to clarify, but I saw no
followup questions on list.
Bart — thanks for explaining my answer.
> however still needed the
> "concatenated string" data too, because much is to be passed. Single entry
> looks like this (fixed columns skipped) and consists of in this case two
> triples:
>
> unit /Users/sgniazdowski/workspace/QtZekyllManager/libgit2
> :MAKEFILE:1:CMAKELISTS:1: project
> /Users/sgniazdowski/workspace/QtZekyllManager
> :GIT:1:MAKEFILE:1:CMAKELISTS:1:PRO:1:
Cheers,
Daniel
> Best regards,
> Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Implement a key-value deserialization or something similar
2016-09-05 21:25 ` Sebastian Gniazdowski
@ 2016-09-05 21:59 ` Sebastian Gniazdowski
0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-05 21:59 UTC (permalink / raw)
To: Zsh Users
Example Zsh solution could be: afunc ...normal parameters...
"MYDATA:1:OTHERDATA:2:" and then: local
mydata="${7/(#b)*MYDATA:([^:]#):*/$match[1]}". I could write a
function to hide the somewhat complex pattern code, it would work like
this: get_key "$7" "MYDATA"; local mydata=$REPLY. That solution works
but I really want to research this and find solution that's best or
useful in a specific way. Any thoughts?
Best regards,
Sebastian Gniazdowski
On 5 September 2016 at 23:25, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> PS. To put it other way, it's that I need to pass a bunch of simple
> marks on some data to a function and don't need reserved positional
> parameters for them, especially because some of the marks are
> optional.
>
> Best regards,
> Sebastian Gniazdowski
>
>
> On 5 September 2016 at 22:47, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
>> Hello,
>> I'm wondering how to best implement a parameter $x, say $7 – I mean a
>> last parameter to a parameter-rich function – that would serve as "put
>> various key-data things here to stop adding more parameters"? Possible
>> call could be: afunction param1 param2 ... "MYDATA=1 OTHERDATA=true"
>>
>> Best regards,
>> Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Implement a key-value deserialization or something similar
2016-09-05 20:47 Sebastian Gniazdowski
@ 2016-09-05 21:25 ` Sebastian Gniazdowski
2016-09-05 21:59 ` Sebastian Gniazdowski
0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-05 21:25 UTC (permalink / raw)
To: Zsh Users
PS. To put it other way, it's that I need to pass a bunch of simple
marks on some data to a function and don't need reserved positional
parameters for them, especially because some of the marks are
optional.
Best regards,
Sebastian Gniazdowski
On 5 September 2016 at 22:47, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> Hello,
> I'm wondering how to best implement a parameter $x, say $7 – I mean a
> last parameter to a parameter-rich function – that would serve as "put
> various key-data things here to stop adding more parameters"? Possible
> call could be: afunction param1 param2 ... "MYDATA=1 OTHERDATA=true"
>
> Best regards,
> Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Implement a key-value deserialization or something similar
@ 2016-09-05 20:47 Sebastian Gniazdowski
2016-09-05 21:25 ` Sebastian Gniazdowski
0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-05 20:47 UTC (permalink / raw)
To: Zsh Users
Hello,
I'm wondering how to best implement a parameter $x, say $7 – I mean a
last parameter to a parameter-rich function – that would serve as "put
various key-data things here to stop adding more parameters"? Possible
call could be: afunction param1 param2 ... "MYDATA=1 OTHERDATA=true"
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-09-07 22:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAKc7PVB19jOGwcsu5bL2zGuEioJXM9LuT009WDzZdg2eNobmQA__43171.2364581928$1473108546$gmane$org@mail.gmail.com>
2016-09-06 0:20 ` Implement a key-value deserialization or something similar Daniel Shahaf
2016-09-07 8:05 ` Bart Schaefer
2016-09-07 18:26 ` Sebastian Gniazdowski
[not found] ` <CAKc7PVCjCwmGdZk+mKUK2YCps2zufeUv4-=WO_yfr=fJ8PtNwQ__7689.56577308035$1473272898$gmane$org@mail.gmail.com>
2016-09-07 22:52 ` Daniel Shahaf
2016-09-05 20:47 Sebastian Gniazdowski
2016-09-05 21:25 ` Sebastian Gniazdowski
2016-09-05 21:59 ` Sebastian Gniazdowski
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).