Magik (programming language): Difference between revisions

Content deleted Content added
No edit summary
Bender the Bot (talk | contribs)
m External links: HTTP to HTTPS for SourceForge
 
(23 intermediate revisions by 15 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]], and [[polymorphism (computer science)|polymorphism]], and it is [[dynamic typing|dynamically typed]]. It was designed and implemented in 1989 by Arthur Chance, of [[Smallworld]]|Smallworld Systems Ltd,.]] as part of Smallworld Geographical Information System (GIS). Following Smallworld's acquisition in 2000, Magik is now is provided by [[GE Energy]], still as part of its [[Smallworld]] technology platform.
 
Magik (Inspirational Magik) was originally introduced in 1990 and has been improved and updated over the years. Its current version is 5.12.
 
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-initializedinitialised to 34) and <code>slot_b</code> (pre-initialised to "hello") that inherits from two existing exemplars called <code>parent_object_a</code> and <code>parent_object_b</code>.
 
===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 initializeinitialise an instance).
<pre>
# New method
Line 99 ⟶ 102:
_endmethod
 
# InitializeInitialise method.
_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 157 ⟶ 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>
 
===Language Quirksquirks===
Because Magik was originally developed in England, methods in the core smallworld libraries are spelled using [[British English]]. For example:
 
Line 165 ⟶ 210:
Like other programming language Magik too has collections. They include the following:
*Simple Vector
*Rope - a [[dynamic array]]
*Rope
*[[Hash Table]]
*Property List
*Equality set
Line 182 ⟶ 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
*[httphttps://sourceforge.net/projects/magikcmpnts Open Source (SourceForge)]
*[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]]