Package lang |
Details |
Procedures: |
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 examineInvoke a procedure by string name. This is a convenience procedure for invoking a procedure given its string name. The primary convenience is that it maps external package procedure names into internal form for string-invocation. An example of its use would be to call the constructor for some class identified by its string name at runtime. @param f_name -- Name of procedure @param f_args... -- arguments to pass to the procedure, if any @return result of invocation
Cast the fields of this object to another object o.
Clone the given object
A closure binds some function parameters at definition time, leaving others unbound until invocation. This procedure defines a closure based on a function and a partial argument list. Unbound parameters are marked with instances of the Arg record constructor (note that the constructor is not called, it is simply a marker). Unbound parameters may be bound at the point of call by providing the values (in order) as arguments. Missing unbound parameters are replaced by &null. Extra arguments are appended.
Sample uses:
h := closure("^",Arg, 2) # x^2 h := closure("^",2, Arg) # 2^x h := closure("^",2) # also 2^x</p>
Compose multiple single-argument functions into a new function. The composite functions are evaluated right-to-left.
Examples:
Given:
h := compose(sqrt, abs) k := compose(integer, sqrt, ord) g := compose(h, k)the call g("1") is equivalent to:
sqrt(abs(integer(sqrt(ord("1")))))
Any Unicon entity that can be evaluated using the standard single-argument function call syntax can be composed. E.g. Given
m := compose(sqrt, closure("^", 2, Arg))The call m(3.5) is equivalent to:
sqrt(2^3.5)</p>
Recreate an object from the encoded string.
Return a string, being the encoded representation of the given object.
Compare this object with another by recursively comparing all members of the object.
Look for the method in the given object. @param obj The object in which to find the method @param method_name The name of the method @return a procedure object, being the method @fail if the method cannot be found.
generate_class_members(object)
Generate the values of the member variables of an object. All other values/objects will cause failure.
Generate the names of the member variables of an object. All other values/objects will cause failure.
Generate the record names for a record. All other values/objects will cause failure.
Get the Class object for this object
Get the Class corresponding to the given object or the class name
Return the value of the {n}th member variable of an object. The results are undefined for a non-class object.
Return the class name for the instance o <i>Deprecated in favor of function <tt>classname(o)</tt>.</i>
Return the id of the object, based on the string returned by {image()}. For types that do not produce such a value, this method will fail for values that do not have a serial number. <i>Deprecated in favor of function <tt>serial()</tt>.</i> @example @ x := [1, 2 ,3] @ write(::image(x)) @ write(get_id(x)) @ @ Output: @ list_5(3) @ 5
Return the name of the object. For a record this is the type name; for a class it is the class name, for a procedure the procedure name, for a file the filename and for a window the window name. For all other types, this method fails.
Return the type of the object, as a string. For standard Icon types, this is the value returned by the {type()} function. For records, it is the string "record" and for classes it is the string "class".
Return a hash code for this object. For any two objects for which {equals} indicates equality, the returned hash code should be the same.
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. |
x if x is an instance of className |
Is className an ancestor of class x? Any class is considered as an ancestor of itself.
Deprecated. There is a potential conflict with the name of this procedure and the method invoke in the Object class. For example, the assignment: call := invoke seems to think that the Object().invoke method is what's wanted, resulting in an error. Consequently, you should use invokeFcn instead.
fcn | thing (see explanation) to invoke |
args | remaining arguments are missing parameters in closure |
results of evaluating fcn, using args
to fill in gaps in closure |
invokes its first argument with the parameters provided by the remaining arguments, returning the result. Supported types are:
procedure - calls fcn!args integer - calls fcn!args string - calls fcn!args list - calls fcn[1]!(fcn[2:0] ||| args) co-expression - calls args@fcn Closure - calls fcn.call ! args
var if it's a class |
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 x if x is a list |
if x is not a list |
Is x a list?
Object to examine x if x is a procedure |
if x is not a procedure |
Is x a procedure?
Object to examine x if x is a record |
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 x if x is a set |
if x is not a set |
Is x a set?
Object to examine x if x is a table |
if x is not a table |
Is x a table?
Object to examineSucceed iff the given object is an instance of the class with the given name.
x | Object to examine
|
s |
x if it's of type s |
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 againstA PDCO for constructing anonymous 'functions' from co-expressions. It preactivates the co-expression argument to advance it to the first synchronization point. This allows the first 'call' to the anonymous function to pass a value in. The standard boiler plate for such anonymous functions is:
C := makeProc { repeat { inVal := outVal@&source # Code for the function goes here, where # any arguments are in the list inVal. # The return result goes into outVal } }Note that this example assumes that the resulting 'function' will be called using procedure invocation syntax, as in:
a := C(3,4,5)which is equivalent to:
a := [3,4,5]@C
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.
The default behaviour for Object.clone
object_equals(obj, other, seen)
The default behaviour for Object.equals
object_hash_code(o, depth, seen)
The default behaviour for Object.hash_code
object_to_string(o, depth, seen)
The default behaviour for Object.to_string
Convert the object to string ,descending structures to the given depth @param o The object to be converted. @param depth The depth of recursion; default is all levels
Switch over to using the simple (transient) property service.
Records: |
A marker that can be used in a list of function parameters to indicate a spot where an argument can be mapped. For example:
invokeFcn([f,3,Arg,5],4,6,7)invokes f(3,4,5,6,7)
This is a singleton class. At most one instance will ever exist, so the === test can be used.
Global variables: |