{"id":466517,"date":"2025-07-08T21:00:25","date_gmt":"2025-07-08T21:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466517"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466517","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0432\u043e\u044e \u043b\u0435\u0433\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e LISP&#8217;\u0430 \u043d\u0430 Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e LISP&#8217;\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0442\u043e \u044f \u0434\u043e\u0432\u0435\u0434\u0443 \u044d\u0442\u043e\u0442 \u043b\u0438\u0441\u043f \u0434\u043e \u0443\u043c\u0430 \u0438 \u043d\u0430\u043f\u0438\u0448\u0443 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e&#8230; \u041d\u043e \u043d\u0435 \u043e\u0431\u0435\u0449\u0430\u044e.<\/p>\n<h2>\u0418\u0441\u0442\u043e\u0440\u0438\u044f LISP&#8217;\u0430 \u0432\u043a\u0440\u0430\u0442\u0446\u0435<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0432\u0432\u0435\u0434\u0443 \u0432\u0430\u0441 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u044e LISP&#8217;\u0430.<\/p>\n<p>\u041e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0414\u0436\u043e\u043d\u043e\u043c \u041c\u0430\u043a\u043a\u0430\u0440\u0442\u0438 \u0432 1958 \u0433\u043e\u0434\u0443 (\u0432\u0440\u043e\u0434\u0435 \u0431\u044b).<\/p>\n<p>\u0418 \u0432 1960-\u043e\u043c \u043e\u043d \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043b\u0438\u0441\u043f\u0443 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#171;\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0438\u0445 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435&#187; (\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f: &#171;Recursive Functions of Symbolic Expressions and Their Computation by Machine&#187;).<\/p>\n<p>\u0418 \u043f\u043e\u0448\u043b\u043e \u043f\u043e\u0435\u0445\u0430\u043b\u043e&#8230; \u0422\u0430\u043c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 LISP \u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043d\u0443 \u0438 \u0432\u0441\u0451 \u0432 \u0442\u0430\u043a\u043e\u043c \u0440\u043e\u0434\u0435.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u0432 1976 \u041e\u041f\u042f\u0422\u042c \u0432 MIT \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0430\u043b\u0435\u043a\u0442 LISP&#8217;\u0430 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#171;Scheme&#187;. \u041d\u0443 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u042f \u043d\u0435 \u0445\u043e\u0447\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043e\u043f\u044f\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0441\u0445\u0435\u043c\u0430&#8230;)<\/h2>\n<p>\u0412\u043e \u043f\u0435\u0440\u0432\u044b\u0445 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0432\u0435\u0434\u044c \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f LISP&#8217;\u0430 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0451 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c LISP. \u0410 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c.<\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f.<\/p>\n<ol>\n<li>\n<p>\u041b\u0435\u043a\u0441\u0435\u0440: \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 (+ 3 2)) \u0432 &#187; ( + 3 2 ) &#171;)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0441\u0435\u0440: \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b \u0432 \u0441\u043f\u0438\u0441\u043e\u043a (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443: [&#8216;+&#8217;, &#8216;3&#8217;, &#8216;2&#8217;])<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440: \u043d\u0443, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 (AST)<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0436\u0435 env \u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u0430 \u0432\u0441\u0435 \u043c\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 (\u044f \u0438\u0445 \u0443\u0431\u0440\u0430\u043b) \u043d\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0451\u043c \u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u043c.<\/p>\n<h2>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0430\u0434\u0438\u0438<\/h2>\n<p>\u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0432\u044b \u043f\u043e\u0439\u043c\u0451\u0442\u0435 \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e.<\/p>\n<p>\u041d\u043e, \u043d\u0430\u0447\u043d\u0451\u043c \u043c\u044b \u043d\u0435 \u0441 \u043b\u0435\u043a\u0441\u0435\u0440\u0430 \u0430 \u0441 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0445\u043e\u0442\u044c \u044d\u0442\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u043a\u0430\u043a \u0430\u043d\u0442\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d.<\/p>\n<p>\u0418\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e. \u0412\u0441\u0435\u0433\u043e 3:<\/p>\n<ol>\n<li>\n<p>Symbol: \u0441\u0438\u043c\u0432\u043e\u043b, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 hello<\/p>\n<\/li>\n<li>\n<p>Real: \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u0437\u0432\u0430\u0442\u044c float, \u043d\u0443 \u043a\u043e\u0440\u043e\u0447\u0435 3.14 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>Number: \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0438\u0444\u0440\u0430. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443: 55<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">Symbol = str #\u0441\u0438\u043c\u0432\u043e\u043b Real = float #\u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 Number = int #\u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u043e<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0432\u0441\u0451. \u0422\u0430\u043a\u0436\u0435 \u0432 \u043b\u0438\u0441\u043f\u0435 \u0435\u0441\u0442\u044c \u0430\u0442\u043e\u043c\u044b. \u042d\u0442\u043e \u043b\u0438\u0431\u043e \u0447\u0438\u0441\u043b\u043e, \u043b\u0438\u0431\u043e \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u043b\u0438\u0431\u043e \u0441\u0438\u043c\u0432\u043e\u043b.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">def atom(val):     try:         return Number(val)     except:         try:             return Real(val)         except:             return Symbol(val)<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<ol>\n<li>\n<p>\u041d\u0435\u0442, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043f\u0440\u043e\u0431\u0443\u0439 \u0432 float.<\/p>\n<ol>\n<li>\n<p>\u0422\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u042d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043b\u0435\u043a\u0441\u0435\u0440\u0443:<\/p>\n<p>\u041e\u043d \u0434\u0432\u0443\u0445\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0439.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">def lexer(string):     return string.replace('(', ' ( ').replace(')', ' ) ').replace('\\n', '\\n').split()<\/code><\/pre>\n<p>\u041d\u0435 \u0445\u043e\u0447\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434. \u041e\u043d \u043f\u043e\u043d\u044f\u0442\u0435\u043d.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043f\u0430\u0440\u0441\u0435\u0440\u0443.<\/p>\n<p>\u0412\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def parse(tokens):     if len(tokens) == 0:         raise SyntaxError('unexpected EOF while reading')     token = tokens.pop(0)     if token == '(':         l = []         while tokens[0] != ')':             l.append(parse(tokens))         tokens.pop(0)         return l     elif token == ')':         raise SyntaxError('unexpected )')     else:         return atom(token)<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0441\u043d\u044f\u044e \u043a\u043e\u0434:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043d\u0435\u0442 &#8212; \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e &#171;)&#187; &#8212; \u0442\u043e\u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 &#171;(&#187; &#8212; \u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u044d\u0442\u043e S-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0418\u043d\u0430\u0447\u0435 &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0430\u0442\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h2>\n<p>\u042f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u0410 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">class Env:     def __init__(self):         self.env = {}      def add(self, name, value):         self.env[name] = value      def get(self, name):         return self.env[name] if name in self.env else 0<\/code><\/pre>\n<p>add &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<p>get &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043a\u043b\u0430\u0441\u0441? \u0414\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0430 \u043d\u0435 \u0434\u043b\u044f \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b.<\/p>\n<pre><code class=\"python\">class Proc:     def __init__(self, lambda_, args):         self.args, self.lambda_ = args, lambda_      def __repr__(self):         return f'#&lt;lambda {self.args}&gt;'<\/code><\/pre>\n<p>\u0412\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u043f\u043e\u0447\u0435\u043c\u0443 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043b\u0430\u0441\u0441? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u043b\u043e\u0432\u0430\u0440\u0438 (\u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u0430).<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u043b\u044f\u043c\u0431\u0434\u0430).<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (builtins \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e).<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c &#8212; \u0441\u0430\u043c\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u043e\u0442 \u043e\u043d\u0438:<\/p>\n<pre><code class=\"python\">old_eval = eval  def rem(lst, el):     new_lst = []     for i in lst:         if i != el:             new_lst.append(i)     return new_lst  genv = Env() genv.env = {     'princ': Proc(lambda *x: print(*x), 'builtins'),     'list': Proc(lambda *x: [*x], 'builtins'),     'nth': Proc(lambda lst, ind: lst[ind], ['lst', 'ind']),     '+': Proc(lambda first, sec: first + sec, ['first', 'sec']),     '-': Proc(lambda first, sec: first - sec, ['first', 'sec']),     '*': Proc(lambda first, sec: first * sec, ['first', 'sec']),     '\/': Proc(lambda first, sec: first \/ sec, ['first', 'sec']),     '&gt;': Proc(lambda first, sec: first &gt; sec, ['first', 'sec']),     '&lt;': Proc(lambda first, sec: first &lt; sec, ['first', 'sec']),     '=': Proc(lambda first, sec: first == sec, ['first', 'sec']),     '\/=': Proc(lambda first, sec: first != sec, ['first', 'sec']),     'py': Proc(lambda exp: old_eval(exp, globals() | genv.env), ['exp']),     'getk': Proc(lambda dct, name: dct[name], ['dct', 'name']),     'append': Proc(lambda lst, el: lst + [el], ['lst', 'el']),     'remove': Proc(lambda lst, el: rem(lst, el), ['lst', 'el']),     'car': Proc(lambda lst: lst[0], ['lst']),     'cdr': Proc(lambda lst: rem(lst, lst[0]), ['lst']),     'cons': Proc(lambda el, lst: [el] + lst, ['el', 'lst']) }<\/code><\/pre>\n<p>\u0417\u0430\u0447\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f rem? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 lst.remove \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u0430 \u0432 \u043b\u0438\u0441\u043f\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a lst \u0433\u0434\u0435 \u043d\u0435\u0442\u0443 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f old_eval? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u043d\u0443\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f eval. \u0410 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0430\u0439\u0442\u043e\u043d\u0430.<\/p>\n<p>\/= \u044d\u0442\u043e != \u0435\u0441\u043b\u0438 \u0447\u0442\u043e.<\/p>\n<p>genv &#8212; \u044d\u0442\u043e \u0441\u0430\u043c\u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0439 \u0442\u0443\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043d\u0430 \u044d\u0442\u043e\u043c.<\/p>\n<h2>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441 \u043d\u0430\u0447\u0430\u043b\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412\u043e\u0442 \u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">def<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u043f\u0440\u0438\u043c\u0435\u0440: (def x 5))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">quote<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u0438\u0434\u0451\u0442 \u043f\u043e\u0441\u043b\u0435 quote. (\u043f\u0440\u0438\u043c\u0435\u0440: (quote hello, world!))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">if<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u0440: (if (= 3 3) (1) (2)) \u0422\u043e \u0435\u0441\u0442\u044c: (if  (\u0443\u0441\u043b\u043e\u0432\u0438\u0435) (\u0435\u0441\u043b\u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e) (\u0438\u043d\u0430\u0447\u0435))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">lambda<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430. \u041f\u0440\u0438\u043c\u0435\u0440: (lambda x (* x x))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">begin<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u041f\u0440\u0438\u043c\u0435\u0440: (begin (def x 5) (+ x 5))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">dict<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0435\u043b\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u041f\u0440\u0438\u043c\u0435\u0440: (dict (a 1) (b 2))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">t<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0441\u0442\u0438\u043d\u0430 (true \u0438\u043b\u0438 truth)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">nil<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u043e\u0436\u044c \u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">;<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440: ;hello world<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">(proc *args)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u041f\u0440\u0438\u043c\u0435\u0440: (square 5). \u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f: \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0451 \u043b\u0435\u0433\u043a\u043e. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">def eval(ast):     try:         name = ast[0] if type(ast) != str else ast     except:         return ast     if name == 'if':         return eval(ast[2] if eval(ast[1]) else eval(ast[3]))     elif name == 'def':         name = ast[1]         val = eval(ast[2])         genv.add(name, val)     elif name == 'lambda':         args = ast[1]         if type(args) != list:             args = [args]         return Proc(lambda *args: eval(ast[2]), args)     elif name == 'quote':         res = ''         for i in ast[1:]:             res += to_lisp(i) + ' '         return res[0:-1]     elif name == 'begin':         res = 'NIL'         for i in ast[1:]:             res = eval(i)         return res     elif name == 'dict':         res = {}         for i in ast[1:]:             name = i[0]             val = eval(i[1])             res[name] = val         return res     elif name == 'nil':         return False     elif name == 't':         return True     elif name == ';':         pass     else:         fn = genv.get(name)         if type(fn) != Proc:             return fn         args = [eval(i) for i in ast[1:]]         if fn.args == 'builtins':             return fn.lambda_(*args)         cur = 0         for i in fn.args:             eval(parse(lexer(f'(def {i} {args[cur]})')))             cur += 1         return fn.lambda_(*args)<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u0434, \u043d\u043e \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0421\u0438\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0432\u0435\u0440\u0445\u044a\u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; eval(parse(lexer('(def square (lambda x (* x x)))'))) None &gt;&gt;&gt; eval(parse(lexer('(square 5)'))) 25 &gt;&gt;&gt; <\/code><\/pre>\n<p>\u0427\u0435\u0433\u043e \u0442\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u044b? \u041d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 LISP. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u0412\u043e\u0442 \u0435\u0451 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def to_lisp(val):     if isinstance(val, list):         cur = 0         for i in val:             val[cur] = to_lisp(i)             cur += 1         return '(' + ' '.join(val) + ')'     elif isinstance(val, bool) or val == None:         if val == True:             return 'T'         return 'NIL'     elif isinstance(val, dict):         cur = 0         res = '('         for i in val.values():             val[list(val.keys())[cur]] = to_lisp(i)             res += list(val.keys())[cur] + ':' + to_lisp(i) + ' '             cur += 1         res = res[0:-1]         return res + ')'     return str(val)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e t \u0438\u043b\u0438 nil \u0442\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c&#8230; \u041d\u0443 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; to_lisp(eval(parse(lexer('(list 1 2 3)')))) (1 2 3) &gt;&gt;&gt; (= 3 2) NIL &gt;&gt;&gt; <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<pre><code class=\"python\">def repl():     print('MyLISP 1.0')     while True:         try:             print(eval(parse(lexer(input('&gt; ')))))         except:             print('Error!')<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 REPL \u043d\u043e \u044d\u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0443, \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; repl() MyLISP 1.0 &gt; (list 1 2 3) (1 2 3) &gt; (dict (a 1) (b 2)) (a:1 b:2) &gt; (def fac (lambda n (if (= n 1) 1 (* n (fac (- n 1)))))) NIL &gt; (fac 5) 120 &gt; <\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0441\u0432\u043e\u0439 LISP \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e. \u0412\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 LISP \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0443\u0447\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0435 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u041d\u043e \u0432\u043e\u043e\u0431\u0449\u0435, \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f.<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0432\u0441\u0435\u043c \u043f\u043e\u043a\u0430!<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u041f\u0438\u0442\u0435\u0440\u0443 \u041d\u043e\u0440\u0432\u0438\u0433\u0443 \u0437\u0430 \u0438\u0434\u0435\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043b\u0435\u043a\u0441\u0435\u0440\u0430 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u0432\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430:<\/p>\n<p><a href=\"https:\/\/norvig.com\/lispy.html\" rel=\"noopener noreferrer nofollow\">https:\/\/norvig.com\/lispy.html<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/926106\/\"> https:\/\/habr.com\/ru\/articles\/926106\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e LISP&#8217;\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0442\u043e \u044f \u0434\u043e\u0432\u0435\u0434\u0443 \u044d\u0442\u043e\u0442 \u043b\u0438\u0441\u043f \u0434\u043e \u0443\u043c\u0430 \u0438 \u043d\u0430\u043f\u0438\u0448\u0443 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e&#8230; \u041d\u043e \u043d\u0435 \u043e\u0431\u0435\u0449\u0430\u044e.<\/p>\n<h2>\u0418\u0441\u0442\u043e\u0440\u0438\u044f LISP&#8217;\u0430 \u0432\u043a\u0440\u0430\u0442\u0446\u0435<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0432\u0432\u0435\u0434\u0443 \u0432\u0430\u0441 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u044e LISP&#8217;\u0430.<\/p>\n<p>\u041e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0414\u0436\u043e\u043d\u043e\u043c \u041c\u0430\u043a\u043a\u0430\u0440\u0442\u0438 \u0432 1958 \u0433\u043e\u0434\u0443 (\u0432\u0440\u043e\u0434\u0435 \u0431\u044b).<\/p>\n<p>\u0418 \u0432 1960-\u043e\u043c \u043e\u043d \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043b\u0438\u0441\u043f\u0443 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#171;\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0438\u0445 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435&#187; (\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f: &#171;Recursive Functions of Symbolic Expressions and Their Computation by Machine&#187;).<\/p>\n<p>\u0418 \u043f\u043e\u0448\u043b\u043e \u043f\u043e\u0435\u0445\u0430\u043b\u043e&#8230; \u0422\u0430\u043c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 LISP \u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043d\u0443 \u0438 \u0432\u0441\u0451 \u0432 \u0442\u0430\u043a\u043e\u043c \u0440\u043e\u0434\u0435.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u0432 1976 \u041e\u041f\u042f\u0422\u042c \u0432 MIT \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0430\u043b\u0435\u043a\u0442 LISP&#8217;\u0430 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#171;Scheme&#187;. \u041d\u0443 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u042f \u043d\u0435 \u0445\u043e\u0447\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043e\u043f\u044f\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0441\u0445\u0435\u043c\u0430&#8230;)<\/h2>\n<p>\u0412\u043e \u043f\u0435\u0440\u0432\u044b\u0445 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0432\u0435\u0434\u044c \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f LISP&#8217;\u0430 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0451 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c LISP. \u0410 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c.<\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f.<\/p>\n<ol>\n<li>\n<p>\u041b\u0435\u043a\u0441\u0435\u0440: \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 (+ 3 2)) \u0432 &#187; ( + 3 2 ) &#171;)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0441\u0435\u0440: \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b \u0432 \u0441\u043f\u0438\u0441\u043e\u043a (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443: [&#8216;+&#8217;, &#8216;3&#8217;, &#8216;2&#8217;])<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440: \u043d\u0443, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 (AST)<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0436\u0435 env \u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u0430 \u0432\u0441\u0435 \u043c\u043e\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 (\u044f \u0438\u0445 \u0443\u0431\u0440\u0430\u043b) \u043d\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0451\u043c \u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u043c.<\/p>\n<h2>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0430\u0434\u0438\u0438<\/h2>\n<p>\u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0432\u044b \u043f\u043e\u0439\u043c\u0451\u0442\u0435 \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e.<\/p>\n<p>\u041d\u043e, \u043d\u0430\u0447\u043d\u0451\u043c \u043c\u044b \u043d\u0435 \u0441 \u043b\u0435\u043a\u0441\u0435\u0440\u0430 \u0430 \u0441 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0445\u043e\u0442\u044c \u044d\u0442\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u043a\u0430\u043a \u0430\u043d\u0442\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d.<\/p>\n<p>\u0418\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e. \u0412\u0441\u0435\u0433\u043e 3:<\/p>\n<ol>\n<li>\n<p>Symbol: \u0441\u0438\u043c\u0432\u043e\u043b, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 hello<\/p>\n<\/li>\n<li>\n<p>Real: \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u0437\u0432\u0430\u0442\u044c float, \u043d\u0443 \u043a\u043e\u0440\u043e\u0447\u0435 3.14 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443<\/p>\n<\/li>\n<li>\n<p>Number: \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0438\u0444\u0440\u0430. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443: 55<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">Symbol = str #\u0441\u0438\u043c\u0432\u043e\u043b Real = float #\u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 Number = int #\u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0441\u043b\u043e<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0432\u0441\u0451. \u0422\u0430\u043a\u0436\u0435 \u0432 \u043b\u0438\u0441\u043f\u0435 \u0435\u0441\u0442\u044c \u0430\u0442\u043e\u043c\u044b. \u042d\u0442\u043e \u043b\u0438\u0431\u043e \u0447\u0438\u0441\u043b\u043e, \u043b\u0438\u0431\u043e \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u043b\u0438\u0431\u043e \u0441\u0438\u043c\u0432\u043e\u043b.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">def atom(val):     try:         return Number(val)     except:         try:             return Real(val)         except:             return Symbol(val)<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<ol>\n<li>\n<p>\u041d\u0435\u0442, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043f\u0440\u043e\u0431\u0443\u0439 \u0432 float.<\/p>\n<ol>\n<li>\n<p>\u0422\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u042d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043b\u0435\u043a\u0441\u0435\u0440\u0443:<\/p>\n<p>\u041e\u043d \u0434\u0432\u0443\u0445\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0439.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">def lexer(string):     return string.replace('(', ' ( ').replace(')', ' ) ').replace('\\n', '\\n').split()<\/code><\/pre>\n<p>\u041d\u0435 \u0445\u043e\u0447\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434. \u041e\u043d \u043f\u043e\u043d\u044f\u0442\u0435\u043d.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043f\u0430\u0440\u0441\u0435\u0440\u0443.<\/p>\n<p>\u0412\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def parse(tokens):     if len(tokens) == 0:         raise SyntaxError('unexpected EOF while reading')     token = tokens.pop(0)     if token == '(':         l = []         while tokens[0] != ')':             l.append(parse(tokens))         tokens.pop(0)         return l     elif token == ')':         raise SyntaxError('unexpected )')     else:         return atom(token)<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0441\u043d\u044f\u044e \u043a\u043e\u0434:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043d\u0435\u0442 &#8212; \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e &#171;)&#187; &#8212; \u0442\u043e\u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 &#171;(&#187; &#8212; \u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u044d\u0442\u043e S-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0418\u043d\u0430\u0447\u0435 &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0430\u0442\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h2>\n<p>\u042f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u0410 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">class Env:     def __init__(self):         self.env = {}      def add(self, name, value):         self.env[name] = value      def get(self, name):         return self.env[name] if name in self.env else 0<\/code><\/pre>\n<p>add &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<p>get &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043a\u043b\u0430\u0441\u0441? \u0414\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0430 \u043d\u0435 \u0434\u043b\u044f \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b.<\/p>\n<pre><code class=\"python\">class Proc:     def __init__(self, lambda_, args):         self.args, self.lambda_ = args, lambda_      def __repr__(self):         return f'#&lt;lambda {self.args}&gt;'<\/code><\/pre>\n<p>\u0412\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u043f\u043e\u0447\u0435\u043c\u0443 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043b\u0430\u0441\u0441? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u043b\u043e\u0432\u0430\u0440\u0438 (\u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u0430).<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u043b\u044f\u043c\u0431\u0434\u0430).<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (builtins \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e).<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c &#8212; \u0441\u0430\u043c\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u043e\u0442 \u043e\u043d\u0438:<\/p>\n<pre><code class=\"python\">old_eval = eval  def rem(lst, el):     new_lst = []     for i in lst:         if i != el:             new_lst.append(i)     return new_lst  genv = Env() genv.env = {     'princ': Proc(lambda *x: print(*x), 'builtins'),     'list': Proc(lambda *x: [*x], 'builtins'),     'nth': Proc(lambda lst, ind: lst[ind], ['lst', 'ind']),     '+': Proc(lambda first, sec: first + sec, ['first', 'sec']),     '-': Proc(lambda first, sec: first - sec, ['first', 'sec']),     '*': Proc(lambda first, sec: first * sec, ['first', 'sec']),     '\/': Proc(lambda first, sec: first \/ sec, ['first', 'sec']),     '&gt;': Proc(lambda first, sec: first &gt; sec, ['first', 'sec']),     '&lt;': Proc(lambda first, sec: first &lt; sec, ['first', 'sec']),     '=': Proc(lambda first, sec: first == sec, ['first', 'sec']),     '\/=': Proc(lambda first, sec: first != sec, ['first', 'sec']),     'py': Proc(lambda exp: old_eval(exp, globals() | genv.env), ['exp']),     'getk': Proc(lambda dct, name: dct[name], ['dct', 'name']),     'append': Proc(lambda lst, el: lst + [el], ['lst', 'el']),     'remove': Proc(lambda lst, el: rem(lst, el), ['lst', 'el']),     'car': Proc(lambda lst: lst[0], ['lst']),     'cdr': Proc(lambda lst: rem(lst, lst[0]), ['lst']),     'cons': Proc(lambda el, lst: [el] + lst, ['el', 'lst']) }<\/code><\/pre>\n<p>\u0417\u0430\u0447\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f rem? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 lst.remove \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u0430 \u0432 \u043b\u0438\u0441\u043f\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a lst \u0433\u0434\u0435 \u043d\u0435\u0442\u0443 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f old_eval? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u043d\u0443\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f eval. \u0410 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0430\u0439\u0442\u043e\u043d\u0430.<\/p>\n<p>\/= \u044d\u0442\u043e != \u0435\u0441\u043b\u0438 \u0447\u0442\u043e.<\/p>\n<p>genv &#8212; \u044d\u0442\u043e \u0441\u0430\u043c\u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0439 \u0442\u0443\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043d\u0430 \u044d\u0442\u043e\u043c.<\/p>\n<h2>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441 \u043d\u0430\u0447\u0430\u043b\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412\u043e\u0442 \u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">def<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u043f\u0440\u0438\u043c\u0435\u0440: (def x 5))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">quote<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u0438\u0434\u0451\u0442 \u043f\u043e\u0441\u043b\u0435 quote. (\u043f\u0440\u0438\u043c\u0435\u0440: (quote hello, world!))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">if<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u0440: (if (= 3 3) (1) (2)) \u0422\u043e \u0435\u0441\u0442\u044c: (if  (\u0443\u0441\u043b\u043e\u0432\u0438\u0435) (\u0435\u0441\u043b\u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u043e) (\u0438\u043d\u0430\u0447\u0435))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">lambda<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430. \u041f\u0440\u0438\u043c\u0435\u0440: (lambda x (* x x))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">begin<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u041f\u0440\u0438\u043c\u0435\u0440: (begin (def x 5) (+ x 5))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">dict<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0435\u043b\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c. \u041f\u0440\u0438\u043c\u0435\u0440: (dict (a 1) (b 2))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">t<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0441\u0442\u0438\u043d\u0430 (true \u0438\u043b\u0438 truth)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">nil<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u043e\u0436\u044c \u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">;<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440: ;hello world<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">(proc *args)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u041f\u0440\u0438\u043c\u0435\u0440: (square 5). \u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f: \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0451 \u043b\u0435\u0433\u043a\u043e. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">def eval(ast):     try:         name = ast[0] if type(ast) != str else ast     except:         return ast     if name == 'if':         return eval(ast[2] if eval(ast[1]) else eval(ast[3]))     elif name == 'def':         name = ast[1]         val = eval(ast[2])         genv.add(name, val)     elif name == 'lambda':         args = ast[1]         if type(args) != list:             args = [args]         return Proc(lambda *args: eval(ast[2]), args)     elif name == 'quote':         res = ''         for i in ast[1:]:             res += to_lisp(i) + ' '         return res[0:-1]     elif name == 'begin':         res = 'NIL'         for i in ast[1:]:             res = eval(i)         return res     elif name == 'dict':         res = {}         for i in ast[1:]:             name = i[0]             val = eval(i[1])             res[name] = val         return res     elif name == 'nil':         return False     elif name == 't':         return True     elif name == ';':         pass     else:         fn = genv.get(name)         if type(fn) != Proc:             return fn         args = [eval(i) for i in ast[1:]]         if fn.args == 'builtins':             return fn.lambda_(*args)         cur = 0         for i in fn.args:             eval(parse(lexer(f'(def {i} {args[cur]})')))             cur += 1         return fn.lambda_(*args)<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u0434, \u043d\u043e \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0421\u0438\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0432\u0435\u0440\u0445\u044a\u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; eval(parse(lexer('(def square (lambda x (* x x)))'))) None &gt;&gt;&gt; eval(parse(lexer('(square 5)'))) 25 &gt;&gt;&gt; <\/code><\/pre>\n<p>\u0427\u0435\u0433\u043e \u0442\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u044b? \u041d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 LISP. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u0412\u043e\u0442 \u0435\u0451 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">def to_lisp(val):     if isinstance(val, list):         cur = 0         for i in val:             val[cur] = to_lisp(i)             cur += 1         return '(' + ' '.join(val) + ')'     elif isinstance(val, bool) or val == None:         if val == True:             return 'T'         return 'NIL'     elif isinstance(val, dict):         cur = 0         res = '('         for i in val.values():             val[list(val.keys())[cur]] = to_lisp(i)             res += list(val.keys())[cur] + ':' + to_lisp(i) + ' '             cur += 1         res = res[0:-1]         return res + ')'     return str(val)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e t \u0438\u043b\u0438 nil \u0442\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c&#8230; \u041d\u0443 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; to_lisp(eval(parse(lexer('(list 1 2 3)')))) (1 2 3) &gt;&gt;&gt; (= 3 2) NIL &gt;&gt;&gt; <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<pre><code class=\"python\">def repl():     print('MyLISP 1.0')     while True:         try:             print(eval(parse(lexer(input('&gt; ')))))         except:             print('Error!')<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 REPL \u043d\u043e \u044d\u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0443, \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b:<\/p>\n<pre><code class=\"python\">#\u0433\u0434\u0435 \u0442\u043e \u0432 REPL &gt;&gt;&gt; repl() MyLISP 1.0 &gt; (list 1 2 3) (1 2 3) &gt; (dict (a 1) (b 2)) (a:1 b:2) &gt; (def fac (lambda n (if (= n 1) 1 (* n (fac (- n 1)))))) NIL &gt; (fac 5) 120 &gt; <\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0441\u0432\u043e\u0439 LISP \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e. \u0412\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 LISP \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0443\u0447\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0435 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u041d\u043e \u0432\u043e\u043e\u0431\u0449\u0435, \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f.<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0432\u0441\u0435\u043c \u043f\u043e\u043a\u0430!<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u041f\u0438\u0442\u0435\u0440\u0443 \u041d\u043e\u0440\u0432\u0438\u0433\u0443 \u0437\u0430 \u0438\u0434\u0435\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043b\u0435\u043a\u0441\u0435\u0440\u0430 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u0432\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430:<\/p>\n<p><a href=\"https:\/\/norvig.com\/lispy.html\" rel=\"noopener noreferrer nofollow\">https:\/\/norvig.com\/lispy.html<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/926106\/\"> https:\/\/habr.com\/ru\/articles\/926106\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466517","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466517"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466517\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}