[e-lang] Couple of newbie questions

Kevin Reid kpreid at mac.com
Wed Dec 27 18:47:04 CST 2006


On Dec 27, 2006, at 12:48, Chris Rathman wrote:

> What is the effect of leaving out the pragma.syntax instruction?   
> From glancing at the documentation, it seems to come highly  
> recommended - indicating that some of the examples won't run.  Is  
> the default not the latest version?

The purpose is compatibility with versions *newer* than the code was  
written for, if the syntax changes.

> But I was also meaning to ask if there's a method that is available  
> to determine the type of variable?

Variables (slots) don't have types (but they may have guards); values  
do.

> Something along the lines of:
>
>     if (!xs.isArray()) return false
>
> In the tree examples, the input is either a list or an integer, so  
> when I hit the leaves it generates an exception - not likely to be  
> efficient.

There are two relevant parts of E: __getAllegedType/0, which is a  
method all objects have, but may implement to return an arbitrary  
type object; and guards, which are reliable but coerce to a specific  
type.

In your case, you want the List or Tuple guards.

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list