Content deleted Content added
m <pre> for unsupported lang |
m →External links: HTTP to HTTPS for SourceForge |
||
(25 intermediate revisions by 17 users not shown) | |||
Line 1:
{{Short description|Object-oriented programming language}}
{{primary sources|date=January 2008}}
'''Magik''' is an [[object-oriented programming]] language that supports [[multiple inheritance]]
Magik (Inspirational Magik) was originally introduced in 1990 and has been improved and updated over the years. Its current version is
In July 2012, Magik developers announced that they were in the process of porting Magik language on the [[Java virtual machine]]. The successful porting was confirmed by [[Oracle Corporation]] in November of the same year.<ref>{{cite web
Line 68 ⟶ 69:
}, {:parent_object_a, :parent_object_b})
</pre>
This code fragment will define a new exemplar called <code>my_object</code> that has two slots (or fields) called <code>slot_a</code> (pre-
===Comparison===
Line 82 ⟶ 83:
a << "hello"
b << a
a = b # returns True (_true) because the values of a and b are equal a _is b # returns True (_true) because b was assigned the specific instance of the same object as a, rather than the value of a.
</pre>
===Methods===
Methods are defined on exemplars using the statements <code>_method</code> and <code>_endmethod</code>:
Line 92 ⟶ 95:
_endmethod
</pre>
It is convention to supply two methods <code>new()</code> (to create a new instance) and <code>init()</code> (to
<pre>
# New method
Line 99 ⟶ 102:
_endmethod
#
_private _method person.init(name, age)
# Call the parent implementation.
Line 119 ⟶ 122:
</pre>
===Iteration===
In Magik the <code>_while</code>, <code>_for</code>, <code>_over</code>, <code>_loop</code> and <code>_endloop</code> statements allow iteration.
<pre>
_block
_local s << 0
_local i << 0
_while i <= 100
_loop
s +<< i
i +<< 1
_endloop
>> s
_endblock
</pre>
Here, the _while is combined with _loop and _endloop.
<pre>
_method my_object.my_method(_gather values)
Line 147 ⟶ 166:
_endmethod
</pre>
===Procedures===
Magik also supports functions called procedures. Procedures are also objects and are declared using the <code>_proc</code> and <code>_endproc</code> statements. Procedures are assigned to variables which may then be invoked:
Line 156 ⟶ 176:
x << my_procedure(1, 2, 3) # x = 6
</pre>
===Language Quirks===▼
===Regular expression===
Magik supports // regular expression syntax:
<pre>
_if /Hello\,\s(\w)+!/.matches?("Hello, Magik!") _then
write("Got a match!")
_endif
</pre>
and to capture groups in Regex:
<pre>
/sw([0-9]+)-([0-9]+).*/.replace_all("sw65456-324sss", "$1") # "65456"
/sw([0-9]+)-([0-9]+).*/.replace_all("sw65456-324sss", "$2") # "324"
</pre>
===HTTP library===
Magik supports making HTTP or HTTPS requests via http library, see below examples:
<pre>
magikhttp << http.new()
magikhttp.url("https://www.google.com").get()
magikhttp.url("https://www.google.com").post({"User-agent", "Bot"}, "some data")
</pre>
Because Magik was originally developed in England, methods in the core smallworld libraries are spelled using [[British English]]. For example:
Line 164 ⟶ 210:
Like other programming language Magik too has collections. They include the following:
*Simple Vector
*Rope - a [[dynamic array]]
*[[Hash Table]]
*Property List
*Equality set
Line 181 ⟶ 227:
*[http://www.ge-energy.com/products_and_services/products/geospatial_systems_and_mobile_workforce/index.jsp Smallworld Product Suite Technology]
*[http://www.mdt.net/ MDT - Magik Development Tools] IDE for GE Smallworld GIS developers
*[
*[http://lambda-the-ultimate.org/classic/message5839.html#5886 Language forum post on Magik]
*[https://archive.today/20061020015202/http://cfis.savagexi.com/pages/technical_paper_5 Technical Paper No. 5 - An Overview of Smallworld Magik]
*[http://www.magikemacs.com/page/6/ GE Smallworld, Emacs Extensions for Magik developers] {{Webarchive|url=https://web.archive.org/web/20160425011048/http://www.magikemacs.com/page/6/ |date=2016-04-25 }}
*[https://marketplace.visualstudio.com/items?itemName=siamz.smallworld-magik Visual Studio Code extension for Smallworld Magik programming language.]
{{DEFAULTSORT:Magik}}
[[Category:Class-based programming languages]]
|