File predicat.icn

Summary

General purpose test procedures contributed by various people:

       Art Eschenlauer
       Kevin Wampler
       Steve Wampler (<i>sbw@tapestry.tucson.az.us</i>)
This is one of several files contributing to the lang package. Changes have been made to rationalise the code to use Unicon functions to avoid implementation dependencies.

This file is in the public domain.

Procedures:
Type, instanceof, isClass, isList, isProcedure, isRecord, isSet, isTable, istype, mapPackageInt2Ext

This file is part of the lang package.

Source code.

Details
Procedures:

Type(var)

Generates:
name of class var and all superclasses or standard Unicon type if var is not a class

A version of the type command designed to work on classes. For non class objects it behaves exactly as the standard type() function. For classes it generates the name of the class and the names of all classes that it inherits from

Note: For all entities defined in packages, returns user-level form of name, e.g.: "package::class" instead of the internal form of name, e.g.: "package__class".

We now use the langprocs procedure instead of implementation dependent code. As with isClass(), this can be tricked by evil people.

Object to examine


instanceof(x, className)

Parameters:
x
-- class to test
className
-- name of potential ancestor or actual potential ancestor. For example, instanceof(X,"lang::Object") and instanceof(X,Object()) are equivalent.
Returns:
x if x is an instance of className

Is className an ancestor of class x? Any class is considered as an ancestor of itself.


isClass(var)

Returns:
var if it's a class
Fails:
if var is not a class

How to tell if something is a class. We now use the langprocs procedure instead of implementation dependent code. This can be tricked, but only by evil people.

Object to examine


isList(x)

Returns:
x if x is a list
Fails:
if x is not a list

Is x a list?

Object to examine


isProcedure(x)

Returns:
x if x is a procedure
Fails:
if x is not a procedure

Is x a procedure?

Object to examine


isRecord(x)

Returns:
x if x is a record
Fails:
if x is not a record

Is x a record? A class is NOT a record! Use get_type(o) which returns "record" for all not object/class values that are records.

Object to examine


isSet(x)

Returns:
x if x is a set
Fails:
if x is not a set

Is x a set?

Object to examine


isTable(x)

Returns:
x if x is a table
Fails:
if x is not a table

Is x a table?

Object to examine


istype(x, s)

Parameters:
x
Object to examine
s
Returns:
x if it's of type s
Fails:
if x is not of type s

Is the type of x s? Works even if s is "class" or "record". Also works if s is an actual class instead of a string, as in:

   if istype(x,Object())
 

Will accept s as "numeric" to check if x is either a real or an integer.

Type to check against


mapPackageInt2Ext(s)

Intended for internal use only. Map "package__object" into "package::object". This is implementation dependent code and at present there is no Unicon function that returns the package information for any defined value. It also checks that the name is not in external format first and if it finds it is then it will return it unchanged. This allows "__" to be used in external names.



This page produced by UniDoc on 2021/04/15 @ 23:59:54.