mIRC Home    About    Download    Register    News    Help

Print Thread
brackets question #260220 16/03/17 12:05 AM
Joined: Nov 2013
Posts: 22
funfare Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Nov 2013
Posts: 22
I understand brackets fairly well, but consider this intentionally flaky code:
Code:
alias test {
  echo -a a $+ [ $+ b c d e ]
}


this prints:
Code:
ac d e


i'm curious about what's going on which causes the 'b' to dissapear.

Re: brackets question [Re: funfare] #260221 16/03/17 06:05 AM
Joined: Feb 2003
Posts: 2,662
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,662
Somebody else could explain it better than I, but there are some hard to describe interactions with evaluation brackets and concatenation. However, in practice, the formula that gets used the most looks like this:

a [ $+ [ b ] $+ [ c ] ]

as in

set -e %foo. $+ $cid $+ $chan Hello World.
echo -a %foo. [ $+ [ $cid ] $+ [ $chan ] ]


same as

set -e $+(%,foo.,$cid,$chan) Hello World.
echo -a $($+(%,foo.,$cid,$chan),2)



Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: brackets question [Re: funfare] #260224 17/03/17 11:20 AM
Joined: Dec 2002
Posts: 4,566
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,566
The [ ] brackets force evaluation of items inside the brackets before items outside of them can be evaluated.

In this case, $+ [ $+ b ] is saying: append b to the $+ outside of [ before it can be evaulated. This results in $+b.

$+anything is treated as $+ (which I think has always been the case).

Re: brackets question [Re: Khaled] #260240 19/03/17 09:07 PM
Joined: Nov 2013
Posts: 22
funfare Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Nov 2013
Posts: 22
interesting, thanks khaled.