magik language practices.txt
Post on 04-Feb-2018
222 Views
Preview:
TRANSCRIPT
-
7/21/2019 magik language practices.txt
1/3
-
7/21/2019 magik language practices.txt
2/3
MagikSF> gis_program_manager.databases$sw:hash_table(0)-----------------------------------------------------------------------------
_for i _over c.fast_elements()_loopx.write(i.name,tab_char,i.external_name)x.newline()
_endloop$--------------------------------------------------------------------------
PolymorphismThe same method name can be used for two or more object classes, and the methodfor each object class may define different behaviour.
For example, you might define a method named area on an object class rectangle,and a different method with the same name on class circle. If each object hasknowledge of its own dimensions, the method defined on rectangle implementswidth * height, while the method defined on circle implements p * radius squared.You could then use expressions like the following to get an appropriate result:MagikSF> a_rectangle.areaMagikSF> a_circle.areaThis example illustrates polymorphism---------------------------------------------------------------------------------------
Slotted objects have named fields, called slots, which can refer to any Magik object.This is the most common format, and almost all the core classes are slotted,including set, hash_table, external_text_input_stream and so on.Some classes of slotted object behave as though they are indexed. For example, theclass rope behaves like a simple_vector except that it can change in length. Objectsof this class have two slotsone slot refers to the current length and the other refersto a simple_vector in which the actual contents are maintained.--------------------------------------------------------------------------------
---------
debug_print_on()on each argument. For example:MagikSF> x y show(x,y)3 4.500
-
7/21/2019 magik language practices.txt
3/3
MagikSF> write(x,y)34.500MagikSF> print(x,y)34.500See Section 10.1 for more details-------------------------------------------------------------------------------sv
top related