Example Structure addMethod 004

 

 

Description

This example uses the added method ComputeProfit to operate on the user-defined type StockTransaction. The ComputeProfit method is added in the Method Dictionary through the addMethod function. The addValues method is invoked using the send function or by calling the method directly with its required arguments.

 

Details

Define a structure that contains information about a single stock transaction. The structure contains fields for the stock symbol, the purchase price of the stock, the selling price and a profit field.

(defineStructure StockTransaction: Symbol: Bought: Sold: Profit: ) Returns: StockTransaction

Define the method ComputeProfit to operate on the StockTransaction structure.

(addMethod StockTransaction: ComputeProfit: (lambda (e) (setq e.Profit (- e.Sold e.Bought )))) Returns: #<Dictionary 123456>

Define a new Structure "IBM" of the StockTransaction user-defined Structure type.

(define IBM (new StockTransaction: Symbol: "IBM" Bought: 100 Sold: 120)) Returns: StockTransaction

The method can be invoked simply by name.

(ComputeProfit: IBM) Returns:

Displays the result of the ComputeProfit method on the Structure "IBM".

(display IBM.Profit) Returns: 20

Notes and Hints

To view the entry in the methods Dictionary created by the addMethod function, you can use the method name to access the dictionary entry by

#<Dictionary 123456>[methodName:] or

To determine the number of assigned methods:

(length (methodsOf Structure: ))

(length (methodsOf StockTransaction:) )

To access the nth method name:

(methodsOf Structure: )[n 0]

(methodsOf StockTransaction: )[n 0]

To view the Methods Dictionary:

(display (methodsOf Structure: ))

Returns #{dic| addValues #<Lambda 5315>}

(display (methodsOf StockTransaction:))

Returns #{dic| ComputeProfit #<Lambda 5497>}
<

 

Related Examples

Here are examples of the addMethod function at work.

BitVector addMethod 023 Boolean addMethod 011 Boolean addMethod 012 Boolean send 010
Brick addMethod 008 Brick send 027 Character addMethod 013 CpxVector addMethod 028
Date addMethod 015 Date addMethod 016 Dictionary addMethod 005 Directory addMethod 006
FltVector addMethod 019 Function addMethod 017 Function addMethod 018 IntVector addMethod 020
List addMethod 025 List send 020 Matrix addMethod 008 NumMatrix addMethod 027
NumMatrix defmethod 024 NumVector addMethod 021 Number addMethod 014 ObjVector addMethod 022
ObjectRepository addMethod 026 ObjectRepository send 026 Pair addMethod 024 ShortVector addMethod 021
String addMethod 001 Structure addMethod 003 Structure addMethod 004 Symbol addMethod 002
Vector addMethod 007 Void addMethod 009 Void addMethod 010 Void defmethod 010

 

Function Links

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

addMethod

Here are a number of links to other related functions.

defmethod(Structure) send(Structure) methodsOf(Structure)

 

Argument Types

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

Structure Dictionary Symbol

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

BitVector addMethod 023 BitVector cdr 010 BitVector defmethod 020 BitVector methodsOf 021
BitVector send 018 Boolean addMethod 011 Boolean addMethod 012 Boolean defmethod 012
Boolean methodsOf 012 Boolean send 010 Brick addMethod 008 Brick defmethod 025
Brick methodsOf 024 Brick send 027 ByteVector isCharAlphabetic 003 ByteVector isCharAlphanumeric 003
ByteVector isCharLowercase 003 ByteVector isCharName 003 ByteVector isCharNumeric 003 ByteVector isCharUppercase 003
ByteVector isCharWhitespace 003 Character addMethod 013 Character defmethod 013 Character methodsOf 013
Character send 011 Context debug 001 Context getGlobalValue 001 Context getSymbolTable 001
Context globalBinding 001 CpxVector addMethod 028 CpxVector send 028 Date addMethod 015
Date addMethod 016 Date defmethod 015 Date methodsOf 015 Date send 013
Dictionary addMethod 005 Dictionary binarySearch 002 Dictionary cdr 003 Dictionary compare 004
Dictionary compareEQ 004 Dictionary compareGE 004 Dictionary compareGT 004 Dictionary compareLE 004
Dictionary compareLT 004 Dictionary compareNE 004 Dictionary comparison functions 004 Dictionary copy 002
Dictionary count 002 Dictionary defMethod 006 Dictionary delete 003 Dictionary delete 004
Dictionary insert 002 Dictionary inside 002 Dictionary isAtom 002 Dictionary isBound 002
Dictionary isDictionary 001 Dictionary isEqual 002 Dictionary isIdentical 002 Dictionary isInside 002
Dictionary isMember 002 Dictionary isObject 004 Dictionary isType 006 Dictionary length 005
Dictionary makeDictionary 001 Dictionary map 002 Dictionary mapc 002 Dictionary member 002
Dictionary methodsOf 007 Dictionary new 004 Dictionary objectToDictionary 001 Dictionary objectToDictionary 002
Dictionary objectToDictionary 003 Dictionary objectToDictionary 004 Dictionary ref 007 Dictionary ref 008
Dictionary ref 009 Dictionary refAttributes 002 Dictionary refValues 002 Dictionary remove 002
Dictionary resize 002 Dictionary send 004 Dictionary setAttributes 002 Dictionary setCdr 001
Dictionary setCdr 002 Dictionary setq 007 Dictionary setq 008 Dictionary setq 009
Dictionary sizeof 004 Dictionary sort 003 Dictionary sort 004 Dictionary sort 005
Dictionary type 007 Directory addMethod 006 Directory defMethod 007 Directory delete 006
Directory insert 003 Directory inside 003 Directory isBound 003 Directory isDirectory 001
Directory isInside 003 Directory isMember 003 Directory member 002 Directory methodsOf 008
Directory new 005 Directory new 006 Directory ref 010 Directory ref 011
Directory ref 012 Directory refAttributes 003 Directory refValues 003 Directory remove 003
Directory send 005 Directory setAttributes 003 Directory setq 010 Directory setq 011
Directory sort 008 Directory sort 009 FltVector addMethod 019 FltVector cdr 006
FltVector defmethod 017 FltVector delete 009 FltVector insert 005 FltVector methodsOf 017
FltVector send 015 Function addMethod 017 Function addMethod 018 Function defmethod 016
Function methodsOf 016 Function send 014 IntVector addMethod 020 IntVector cdr 007
IntVector defmethod 018 IntVector delete 010 IntVector insert 006 IntVector methodsOf 018
IntVector send 016 List addMethod 025 List defmethod 022 List methodsOf 022
List send 020 Matrix addMethod 008 Matrix cdr 007 Matrix cdr 008
Matrix defMethod 009 Matrix delete 009 Matrix insert 005 Matrix methodsOf 010
Matrix send 008 NumMatrix addMethod 027 NumMatrix cdr 011 NumMatrix defmethod 024
NumMatrix delete 014 NumMatrix insert 009 NumMatrix methodsOf 024 NumMatrix send 027
NumVector addMethod 021 NumVector cdr 008 NumVector defmethod 019 NumVector delete 011
NumVector insert 007 NumVector methodsOf 019 NumVector send 017 NumVector svmRegression 001
Number addMethod 014 Number defmethod 014 Number methodsOf 014 Number send 012
ObjVector addMethod 022 ObjVector cdr 009 ObjVector delete 012 ObjVector insert 008
ObjectRepository addMethod 026 ObjectRepository defmethod 023 ObjectRepository delete 013 ObjectRepository methodsOf 023
ObjectRepository send 026 Pair addMethod 024 Pair defmethod 021 Pair methodsOf 021
Pair send 019 PcodeVector methodsOf 020 ShortVector addMethod 021 ShortVector cdr 008
ShortVector defmethod 019 ShortVector delete 011 ShortVector insert 007 ShortVector methodsOf 019
ShortVector send 017 String addMethod 001 String defMethod 001 String defMethod 002
String isChar 001 String isCharAlphabetic 001 String isCharAlphanumeric 001 String isCharLowercase 001
String isCharName 001 String isCharNumeric 001 String isCharUppercase 001 String isCharWhitespace 001
String isEqual 001 String isEqual 002 String isObject 001 String isString 001
String isText 001 String isType 001 String isType 002 String isType 003
String methodsOf 001 String methodsOf 002 String methodsOf 003 String parse 001
String send 001 String setq 001 String sizeof 001 String string 001
String string 002 String string 003 String type 001 Structure addMethod 003
Structure addMethod 004 Structure append 004 Structure append 005 Structure apply 001
Structure apply 002 Structure binaryInsert 001 Structure binarySearch 001 Structure cdr 001
Structure cdr 002 Structure compareEQ 003 Structure compareGE 003 Structure compareGT 003
Structure compareLE 003 Structure compareLT 003 Structure compareNE 003 Structure comparison functions 003
Structure copy 001 Structure count 001 Structure defineStructure 001 Structure defineStructure 002
Structure defineStructure 003 Structure defmethod 004 Structure defmethod 005 Structure defstruct 001
Structure defstruct 002 Structure delete 001 Structure delete 002 Structure fieldsOf 001
Structure insert 001 Structure inside 001 Structure isAtom 001 Structure isBound 001
Structure isEqual 001 Structure isIdentical 001 Structure isInside 001 Structure isMember 001
Structure isObject 003 Structure isStructure 001 Structure isType 005 Structure length 004
Structure makeStructure 001 Structure makeStructure 002 Structure map 001 Structure mapc 001
Structure member 001 Structure methodsOf 005 Structure new 003 Structure objectToStructure 001
Structure objectToStructure 002 Structure objectToStructure 003 Structure objectToStructure 004 Structure ref 004
Structure ref 006 Structure refAttributes 001 Structure refValues 001 Structure remove 001
Structure resize 001 Structure send 003 Structure setAttributes 001 Structure setCdr 001
Structure setCdr 002 Structure setLastCdr 001 Structure setq 003 Structure setq 004
Structure setq 005 Structure setq 006 Structure sizeof 003 Structure sort 001
Structure sort 002 Structure sort 003 Structure type 003 Structure type 004
Structure type 005 Structure uniqueInsert 001 Structure uniqueInsert 002 Symbol *< 001
Symbol ++ 001 Symbol +< 001 Symbol -- 001 Symbol -< 001
Symbol /< 001 Symbol addMethod 002 Symbol append 003 Symbol compare 002
Symbol compareEQ 002 Symbol compareGE 002 Symbol compareGT 002 Symbol compareLE 002
Symbol compareLT 002 Symbol compareNE 002 Symbol comparison functions 002 Symbol defMethod 003
Symbol downcase 002 Symbol getGlobalValue 001 Symbol getGlobalValue 002 Symbol getSymbolTable 001
Symbol getSymbolTable 002 Symbol hashString 002 Symbol isCharAlphabetic 002 Symbol isCharAlphanumeric 002
Symbol isCharLowercase 002 Symbol isCharName 002 Symbol isCharNumeric 002 Symbol isCharUppercase 002
Symbol isCharWhitespace 002 Symbol isObject 002 Symbol isSymbol 001 Symbol isType 004
Symbol methodsOf 004 Symbol new 002 Symbol proplist 001 Symbol proprecord 001
Symbol putprop 001 Symbol ref 003 Symbol remProp 001 Symbol send 002
Symbol setq 001 Symbol setq 002 Symbol sizeof 002 Symbol symbol 001
Symbol symbol 002 Symbol type 002 Symbol upcase 004 Vector addMethod 007
Vector cdr 005 Vector cdr 006 Vector defmethod 008 Vector delete 007
Vector delete 008 Vector insert 004 Vector methodsOf 009 Vector send 006
Vector setAttributes 004 Vector setAttributes 005 Void addMethod 009 Void addMethod 010
Void defmethod 010 Void defmethod 011 Void methodsOf 011 Void send 009

How do I contact the AIS Server team?

You can always talk with the AIS at aiserver.sourceforge.net.