Вы находитесь на странице: 1из 3

_for i _over range(2,100)

_loop
_if((i _mod 2)=0)
_then
write("even number:")
_else
write("odd number")
_endif
_endloop
$-----------------------------------------------------------------------------------def_slotted_exemplar(:mr,
{

{:name,"madhav"},
{:age,"sixteen"}
} :superclass

$ _method mr.sub(a,b,c)
_return (a-b-c)
_self
_endmethod
$
inst<<mr.sub(10,5,5)
-----------------------------------------------------------------------------f<<external_text_output_stream.new("D:m.txt")
f.newline()
$
MagikSF> f.write("dfvsdCV")
$
MagikSF> f.close()
$
------------------------------------------------------------------def_slotted_exempler(:sri_rr,
{{:name,"sri"},{:id,19570}})
_method sri_rr.add(a,b)
_return(a+b)
>>-_self
_endmethod
a_inst<<sri_rr.add(2,5)
-------------------------------------------------------------------s<<external_text_output_stream.new("F:\ab.xls")
f.newline()
f.write("dfvsdCV",%tab,"gsdh",%tab,"dfhwekjd")
f.close()
------------------------------------------------------------

MagikSF> gis_program_manager.databases
$
sw:hash_table(0)
-----------------------------------------------------------------------------

_for i _over c.fast_elements()


_loop
x.write(i.name,tab_char,i.external_name)
x.newline()
_endloop
$
--------------------------------------------------------------------------

Polymorphism
The same method name can be used for two or more object classes, and the method
for 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 has
knowledge of its own dimensions, the method defined on rectangle implements
width * 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.area
MagikSF> a_circle.area
This example illustrates polymorphism
--------------------------------------------------------------------------------------

Slotted objects have named fields, called slots, which can refer to any Magik ob
ject.
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, t
he
class rope behaves like a simple_vector except that it can change in length. Obj
ects
of this class have two slots one slot refers to the current length and the other r
efers
to a simple_vector in which the actual contents are maintained.
---------------------------------------------------------------------------------------debug_print_on() on each argument. For example:
MagikSF> x << 3
3
MagikSF> y << 4.5
4.500
MagikSF> show(x,y)
3 4.500

MagikSF> write(x,y)
34.500
MagikSF> print(x,y)
3
4.500
See Section 10.1 for more details
------------------------------------------------------------------------------sv<<simple_vector.new_with(12,25,56,69,98,87,74)
> _for i _over sv.elements()
_loop
_if (i = 12)
_then
write("mini num:",+i)
_elif (i = 98)
_then
write("max num ",+i)
_else write("not found")
_endif
_
$
mini num:12
not found
not found
not found
max num 98
not found
not found
----------------------------------------------------------------------------------The _clone creates a physical copy of the person object.
The _super statement allows objects to invoke an implementation of a method on t
he parent exemplar.
Objects can reference themselves using the _self statement. An object's slots a
re accessed and assigned using a dot notation.
Methods that are not part of the public interface of the object can be marked pr
ivate using the _private statement.
Private methods can only be called by _self, _super and _clone.
Optional arguments can be declared using the _optional statement.
Optional arguments that are not passed are assigned by Magik to the special obje
ct _unset (the equivalent of null).
The _gather statement can be used to declare a list of optional arguments.

Вам также может понравиться