* would it be nice to support =<< ? (not the haskell one)
@ 2016-11-09 18:02 khatar
2016-11-09 19:27 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: khatar @ 2016-11-09 18:02 UTC (permalink / raw)
Cc: zsh-users
hello people,
this is a script to render some json elements
json_elements=()
read json_elements\[1+$#json_elements] <<.
{ "user": "$USER", "uid": "$UID" }
.
read json_elements\[1+$#json_elements] <<.
{ "user": "$USER", "uid": "$UID" }
.
print "[ ${(j:
,:)json_elements} ]"
the thing is
read json_elements\[1+$#json_elements] <<.
is quiet hard to read and i really miss syntaxes
like the perl qq() or the ruby %Q.
would it be possible to get a
would it be smart?
i was thinking of a =<< operator so we could write
element=<<.
{ "user": "$USER", "uid": "$UID" }
.
instead of
read element <<.
{ "user": "$USER", "uid": "$UID" }
.
this would be very convenient to replace this
read json_elements\[1+$#json_elements] <<.
{ "user": "$USER", "uid": "$UID" }
.
by
json_elements+=<<.
{ "user": "$USER", "uid": "$UID" }
.
but is it smart? is it possible?
regards
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: would it be nice to support =<< ? (not the haskell one)
2016-11-09 18:02 would it be nice to support =<< ? (not the haskell one) khatar
@ 2016-11-09 19:27 ` Bart Schaefer
2016-11-10 8:15 ` khatar
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-11-09 19:27 UTC (permalink / raw)
To: Zsh Users; +Cc: Marc Chantreux
On Wed, Nov 9, 2016 at 10:02 AM, <khatar@phear.org> wrote:
>
> i was thinking of a =<< operator so we could write
>
> element=<<.
> { "user": "$USER", "uid": "$UID" }
> .
You can do this:
element=$(<<.
{ "user": "$USER", "uid": "$UID" }
.
)
This is handled efficiently, with a minimum of forking. Note that
it's necessary to follow the end marker with a newline before adding
the closing paren.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: would it be nice to support =<< ? (not the haskell one)
2016-11-09 19:27 ` Bart Schaefer
@ 2016-11-10 8:15 ` khatar
2016-11-10 16:44 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: khatar @ 2016-11-10 8:15 UTC (permalink / raw)
To: Zsh Users
On Wed, Nov 09, 2016 at 11:27:41AM -0800, Bart Schaefer wrote:
> element=$(<<.
> { "user": "$USER", "uid": "$UID" }
> .
> )
>
> This is handled efficiently, with a minimum of forking.
i got it in my mind but i have to admit i always think twice before
using $() for a little amount of data (but i never benchmark anything)
in another hand, i realize i assumed that using read with an heredoc
doesn't need a fork. was i wrong ?
anyway: thanks for the idea!
> Note that it's necessary to follow the end marker with a newline before adding
> the closing paren.
nice to point it out! i wasted hours on things like that when i was a
newbie.
regards
marc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: would it be nice to support =<< ? (not the haskell one)
2016-11-10 8:15 ` khatar
@ 2016-11-10 16:44 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-11-10 16:44 UTC (permalink / raw)
To: Zsh Users
On Nov 10, 8:15am, khatar@phear.org wrote:
}
} in another hand, i realize i assumed that using read with an heredoc
} doesn't need a fork. was i wrong ?
You were not wrong. Here-documents use a hidden temporary file, but
do not fork.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-10 16:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 18:02 would it be nice to support =<< ? (not the haskell one) khatar
2016-11-09 19:27 ` Bart Schaefer
2016-11-10 8:15 ` khatar
2016-11-10 16:44 ` 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).