Path: news.daimi.aau.dk!poe From: Peter Andersen Newsgroups: comp.lang.beta Subject: Re: Constants in Beta Date: 25 Apr 1995 15:54:33 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 71 Approved: mailtonews@daimi.aau.dk Distribution: world Message-ID: <3nj5vp$rum@belfort.daimi.aau.dk> NNTP-Posting-Host: daimi.daimi.aau.dk Baiss E. Magnusson writes: > > Hello, > > I see in the Beta demo programs a lot of lines where hard coded numeric > values exist: > > clear : (# exit 6 #); > exit 130 #); (* resource id's for edit menu *) > > windowId : (# exit 128 #); (* resource id of the application window > *) > do (100, 100) -> position; > (300, 300) -> size; > > Now in a real world application these numbers would exist in a separate > file and they would be reference by some constant name, or they > would be calculated based upon some environmental setting. > > This is accomplished in C with <#defines> so the above would be: > #define H_WINDOW 100 > ... > do (H_WINDOW, V_WINDOW) -> position; > (WINDOW_WIDTH, WINDOW_HEIGHT) -> size; > etc. > > What method in Beta would you use to replace all hard coded numeric > values with substitute values? > You could do it similarly: H_WINDOW: (# exit 100 #); V_WINDOW: (# exit 100 #); ... do (H_WINDOW, V_WINDOW) -> position; (WINDOW_WIDTH, WINDOW_HEIGHT) -> size; This method would force a recompilation each time you change the constants. You could instead use virtual constants: H_WINDOW:< IntegerValue(# do 100->value (* default *); INNER #); V_WINDOW:< IntegerValue(# do 100->value (* default *); INNER #); ... Then in some specialization you can override the default value (100) by furtherbinding: H_WINDOW::< (# do 200->value; INNER #); V_WINDOW::< (# do 200->value; INNER #); or final-binding: H_WINDOW:: (# do 200->value #); V_WINDOW:: (# do 200->value #); Then you will only have to recompile the specialization to change the size of all windows specified using H_WINDOW and V_WINDOW. Sincerely, Peter Andersen _____________________________________________________________________________ Mjolner Informatics Aps Phone: (+45) 86 20 20 00 ext. 2753 Science Park Aarhus Direct: (+45) 86 20 20 11 - 2753 Gustav Wieds Vej 10 Fax: (+45) 86 20 12 22 DK-8000 Aarhus C, Denmark Email: peter.andersen@mjolner.dk _____________________________________________________________________________ BETA is better -----------------------------------------------------------------------------