* Arithmetic expression and TRY_BLOCK_ERROR
@ 2005-09-27 23:41 DervishD
2005-09-28 0:11 ` John Reese
0 siblings, 1 reply; 7+ messages in thread
From: DervishD @ 2005-09-27 23:41 UTC (permalink / raw)
To: Zsh Users
Hi all :)
I'll try to make it short ;) Why this:
...
(( TRY_BLOCK_ERROR = 0 ))
...
and not just this:
...
TRY_BLOCK_ERROR=0
...
?????
Thanks a lot :) If anyone is interested, take a look at zsh-users
8485 and 8489.
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-27 23:41 Arithmetic expression and TRY_BLOCK_ERROR DervishD
@ 2005-09-28 0:11 ` John Reese
2005-09-28 0:48 ` Will Maier
2005-09-28 8:46 ` DervishD
0 siblings, 2 replies; 7+ messages in thread
From: John Reese @ 2005-09-28 0:11 UTC (permalink / raw)
To: Zsh Users
2005/9/27, DervishD <zsh@dervishd.net>:
> Hi all :)
> I'll try to make it short ;) Why this:
> ...
> (( TRY_BLOCK_ERROR = 0 ))
> ...
> and not just this:
> ...
> TRY_BLOCK_ERROR=0
> ...
> ?????
>
The parentheses make it an integer variable. Also, that particular
assignment sets $? to 1. Maybe that's desired. I don't know.
Probably it's just that it's a fairly compact syntax for setting an
integer variable.
ofb:1% thok=0 17:08 ofb:~
ofb:1% (( khot = 0 )) 17:08 ofb:~
ofb:1% integer xox=0 17:08 <1> ofb:~
ofb:1% let box=0 17:08 ofb:~
ofb:1% typeset -p thok khot xox box 17:09 ofb:~
typeset thok=0
typeset -i khot=0
typeset -i xox=0
typeset -i box=0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-28 0:11 ` John Reese
@ 2005-09-28 0:48 ` Will Maier
2005-09-28 1:04 ` John Reese
2005-09-28 8:46 ` DervishD
1 sibling, 1 reply; 7+ messages in thread
From: Will Maier @ 2005-09-28 0:48 UTC (permalink / raw)
To: Zsh Users
On Tue, Sep 27, 2005 at 05:11:28PM -0700, John Reese wrote:
[snip]
> ofb:1% thok=0 17:08 ofb:~
Would you mind sharing the code in you .zshrc that generates that
attractive, spartan prompt?
--
[Will Maier]---------------[willmaier@ml1.net/wcmaier@jabber.ccc.de]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-28 0:48 ` Will Maier
@ 2005-09-28 1:04 ` John Reese
0 siblings, 0 replies; 7+ messages in thread
From: John Reese @ 2005-09-28 1:04 UTC (permalink / raw)
To: Zsh Users
2005/9/27, Will Maier <willmaier@ml1.net>:
> On Tue, Sep 27, 2005 at 05:11:28PM -0700, John Reese wrote:
> [snip]
> > ofb:1% thok=0 17:08 ofb:~
>
> Would you mind sharing the code in you .zshrc that generates that
> attractive, spartan prompt?
>
RPS1='%B%T %(0?,,<%?> )%m:%~%b'
PS1="%Bofb${WINDOW:+:$WINDOW}%#%b"
The right prompt displays the status code of the last command if it
was non-zero, and if I'm running inside screen the screen number goes
in the left prompt.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-28 0:11 ` John Reese
2005-09-28 0:48 ` Will Maier
@ 2005-09-28 8:46 ` DervishD
2005-09-28 14:55 ` Bart Schaefer
1 sibling, 1 reply; 7+ messages in thread
From: DervishD @ 2005-09-28 8:46 UTC (permalink / raw)
To: John Reese; +Cc: Zsh Users
Hi John :)
* John Reese <john.reese@gmail.com> dixit:
> 2005/9/27, DervishD <zsh@dervishd.net>:
> > Hi all :)
> > I'll try to make it short ;) Why this:
> > ...
> > (( TRY_BLOCK_ERROR = 0 ))
> > ...
> > and not just this:
> > ...
> > TRY_BLOCK_ERROR=0
> > ...
> > ?????
> >
> The parentheses make it an integer variable.
I know it, what I don't understand is why is it needed :? I mean,
that variable is already an integer variable.
> Also, that particular
> assignment sets $? to 1. Maybe that's desired. I don't know.
Not in that context (is the code of the "throw" and "catch"
functions).
> Probably it's just that it's a fairly compact syntax for setting an
> integer variable.
'let variable=0' is shorter ;) I really don't know the reason,
but I can find this kind of assignment everywhere :-/
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-28 8:46 ` DervishD
@ 2005-09-28 14:55 ` Bart Schaefer
2005-09-29 10:30 ` DervishD
0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2005-09-28 14:55 UTC (permalink / raw)
To: Zsh Users
On Sep 28, 10:46am, DervishD wrote:
}
} 'let variable=0' is shorter ;) I really don't know the reason,
} but I can find this kind of assignment everywhere :-/
I suspect it's simply Peter's preference to always use variables in
a consistent context, i.e., either in math expressions or out, not
some of each. A possible reason for this is future-proofing.
Suppose you have:
(( variable = 0 )) # or any other integer constant
Then later that gets changed to:
(( variable = othervariable ))
If you had instead written it without the (( )), the meaning of:
variable=othervariable
is entirely different.
Also, some people prefer the readability of being able to put spaces
around the "=".
However, doing integer/float assignments in math context is marginally
more efficient than doing them as plain assignments. In a single
command this is probably offset by the overhead of parsing the (( )),
but in a loop it could become important, and if you're in the habit of
always writing the (( )) you won't forget them where they matter.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Arithmetic expression and TRY_BLOCK_ERROR
2005-09-28 14:55 ` Bart Schaefer
@ 2005-09-29 10:30 ` DervishD
0 siblings, 0 replies; 7+ messages in thread
From: DervishD @ 2005-09-29 10:30 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
Hi Bart :)
* Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Sep 28, 10:46am, DervishD wrote:
> }
> } 'let variable=0' is shorter ;) I really don't know the reason,
> } but I can find this kind of assignment everywhere :-/
> I suspect it's simply Peter's preference to always use variables in
> a consistent context, i.e., either in math expressions or out, not
> some of each. A possible reason for this is future-proofing.
I understand, thanks for the explanation :)
> Also, some people prefer the readability of being able to put spaces
> around the "=".
Me, for example. In fact, the entire ((...)) syntax is quite good
when reading shource files, it really catches the eye.
> However, doing integer/float assignments in math context is marginally
> more efficient than doing them as plain assignments. In a single
> command this is probably offset by the overhead of parsing the (( )),
> but in a loop it could become important, and if you're in the habit of
> always writing the (( )) you won't forget them where they matter.
Thanks for both the explanation and the advice :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-09-29 10:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-27 23:41 Arithmetic expression and TRY_BLOCK_ERROR DervishD
2005-09-28 0:11 ` John Reese
2005-09-28 0:48 ` Will Maier
2005-09-28 1:04 ` John Reese
2005-09-28 8:46 ` DervishD
2005-09-28 14:55 ` Bart Schaefer
2005-09-29 10:30 ` DervishD
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).