Mojo (programming language): Difference between revisions

Content deleted Content added
Ibrahh (talk | contribs)
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
Line 51:
 
== Features ==
Mojo was created for an easy transition from Python. The language has syntax similar to Python's, with inferred static typing,<ref>{{Cite web |title=Modular Docs - Mojo🔥 programming manual |url=https://docs.modular.com/mojo/programming-manual.html#parameterization-compile-time-metaprogramming |access-date=2023-10-19 |website=docs.modular.com |language=en}}</ref>, and allows users to import Python [[Modular programming|modules]].<ref name=":0">{{Cite web |title=Modular Docs - Mojo🔥 programming manual |url=https://docs.modular.com/mojo/programming-manual.html#python-integration |access-date=2023-10-31 |website=docs.modular.com |language=en}}</ref>. It uses [[LLVM]] and [[MLIR (software)|MLIR]] as its compilation backend.<ref name="InfoWorld" /><ref>{{cite tech report |last1=Lattner |first1=Chris |title=MLIR Primer: A Compiler Infrastructure for the End of Moore's Law |date=2019 |url=https://research.google/pubs/pub48035/ |access-date=2022-09-30 |last2=Pienaar |first2=Jacques}}</ref><ref>{{cite arXiv |last1=Lattner |first1=Chris |last2=Amini |first2=Mehdi |last3=Bondhugula |first3=Uday |last4=Cohen |first4=Albert |last5=Davis |first5=Andy |last6=Pienaar |first6=Jacques |last7=Riddle |first7=River |last8=Shpeisman |first8=Tatiana |last9=Vasilache |first9=Nicolas |last10=Zinenko |first10=Oleksandr |date=2020-02-29 |title=MLIR: A Compiler Infrastructure for the End of Moore's Law |class=cs.PL |eprint=2002.11054}}</ref>. The language also intends to add a [[foreign function interface]] to call C/C++ and Python code. The language is not [[source-code compatibility|source-compatible]] with Python 3, only providing a [[subset]] of its [[Syntax (programming languages)|syntax]], e.g. missing the {{mono|global}} keyword, list and dictionary comprehensions, and support for classes. Further, Mojo also adds features that enable performant low-level programming: {{mono|fn}} for creating [[Type system|typed]], [[Compiled language|compiled]] [[Function (computer programming)|function]]s and "struct" for [[Memory model (programming)|memory]]-optimized alternatives to [[Class (computer programming)|classes]]. Mojo structs support [[Method (computer programming)|methods]], [[Field (computer science)|fields]], [[operator overloading]], and [[Python syntax and semantics#Decorators|decorators]].<ref name="IWFirst" />
 
The language also provides a [[borrow checker]], an influence from [[Rust (programming language)|Rust]].<ref>{{Cite web |title=Ownership and borrowing {{!}} Modular Docs |url=https://docs.modular.com/mojo/manual/values/ownership.html |access-date=2024-02-29 |publisher=Modular}}</ref> Mojo {{Mono|def}} functions use value semantics by default (functions receive a copy of all arguments and any modifications are not visible outside the function), while [[Python (programming language) | Python]] functions use reference semantics (functions receive a reference on their arguments and any modification of a mutable argument inside the function is visible outside).<ref>{{Cite web |title=Mojo🔥 programming manual |url=https://docs.modular.com/mojo/programming-manual.html |access-date=2023-06-11 |publisher=Modular |archive-url=https://web.archive.org/web/20230611225929/https://docs.modular.com/mojo/programming-manual.html |archive-date=2023-06-11 |quote=All values passed into a Python def function use reference semantics. This means the function can modify mutable objects passed into it and those changes are visible outside the function. However, the behavior is sometimes surprising for the uninitiated, because you can change the object that an argument points to and that change is not visible outside the function. All values passed into a Mojo function use value semantics by default. Compared to Python, this is an important difference: A Mojo def function receives a copy of all arguments— it can modify arguments inside the function, but the changes are not visible outside the function.}}</ref>