# Example Lambda send 009

#### Description

In this example, we will add a child Lambda, also named "square", that takes a number and computes the cube of that number. The send command will call the child Lambda instead of the like named method in the Methods Dictionary.

#### Details

Add a method named square which will compute the square of a number and install the message and the method in the Methods dictionary. Note, the Lambda argument is necessary for the send message to work but is not need by the square message.

 (defmethod Lambda: square: (anLambda aNum) (* aNum aNum) ) Returns: #

Define a function aNumberLambda that contains a persistent variable containing a number, p1. The persistent variable is set by an argument, x.

 (defun aNumLambda (x) (defun square(n) (* n n n)) (setq p1 x)) Returns: #

Initialize the persistent variable.

 (aNumLambda 10) Returns: 10

Invoke the method named square to compute the cube of a number.

 (send square: aNumLambda aNumLambda.p1) Returns: 1000

The method can be invoked simply by name:

 (square: aNumLambda aNumLambda.p1) Returns: 1000

Notes and Hints

When the receiver of the send command is an Lambda, the send command looks to see if the receiver has any child Lambdas with the same name as the message. If so, the child Lambda is called instead of the method in the Methods Dictionary.

#### Related Examples

Here are examples of the send function at work.

 BitVector send 018 Character send 011 CpxVector send 028 Date send 013 Dictionary send 004 Directory send 005 FltVector send 015 Function send 014 IntVector send 016 Lambda send 008 Lambda send 009 Matrix send 008 NumMatrix send 027 NumVector send 017 Number send 012 Pair send 019 ShortVector send 017 String send 001 Structure send 003 Symbol send 002 Vector send 006 Void send 009

Here is the link to the current function used in this example.

send

Here are a number of links to other related functions.

#### Argument Types

Here are the links to the data types of the arguments used in this example.

 Lambda Dictionary

Here are a number of links to examples having similar argument types.