I was just experimenting with AEL2, and tried to use a for loop as per the example. Here's what I have. context new_pbx_betty_start { _X. => { for (x=0; ${x} < 3; x=${x} + 1) { Verbose(x is ${x} !); } }; } Here's the output. The var x never gets incremented! Is this a bug? The while loops seem to work ok. x is 0 ! -- Executing Set("SIP/3254101-db4b", " x=1") in new stack -- Executing Goto("SIP/3254101-db4b", "2") in new stack -- Goto (new_pbx_betty_start,36521478,2) -- Executing GotoIf("SIP/3254101-db4b", "1?3:6") in new stack -- Goto (new_pbx_betty_start,36521478,3) -- Executing Verbose("SIP/3254101-db4b", "x is 0 !") in new stack x is 0 ! -- Executing Set("SIP/3254101-db4b", " x=1") in new stack -- Executing Goto("SIP/3254101-db4b", "2") in new stack -- Goto (new_pbx_betty_start,36521478,2) -- Executing GotoIf("SIP/3254101-db4b", "1?3:6") in new stack -- Goto (new_pbx_betty_start,36521478,3) -- Executing Verbose("SIP/3254101-db4b", "x is 0 !") in new stack x is 0 ! -- Executing Set("SIP/3254101-db4b", " x=1") in new stack -- Executing Goto("SIP/3254101-db4b", "2") in new stack -- Goto (new_pbx_betty_start,36521478,2) -- Executing GotoIf("SIP/3254101-db4b", "1?3:6") in new stack -- Goto (new_pbx_betty_start,36521478,3) -- Executing Verbose("SIP/3254101-db4b", "x is 0 !") in new stack x is 0 ! -- Executing Set("SIP/3254101-db4b", " x=1") in new stack -- Executing Goto("SIP/3254101-db4b", "2") in new stack -- Goto (new_pbx_betty_start,36521478,2) -- Executing GotoIf("SIP/3254101-db4b", "1?3:6") in new stack -- Goto (new_pbx_betty_start,36521478,3) -- Executing Verbose("SIP/3254101-db4b", "x is 0 !") in new stack x is 0 ! -- Executing Set("SIP/3254101-db4b", " x=1") in new stack -- Executing Goto("SIP/3254101-db4b", "2") in new stack -- Goto (new_pbx_betty_start,36521478,2) -- Executing GotoIf("SIP/3254101-db4b", "1?3:6") in new stack -- Goto (new_pbx_betty_start,36521478,3) -- Executing Verbose("SIP/3254101-db4b", "x is 0 !") in new stack x is 0 !
----- Douglas Garstang <dgarstang@oneeighty.com> wrote:> context new_pbx_betty_start { > > _X. => { > for (x=0; ${x} < 3; x=${x} + 1) { > Verbose(x is ${x} !); > } > }; > > } > > Here's the output. > > The var x never gets incremented! Is this a bug? > The while loops seem to work ok.I would have to see the output of "show dialplan new_pbx_betty_start" to know exactly what is going on. However, I'm guessing that if you remove the space between the semicolon and the "x=${x} + 1", it will work. On pretty much everything except expression evaluation (such as ${x} < 3), Asterisk is sensitive to whitespace. " x=${x} + 1" was most likely translated directly into Set( x=$[${x} = 1]). That means you are setting the variable name, " x", including the leading space. That is not the same variable as ${x} which you are using everywhere else. -- Russell Bryant Software Developer Digium, Inc.
I actually did get it to work, by removing _all_ spaces from the for line... for (x=0;${x}<3;x=${x}+1) { This works for me. It's just a matter of finding WHICH space is breaking it. -----Original Message----- From: Rushowr [mailto:rushowr@phreaker.net] Sent: Sat 7/29/2006 12:24 PM To: 'Asterisk Users Mailing List - Non-Commercial Discussion' Cc: Subject: RE: [asterisk-users] AEL2 Looping >> context new_pbx_betty_start { >> >> _X. => { >> for (x=0; ${x} < 3; x=${x} + 1) { >> Verbose(x is ${x} !); >> } >> }; >> >> } >I would have to see the output of "show dialplan new_pbx_betty_start" to know exactly >what is going on. However, I'm guessing that if you remove the space between the >semicolon and the "x=${x} + 1", it will work. >On pretty much everything except expression evaluation (such as ${x} < 3), Asterisk >is sensitive to whitespace. " x=${x} + 1" was most likely translated directly into >Set( x=$[${x} = 1]). That means you are setting the variable name, " x", including >the leading space. That is not the same variable as ${x} which you are using >everywhere else. Russel, Stupid question, but isn't the AEL2 parser supposed to handle the above code first? Hypothetically, if the parser DOES handle the code the example given by Murf on voip-info (which is the exact code Douglas posted, other than the name new_pbx_betty_start) should work properly. Also, to answer your question, removing the space does not help. I'm actually getting a bug report together concerning this, and I tested it with and without spaces in multiple places in the for loop definition. I'd give examples but I don't have access right now. Keep up the great work guys! Rushowr _______________________________________________ --Bandwidth and Colocation provided by Easynews.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Douglas-- Just to let you know-- ----- Douglas Garstang <dgarstang at oneeighty.com> wrote:> context new_pbx_betty_start { > > _X. => { > for (x=0; ${x} < 3; x=${x} + 1) { > Verbose(x is ${x} !); > } > }; > > } > > Here's the output. > > The var x never gets incremented! Is this a bug? > The while loops seem to work ok.I've created bug 7635, then created a branch, found it indeed was a problem with the spaces in the for() statement, which is completely stupid, so I put in some code to clear out the spaces, and then tested in my dialplan. It worked fine. So, I merged the branch back into trunk, and closed 7635. So, try it again, after you update your trunk copy, of course, and see if it's acting more sanely. You should be able to put tabs, spaces, newlines, and returns in the for, with no problems. Many thanks for testing out AEL; We are trying to make it solid, but need help testing from the community. There's always some nits that a single programmer just plain will not bump into without help. Now is the time, folks! Play with AEL!!! murf -- Steve Murphy Software Developer Digium -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3227 bytes Desc: not available Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20060801/44f770a3/smime.bin