Skip to content

_instantiate

bergsma edited this page Sep 26, 2014 · 5 revisions

#instantiate

###The instantiate function creates and runs a new instance of the concept.

Syntax

status = instantiate[  name ] ;

Arguments

  1. str name(optional)

The name of the instance. If the name is unspecified, then the instance name becomes a randomly generated 8 digit hex number.

Return Value

str status
  • $ACKNOWLEDGE : The new instance was created.

The STATUS variable is set to $ACKNOWLEDGE

  • %INVALID : Instance name must be alphanumeric characters only

The STATUS variable is set to %INVALID

  • %REJECTED : Instantiate to the requested name is not allowed if instance is not the concept instance.

The STATUS variable is set to %REJECTED

  • %TARGET : Instance is already created.

The STATUS variable is set to %TARGET

Warnings

  • %INVALID : Instance name must be alphanumeric characters only
  • %REJECTED : Instantiate to the requested name is not allowed if instance is not the concept instance.
  • %TARGET : Instance is already created.

Exceptions

  • %ARGUMENT: Invalid arguments. Usage: status = instantiate[ name ] ;

Description

The instantiate or instantiation functions create new instances of the concept.

When a HyperScript process is first created, it begins as the concept instance. The concept instance is the instance with the same name as the concept name. For example, a HyperScript program started as

hs -t concept_name

begins a thread of execution identified by concept_name. Only the concept instance can perform an instantiate function.

For example, if concept_name executes

    instantiate("my_instance");

then a new thread called _my_instance#concept_name _will be created and execution will continue under that new thread. The concept instance goes to an idle state.

The instantiation() function is identical to the instantiate() function except that the new instance created goes to idle rather than the concept instance.

Only the concept instance can instantiate. For example, if the name of the concept is "test", then the concept instance is "test". If 'test' executes:

instantiate ( "i1" ) ;

then the new instance "i1#test" is created. The original concept instance remains, but goes to an idle state. The new instance continues to execute at the next instruction following the instantiate instruction.

When a HyperScript program is started, it is often initiated by a CONNECT message sent by a remote application object. Initially, the sender of the CONNECT message only knows the target object by its concept name. For example, the target of the CONNECT message might be "furnace", where furnace is the concept name of the HyperScript object. When the HyperScript object starts executing, its name will be "urnace".

If the role of the HyperScript object is to be a client, it should probably create an unique instance name that differentiates it from the concept object. By executing the instantiate method, the instance name will be changed. For example, when the HyperScript program "furnace" executes the instantiate method, its instance name would change to a randomly generated hex number, for example the new instance name might become "1ea83b23#furnace".

Should another remote application object send a CONNECT message to "furnace", then it would start a new HyperScript program, and not interrupt the unique HyperScript "1ea83b23#furnace" instance.

If the role of the HyperScript object is to be a server to multiple clients, then it should not instantiate. This is so that any clients can send a QUERY message to the class object HyperScript program and receive back a REPLY message.

When the instantiate method is executed after receiving a CONNECT message from a client object (the sender) , the HyperScript program should send a message to the sender to inform it of its new identity. Often the sequence of messages involves a role reversal of client and sender, proceeding as follows: Object Actions

sender Beginning as a client, send a connect message to a "target" server.

|target@node|event|connect|sender|

The sender becomes a server, and then waits for QUERY messages from the target object.

target As a server, the target receives the connect message, then creates an unique instance and becomes a client.

target@node -> 3EF8D123#target@node

target The target client sends a QUERY or EVENT message to the sender server.

|sender|event|message|3EF8D123#target@node|...

sender The sender receives the QUERY or EVENT message from the target client, and records the new instantiated name of the target for future reference.

target@node -> 3EF8D123#target@node

Examples

CONNECT()
{
  puts { "I am ",self()," before instantiate" } ;
  instantiate() ;
  puts { "Now I am ",self()," after instantiate" } ;
  return ;
}
CONNECT();
puts { "I am ",self()," the next line after CONNECT" } ;

Related Links

instantation

Clone this wiki locally