The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Brackets on macro definition

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Jose Posted - 02/19/2001 : 11:05:04 AM
I always use curly brackets to define my macros, this way:


def mymacro {type Hello world;}


But this doesn't work properly with the special macro ErrorProc. In the manual examples it is defined with square brackets, like this:


Def NewFunction {
doc -cs F;%B=F$(count+1);create %B -f 10;
def ErrorProc [del %B];set %B;del -m ErrorProc;
};


But it is not explained anywere why this must be. And in other places I find it defined with curly brackets, like in this topic. But if I define it with curly brackets it is not executed when the error occurs! What must I use to have a standard code? I am using Origin 6.0 SR2.

j.

Edited by - Jose on 02/19/2001 11:06:30
4   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 02/22/2001 : 6:27:00 PM
There is no problem with nested {} in LabTalk anywhere, even though [] is also supported but should be discouraged, as we will be moving more and more to be consistent entirely with C notations. As for the ErrorProc, there is no need to delete that particular macro as the LabTalk interpreter executes the ErrorProc on error (whenever echo=1), and then that macro is automatically deleted. I am sorry that our documentation team has not been updated with details like that.

As for the reason this NewFunction macro not working, it should be apparent once you set echo=1, as it errors at the “set %B” command, so it never gets to bring up the function dialog box. The reason the “set” command failed was because the “create –f” command assumed a plot window to add the function into, while the “set” command assumed that the given function is plotted in the current window in order to open its dialog box. I would then assume that you ran this macro with the worksheet window active.


rtoomey Posted - 02/21/2001 : 4:41:42 PM
It may be that the alternating brace types are required for internally defined macros (as opposed to macros defined in Macros.CNF) only. However, I am not completely sure this is the reason. I will continue to look into this. If I uncover any additional insight, I will be sure to post it for you.

As for Gary's earlier report about the "archaic notation", I believe he provided you with the best answer he could at the time (it was a year ago after all!).

Incidentally, have you tried placing a type statement in the ErrProc macro to see if it really isn't executing? I did this during my testing and found that the ErrProc macro does in fact execute. However, it seems that the macro always stops at the set %B; for me. The last line of the NewFunction macro never gets executed because a Command Error! is generated every time.

Ryan

Jose Posted - 02/21/2001 : 11:13:11 AM
This makes sense.

But if you are right, why did Gary say in the above referenced topic "...I think the [ ]'s in place of the { }'s is an archaic notation", so he corrected his post after my suggestion?

Gary's script is as follows:


def newfunction {
for(ii=1;ii>0;ii++) {
%B=F$(ii);
if(exist(%B)==1) continue;
break;
};
create %B -f 10;
def ErrorProc {del %B;};
set %B;
del -m ErrorProc;
}


Why does it work? It shouldn't, after what you've said... And it seems it does as I use it everyday!

But the point is that I tried to copy his structure in a macro of mine, and I wasn't able: it stops when reaches the error, but ErrorProc is not executed.

(Perhaps Gary's doesn't work properly and I don't realize! I'll take a closer look one of these days).

j.

Edited by - Jose on 02/21/2001 11:14:02
rtoomey Posted - 02/20/2001 : 12:33:50 PM

Jose,



There is a limitation in our macro interpreter which prevents nested macros from working unless you enclose each macro's script inside braces of a different type (i.e. {} for the outer macro and then [] for the inner macro and so on...).



In other words, if you were to nest two macros using curly braces {} for both, the interpretor would think the closing curly brace for the internally defined macro was actually the closing curly brace for the first macro. This might cause all subsequent script to function incorrectly. I point out the curly braces I am referring to by bolding them and displaying them in red below.





def NewFunction
{
doc -cs F;
%B=F$(count+1);
create %B -f 10;
def ErrorProc
{
del %B;
}
;
set %B;
del -m ErrorProc;
};


 



Please note that I have entered a bug report which will hopefully address this limitation. If it is not addressed, I will make sure the limitation is documented.



Sincerely,
Ryan Toomey
OriginLab Corp.




The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000