mIRC Home    About    Download    Register    News    Help

Print Thread
#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.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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!
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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).

Joined: Nov 2013
Posts: 22
funfare Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Nov 2013
Posts: 22
interesting, thanks khaled.


Link Copied to Clipboard