gotoif accomplishes exactly what you want (except the one line part). On Thu, Dec 23, 2021 at 3:32 PM Antony Stone < Antony.Stone at asterisk.open.source.it> wrote:> On Thursday 23 December 2021 at 18:31:38, asterisk at phreaknet.org wrote: > > > > -----Original Message----- > > > From: asterisk-users <asterisk-users-bounces at lists.digium.com> On > Behalf > > > Of Dovid Bender > > > Sent: Thursday, December 23, 2021 12:11 PM > > > To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk- > > > users at lists.digium.com> > > > Subject: Re: [asterisk-users] Exec two commands with ExecIf > > > > > > Anyone know why this never made it into Asterisk? > > > > I believe it was deemed not to be of interest to the community. > > Assuming that the dates in that ticket refer to 2021 (I see only months > and > days, not years), I don't recall any discussion taking place with the > community about it, so that seems to me like a surprising explanation. > > After all, if GotoIf(), ExecIf() and While() are "deemed to be of > interest", > and therefore exist, why would a simple If() be deemed not to be of > interest? > > And, taking it from the other point of view, even if many people genuinely > think "meh, I don't think I'd use this", then surely they just avoid using > it, > as I suspect the majority of people do with DumpChan() (for example, to > take a > pretty obscure, yet still available, command at random). > > In short, what's the drawback to making If() available for those who would > use > it? > > Personally, I would very much like to see an If() statement made available. > > > Antony. > > -- > Tinned food was developed for the British Navy in 1813. > > The tin opener was not invented until 1858. > > Please reply to the > list; > please *don't* CC > me. > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Check out the new Asterisk community forum at: > https://community.asterisk.org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20211223/b798cd18/attachment.html>
asterisk at phreaknet.org
2021-Dec-23 21:33 UTC
[asterisk-users] Exec two commands with ExecIf
> -----Original Message----- > From: asterisk-users <asterisk-users-bounces at lists.digium.com> On Behalf > Of John Harragin > Sent: Thursday, December 23, 2021 4:16 PM > To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk- > users at lists.digium.com> > Subject: Re: [asterisk-users] Exec two commands with ExecIf > > gotoif accomplishes exactly what you want (except the one line part).Not really - GotoIf does generic branching, not execution. The closest thing is just using ExecIf twice. There are four general ways to do this in the dialplan that I can think of, each with their own pros and cons: Option 1: ExecIf, fewest lines of dialplan, but lots of repetition Same => n,ExecIf(${condition1}?App1(something)) Same => n,ExecIf(${condition1}?App2(somethingelse)) Same => n,ExecIf(${condition2}?App3(something)) Same => n,ExecIf(${condition2}?App4(somethingelse)) Option 2: If/EndIf, most "DRY" (don't repeat yourself), probably easiest to read/maintain Same => n,If(${condition1}) Same => n,App1(something) Same => n,App2(somethingelse) Same => n,EndIf() Same => n,If(${condition2}) Same => n,App3(something) Same => n,App4(somethingelse) Same => n,EndIf() Option 3: using GotoIf, hardest to read, maintain, and update Same => n,GotoIf(${condition1}?:postcond1) Same => n,App1(something) Same => n,App2(somethingelse) Same => n(postcond1),GotoIf(${condition2}?: postcond2) Same => n,App3(something) Same => n,App4(somethingelse) Same => n(postcond2),NoOp() Option 4: using GosubIf, also easy to read, but worst performance penalty, requires additional extensions/contexts, plus might be silly for just a few lines Same => n,GosubIf(${condition1}?condition1,1) Same => n,GosubIf(${condition2}?condition2,1) Exten => condition1,App1(something)) Same => n,App2(somethingelse) Same => n,Return() Exten => condition2,1,App3(something) Same => n,App4(somethingelse) Same => n,Return() Using GotoIf is probably the ugliest way to do something like this. If, ExecIf, even Gosub are arguably more elegant. Personally, I started off doing Option 3 (GotoIf) in my dialplan, moved to using Option 1 (ExecIf), and now I use Option 2 (If). I did this mainly because each progression made my dialplan easier to read and maintain. I don't use Gosub for code that would make sense to put in a function a regular procedural programming language (like C), and If/EndIf for stuff that would typically be done "inline", without a function call, particularly if only appears once in the whole dialplan. Often which paradigm is best depends on the context and goal.> > > On Thu, Dec 23, 2021 at 3:32 PM Antony Stone > <Antony.Stone at asterisk.open.source.it > <mailto:Antony.Stone at asterisk.open.source.it> > wrote: > > > On Thursday 23 December 2021 at 18:31:38, asterisk at phreaknet.org > <mailto:asterisk at phreaknet.org> wrote: > > > > -----Original Message----- > > > From: asterisk-users <asterisk-users-bounces at lists.digium.com > <mailto:asterisk-users-bounces at lists.digium.com> > On Behalf > > > Of Dovid Bender > > > Sent: Thursday, December 23, 2021 12:11 PM > > > To: Asterisk Users Mailing List - Non-Commercial Discussion > <asterisk- > > > users at lists.digium.com <mailto:users at lists.digium.com> > > > > Subject: Re: [asterisk-users] Exec two commands with ExecIf > > > > > > Anyone know why this never made it into Asterisk? > > > > I believe it was deemed not to be of interest to the community. > > Assuming that the dates in that ticket refer to 2021 (I see only > months and > days, not years), I don't recall any discussion taking place with the > community about it, so that seems to me like a surprising > explanation. > > After all, if GotoIf(), ExecIf() and While() are "deemed to be of > interest", > and therefore exist, why would a simple If() be deemed not to be of > interest? > > And, taking it from the other point of view, even if many people > genuinely > think "meh, I don't think I'd use this", then surely they just avoid > using it, > as I suspect the majority of people do with DumpChan() (for > example, to take a > pretty obscure, yet still available, command at random). > > In short, what's the drawback to making If() available for those who > would use > it? > > Personally, I would very much like to see an If() statement made > available. > > > Antony. > > -- > Tinned food was developed for the British Navy in 1813. > > The tin opener was not invented until 1858. > > Please reply to the list; > please *don't* CC me. > > -- > ____________________________________________________ > _________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com > -- > > Check out the new Asterisk community forum at: > https://community.asterisk.org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users
On Thursday 23 December 2021 at 22:16:26, John Harragin wrote:> gotoif accomplishes exactly what you want (except the one line part).Goto() and GotoIf() always remind me of programming in BASIC in the 1980s. Antony. -- "In fact I wanted to be John Cleese and it took me some time to realise that the job was already taken." - Douglas Adams Please reply to the list;