<jupyter_start><jupyter_text>LispLikeEval.ipynb* Author: <NAME>* Date: 2020-10-19* Repository: https://github.com/genkuroki/LispLikeEval.jl**Installation**```pkg> add https://github.com/genkuroki/LispLikeEval.jl``` Table of Contents1&nbsp;&nbsp;Lisp-like functions2&nbsp;&nbsp;@leval examples2.1&nbsp;&nbsp;lambda expression of addition2.2&nbsp;&nbsp;factorial2.3&nbsp;&nbsp;more Lisp-like example3&nbsp;&nbsp;Documents<jupyter_code>if isfile("Project.toml")
    using Pkg
    Pkg.activate(".")
    using Revise
end
using LispLikeEval
using MetaUtils<jupyter_output><empty_output><jupyter_text>Lisp-like functions<jupyter_code>@lexpr2expr lambda((x, y), f(x, y))(a, b)
@lexpr2expr lambda((x, y), f(x, y))
@lexpr2expr cond((a, A), (b, B), (c, C))
@show null(nil)
@show null(1)
;
@show eq(1, 1)
@show eq(1, 2)
@show eq(nil, nil)
@show eq(nil, ())
@show eq((), nil)
;
@show a = cons(1, nil)
@show b = cons(2, a)
@show c = cons(3, b)
@show d = cons(4, c)
;
@show a = cons(1, 0)
@show b = cons(2, a)
@show c = cons(3, b)
@show d = cons(4, c)
;
@show car((1,))
@show car((1, 2))
@show car((1, 2, 3))
@show car((1, 2, 3, 4))
@show car(((1, 2), 3, 4))
;
@show car(1)
@show car((1=>2,))
@show car((1, 2=>3))
@show car((1, 2, 3=>4))
;
@show cdr(1)
@show cdr((1,))
@show cdr((1, 2))
@show cdr((1, 2, 3))
@show cdr((1, 2, 3, 4))
@show cdr(((1, 2), 3, 4))
;
@show cdr((1=>2,))
@show cdr((1, 2=>3))
@show cdr((1, 2, 3=>4))
@show cdr((1, 2, 3, 4=>5))
;
@show list()
@show list(1)
@show list(1, 2)
@show list(1, 2, 3)
@show list(1, 2, 3, 4)
;<jupyter_output>list() = nil
list(1) = (1,)
list(1, 2) = (1, 2)
list(1, 2, 3) = (1, 2, 3)
list(1, 2, 3, 4) = (1, 2, 3, 4)<jupyter_text>@leval examples  lambda expression of addition<jupyter_code>lexpr = :(lambda((x, y), x+y)(1, 2))
show(lexpr); println("\n")
show_texpr(lexpr); println("\n")

println("|\nV\n")

expr = lexpr2expr(lexpr)
show(expr); println("\n")
show_texpr(expr); println("\n")

@leval lambda((x, y), x+y)(1, 2)<jupyter_output>:((lambda((x, y), x + y))(1, 2))

(:call, 
    (:call, :lambda, 
        (:tuple, :x, :y), 
        (:call, :+, :x, :y)), 1, 2)

|
V

:(let
      x = 1
      y = 2
      x + y
  end)

(:let, 
    (:block,), 
    (:block, 
        (:(=), :x, 1), 
        (:(=), :y, 2), 
        (:call, :+, :x, :y)))<jupyter_text>factorial<jupyter_code>lexpr = :(lambda((f, x), f(x))(
        lambda(x, cond((iszero(x), 1), (true, x*f(x-1)))),
        10))
show(lexpr); println("\n")
show_texpr(lexpr); println("\n")

println("|\nV\n")

expr = lexpr2expr(lexpr)
show(expr); println("\n")
show_texpr(expr); println("\n")

@leval lambda((f, x), f(x))(
    lambda(x, cond((iszero(x), 1), (true, x*f(x-1)))),
    10)<jupyter_output>:((lambda((f, x), f(x)))(lambda(x, cond((iszero(x), 1), (true, x * f(x - 1)))), 10))

(:call, 
    (:call, :lambda, 
        (:tuple, :f, :x), 
        (:call, :f, :x)), 
    (:call, :lambda, :x, 
        (:call, :cond, 
            (:tuple, 
                (:call, :iszero, :x), 1), 
            (:tuple, true, 
                (:call, :*, :x, 
                    (:call, :f, 
                        (:call, :-, :x, 1)))))), 10)

|
V

:(let
      f = (x->if iszero(x)
                  1
              elseif true
                  x * f(x - 1)
              end)
      x = 10
      f(x)
  end)

(:let, 
    (:block,), 
    (:block, 
        (:(=), :f, 
            (:->, :x, 
                (:if, 
                    (:call, :iszero, :x), 
                    (:block, 1), 
                    (:elseif, 
                        (:block, true), 
                        (:block, 
                            (:call, :*, :x, 
                                (:call, :f, 
                       [...]<jupyter_text>more Lisp-like example https://nbviewer.jupyter.org/gist/genkuroki/b60908cca4f4978b8adcaa7955e7b5b6**example 4**```lisp((lambda (assoc k v) (assoc k v))    '(lambda (k v) (cond         ((eq v '()) nil)         ((eq (car (car v)) k) (cdr (car v)))         ('t (assoc k (cdr v)))))    'Orange    '((Apple . 120) (Orange . 210) (Lemmon . 180)))=> 210```<jupyter_code>@lexpr2expr lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Orange,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
@leval lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Apple,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
@leval lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Orange,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
@leval lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Lemmon,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
@leval lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Melon,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
@show_texpr lambda((assoc, k, v), assoc(k, v))(
    lambda((k, v), cond(
            (eq(v, nil), nil),
            (eq(car(car(v)), k), cdr(car(v))), 
            (true, assoc(k, cdr(v))))),
    :Orange,
    ((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,)))
:(((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,))) |> show_texpr
texpr_exmaple4(x) = (:call, 
    (:lambda, (:tuple, :assoc, :k, :v), (:call, :assoc, :k, :v)), 
    (:lambda, (:tuple, :k, :v), (:cond, 
            (:tuple, (:eq, :v, :nil), :nil), 
            (:tuple, (:eq, (:car, (:car, :v)), :k), (:cdr, (:car, :v))), 
            (:tuple, true, (:call, :assoc, :k, (:cdr, :v))))), 
    (:quote, x), 
    :(((:Apple=>120,), (:Orange=>210,), (:Lemmon=>180,))))
texpr_exmaple4(:Apple) |> texpr2expr |> leval
texpr_exmaple4(:Orange) |> texpr2expr |> leval
texpr_exmaple4(:Lemmon) |> texpr2expr |> leval
texpr_exmaple4(:Melon) |> texpr2expr |> leval<jupyter_output><empty_output><jupyter_text>Documents<jupyter_code>@doc lambda
@doc cond
@doc lexpr2expr
@doc @lexpr2expr
@doc leval
@doc @leval
@doc Nil
@doc nil
@doc null
@doc eq
@doc cons
@doc car
@doc cdr
@doc caar
@doc cadr
@doc cdar
@doc cddr
@doc list<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.252787536276157, 'fraction_numerical': 0.04078203757446158, 'mean_word_length': 2.771889400921659, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 67, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '646299', 'license': 'MIT', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2779, 'n_words': 626, 'path': 'LispLikeEval.ipynb', 'repo_name': 'genkuroki/LambdaExpressions', 'size': '6551'}