Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Moscow Python Meetup №97. Daniel Arango (EAFIT ...

Moscow Python Meetup №97. Daniel Arango (EAFIT (Medelin, Columbia), Student). How to make a multilingual programing language in Python

Multilingual programming language means it is programmed not just in English; you can use Russian, German, English, and more. This programming language is functional because it is a Lisp dialect. I will explain some features of Lisp, such as the environment, S-expressions, and how to optimize recursion in functional programming languages.

Видео: https://moscowpython.ru/meetup/97/multilingual-programming/

Moscow Python: http://moscowpython.ru
Курсы Learn Python: http://learn.python.ru
Moscow Python Podcast: http://podcast.python.ru
Заявки на доклады: https://bit.ly/mp-speaker

Moscow Python Meetup

December 24, 2024
Tweet

More Decks by Moscow Python Meetup

Other Decks in Programming

Transcript

  1. Who am I? DD -I made this talking Colombia. -PyCon

    Colombia Lightning Talk -Novo Hamburgo University, Simultaneous Multilingual Translation Systems -I won 3 competitions at my uni with my projects. -Leader of ML group in Eafit University.
  2. What is Deru Lisp dialect in De-> Deustche Spreche (German

    language) Ru->Русский язык (Russian language) My Motivations
  3. John MCcarthy Lisp Paper LISt Procecing What is lisp? Not

    a programming Language Is a metaprogramming language
  4. Examples print("hello word") (печать "привет Мир") print("hello word") print("hello",input("how is

    your name")) This is not an esoteric programing language, is more powerful than that, but I didn't see the future for this programming language, except for learning how to make a programing language
  5. Notes The first element is the function. The others are

    arguments. (F a1 a2 a3 … ax) F is a function name. a1 ... ax are arguments.
  6. Notes Deru is not a pure Functional Programming because it

    has side effects and monads are not implemented Is interpreted Is not Complicated, sorry I mean Compiled
  7. https://github.com/kanaka/mal How to make a lisp Dialect in python Index

    • step1_REPL • step2_eval • step3_lexical,syntaxis and semantic analysis • step4_Environment • step5_Control_Structures • … and more https://github.com/kanaka/mal
  8. Eval Python eval() is different from this eval. Lisp (F

    a1 a2 a3 … ax) How to convert Sintaxis of the functions Python F ( a1 a2 a3 … ax ) The EVAL function processes Lisp code as structured lists, treating them as directly evaluable syntax. It interprets constructs dynamically, supporting macros, conditionals without an explicit AST.
  9. Tokenization How look the code tokenized Regular expression for tokenization

    H code NOT Tokenized The process of separating the string into substrings (referred to as tokens) organizes the information that is being passed to the parser.
  10. Syntax's analysis •The process for verifying that our grammar is

    being followed •Normally Syntax Analysis builds an abstract syntax tree •Here no, you traverse the tree with the eval recursion
  11. Grammar • A grammar is a set of rules that

    describe how tokens can be combined to form valid statements and expressions in the language.
  12. S-expressions There are two kinds of S-expression, atoms and lists.

    S-expressions express your program and manipulate it the same way an interpreter would. This lets you add your own language features without modifying the compiler or interpreter.
  13. Semantics Semantic Analysis makes sure that declarations and statements of

    a program have a correct structure and give the meaning to the tokens.
  14. Type checking We assign the types by validating the string

    with regular expressions, regular expressions create Automata
  15. ENViroment We save Quadrat function in the enviroment (python dictionary)

    Python Dictionary Complexity O(1) get item O(1) set item O(1) delete item We use dictonaries because their operations have O(1) complexity and let you change some predefined functions programing
  16. A programing language for all languages? (2)add intermediate step for

    translation before access to the environment that must be in English, in English because is and Interligua and most the translators use it as intermediate language for optimizing translations You have 2 ways to do this (1) add all instructions translations to the environment
  17. macros The rule or pattern that specifies how a certain

    input should be mapped to a replacement output. Python doesn't have macros but we can create it with eval () Everything in lisp is a macro
  18. Variables and Functions "Let" adds value to the symbol table

    The third argument of the function is the code of the function, which will insert the AST We are inheriting the environment to manage public and private variables.
  19. Control structures We use the "if" of deru passing the

    values to the "if" of python , it is in the eval() Function
  20. WHere are the "for or while"? I know I'm a

    terrible person for leaving `while` commented out, but we need to learn how to make fast recursions.
  21. TCO (Tail call optimization) Benefits: • Avoids unnecessary stack manipulation

    operations. • No stack overflow • Improved Performance
  22. TCO (Tail call optimization) Tail call optimization in Python is

    not natively supported due to Python's recursion limit and the lack of tail call optimization in its interpreter. However, it can be simulated using a loop to replace recursive calls with iterative ones and with externals tools. Programing languages like haskell , Scala, Clojure, Erlang, and Elixir have TCO
  23. Trampolines Trampolines allow to replicate tail call optimization by wrapping

    function calls into a special object using the @trampoline decorator.
  24. ¿HOW to archive real TCO? ctypes Rust TCO cargo package

    didn't work and had no documentation With Ctypes you can connect C and python using the TCO to C