More on conversions
Username:  
Password:
  > Home
v User Guide
    > Introduction
    v Hello World
       o Authoring program set up
       o Your first BEE Web Page
       o Your first BEE Section
       o Using Variables
       o What is the time now
       o More on conversions
    > Flow Control
    > Function Calls
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Hello World >> More on conversions <=  =>      <  1  >  
More on conversions

An alternative way to specify a Conversion is using the "conv" parameter:

display "The time now is ";

display "{sys%time}" conv="strftime:%d/%m/%Y (%a)";

display ". ";

 

The "conv" parameter applies to the whole string, so the following does NOT work because the Conversion will take the whole sentence as input:

// WRONG

display "The time now is {sys%time}. " conv="strftime:%d/%m/%Y (%a)";

 

The following will work:

// CORRECT

display "{sys%time}" conv="strftime:The time now is %d/%m/%Y (%a). ";

 

The simple format of {var|conv} is commonly used.  However, since {...} always evaluate to a string, if the conversion gives an array, you need to do it with "conv=...".  For example:

var a = "(array)x,y";

var b = "(var)a" conv="push:z";

display "{b|list} ";

// Output: 0=>'x',1=>'y',2=>'z'

 

Please note that variable a has acquired the extra element "z", and b is a copy of a after the conversion.  Because the input variable (a) is changed by the conversion "push", we call this conversion "passed by reference".

Some conversions do change the input (passed by reference).  They include ++, +=, -, -=, pop and shift.  For example:

var a = 2;

var a conv=++;

display "{a}";  // Output: 3

 

Or

var arr = "(array)x,y";

display "arr was: {arr|list}, ";

var item = "(var)arr" conv="pop";

display "but after popping out '{item}'<br> ";

display "arr becomes: {arr|list} ";

// Output:

// arr was: 0=>'x',1=>'y', but after popping out 'y'

// arr becomes: 0=>'x'

 

Only variables (as specified with the "(var)" type cast) can be passed by reference.  If we replace var item = "(var)arr" conv="pop"; with var item = "{arr|pop}";, {item} will still get the popped value ('y'), but variable arr will not change.

With the existing version of BEE, only ++ (or inc), +=, -- (or dec), -=, push, pop, shift and unshift are passed-by-reference conversions.

With user-defined conversions, the input variable can be altered in the conversion function.  So it is the programmer of such function who decides whether the conversion is a passed-by-reference or not.

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd