lispy | LISP interpreter in Python | Interpreter library

 by   ridwanmsharif Python Version: Current License: MIT

kandi X-RAY | lispy Summary

kandi X-RAY | lispy Summary

lispy is a Python library typically used in Utilities, Interpreter applications. lispy has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can install using 'pip install lispy' or download it from GitHub, PyPI.

Interpreter for Scheme (A dialect of LISP) in Python. Contains two modules that cover tokenizing, parsing, loading environments and evaluating valid Scheme code input. Closely following Peter Norvig's implementation to get started. Covers primitive keywords and syntactic and procedure calls. A more complete LISP interpreter is what I hope to build on top of this and I intend to closely follow Norvig's thorough interpreter. I have worked independantly to include and cover features inpired by Racket (A dialect of Scheme) we'd been taught this past semester in CS135 at University of Waterloo.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              lispy has a low active ecosystem.
              It has 25 star(s) with 10 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              lispy has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of lispy is current.

            kandi-Quality Quality

              lispy has 0 bugs and 0 code smells.

            kandi-Security Security

              lispy has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              lispy code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              lispy is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              lispy releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              lispy saves you 102 person hours of effort in developing the same functionality from scratch.
              It has 260 lines of code, 16 functions and 4 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed lispy and discovered the below as its top functions. This is intended to give you an instant insight into lispy implemented functionality, and help decide if they suit your requirements.
            • Parse the given code
            • Read from tokens
            • Convert a token into an integer
            • Tokenize code
            • Generate standard construction variables for math
            • Return symbol object
            Get all kandi verified functions for this library.

            lispy Key Features

            No Key Features are available at this moment for lispy.

            lispy Examples and Code Snippets

            lispy,Examples
            Pythondot img1Lines of Code : 63dot img1License : Permissive (MIT)
            copy iconCopy
            Code: (define const "Constant")
            Code: const
            "Constant"
            
            Code: (define var "Variable")
            Code: var
            "Variable"
            Code: (set! var "Variable")
            Code: var
            "Variable"
            
            Code: (* (+ 1 1) (/ (- 5 3) 2))
            2
            
            Code: (define factorial 
                      (lambda (x)
                         
            lispy,Usage
            Pythondot img2Lines of Code : 3dot img2License : Permissive (MIT)
            copy iconCopy
            $ python rlispy/lis.py
            
            Code: ENTER ANY SCHEME CODE HERE (NOTE THE RESTRICTIONS)
            
            Code: quit
              
            lispy,Setup
            Pythondot img3Lines of Code : 2dot img3License : Permissive (MIT)
            copy iconCopy
            pip install rlispy
            
            git clone https://github.com/ridwanmsharif/lispy
              

            Community Discussions

            QUESTION

            Functional style with conditional returns in python
            Asked 2021-Apr-03 at 05:42

            Suppose we have a function with the following structure:

            ...

            ANSWER

            Answered 2021-Apr-03 at 05:42

            A return statement anywhere in a function is not functional.

            In Python, you have no choice.

            The Lisp code

            Source https://stackoverflow.com/questions/66641707

            QUESTION

            Is Clojure less homoiconic than other lisps?
            Asked 2021-Jan-25 at 21:54

            A claim that I recall being repeated in the Clojure for Lisp Programmers videos is that a great weakness of the earlier Lisps, particularly Common Lisp, is that too much is married to the list structure of Lisps, particularly cons cells. You can find one occurrence of this claim just at the 25 minute mark in the linked video, but I'm sure that I can remember hearing it elsewhere in the series. Importantly, at that same point in the video, we see this slide, showing us that Clojure has many other data structures than just the old school Lispy lists: This troubles me. My knowledge of Lisp is quite limited, but I've always been told that a key element of its legendary metaprogrmmability is that everything - yes, everything - is a list and that this is what prevents the sort of errors that we get when trying to metaprogram other languages. Does this suggest that by adding new first-class data structures, Clojure has reduces its homoiconicity, thus making it more difficult to metaprogram than other Lisps, such as Common Lisp?

            ...

            ANSWER

            Answered 2021-Jan-18 at 20:34

            In Clojure, the only one of those extra data structures that is required for some language constructs, besides lists, are vectors, and those are in well-known places such as around sequences of arguments to a function, or in symbol/expression pairs of a let. All of them can be used for data literals, but data literals are less often something you want to involve when writing a Clojure macro, as compared to function calls and macro invocations, which are always in lists.

            I am not aware of anything in Clojure that makes writing macros more difficult than in Common Lisp, and there are a few features there distinct to Clojure that can make it a little bit easier, such as the behavior where Clojure backquoted expressions by default will namespace-qualify symbols, which is often what you want to prevent 'capturing' a name accidentally.

            Source https://stackoverflow.com/questions/65781570

            QUESTION

            Editing norvig's scheme interpreter for python
            Asked 2020-Nov-27 at 02:55

            I'm trying to edit Norvig's lispy.py scheme-to-python interpreter for a racket program in which, in addition to the procedures he includes, I use open-input-string and string-replace.

            It looked like I could just add the corresponding python definitions into his add_globals() function, which I did, as follows.

            ...

            ANSWER

            Answered 2020-Nov-26 at 03:09

            It makes sense that you cannot find variable inputsliceexample, because the variable you defined is named inputlistsliceexample. So your string-replace has worked fine. I'm not sure about your problem with open-input-string, but from the link you posted it looks to me like read takes in a file or a port or something like that, while your open-input-string returns a string.

            Source https://stackoverflow.com/questions/65014622

            QUESTION

            Default identity value of a key function
            Asked 2020-Oct-29 at 15:42

            Often a function takes an optional argument that defaults to the identity function (the function that returns its argument, not id). A typical example is the key argument of sorted.

            In my case the key is a class field:

            ...

            ANSWER

            Answered 2020-Oct-29 at 15:42

            I would define an identity function and use it as a default parameter:

            Source https://stackoverflow.com/questions/64594176

            QUESTION

            Missing argument in syntax-rules Hygienic macro call from Scheme R5RS example
            Asked 2020-Apr-13 at 21:42

            I have one more questions about Hygienic macros in Scheme, consider example from R5RS

            ...

            ANSWER

            Answered 2020-Apr-13 at 21:42

            Yes. It is very non lispy that we have a modifier ... that changes the meaning of element in front. eg. something ... is basically similar to . something except it works with structures like this:

            Source https://stackoverflow.com/questions/61195399

            QUESTION

            What are the rules behind the typical indenting conventions of lisp?
            Asked 2019-Nov-21 at 18:09

            Note to mods: Please note that this question is NOT AT ALL a question of taste. I am asking for specific information regarding the indenting conventions I have encountered in Spacemacs' default indentation rules for elisp.

            Why is this code indented like this by formatters:

            ...

            ANSWER

            Answered 2018-Mar-26 at 20:10

            Because the IF operator of Emacs Lisp allows one then form and multiple else forms. The else forms are indented differently from the then form for readability.

            Source https://stackoverflow.com/questions/49499245

            QUESTION

            How does one make symbols that refer to structure slots in lisp?
            Asked 2019-Aug-17 at 21:12

            I am self learning lisp and thought a nice non-trivial program would be to write a set of standard tree insertion and manipulation routines. I figured it could be done with CONS but wanted to try it with a structure.

            I put together one version that worked:

            ...

            ANSWER

            Answered 2019-Aug-15 at 06:48

            simple version for your inspiration:

            Source https://stackoverflow.com/questions/57487386

            QUESTION

            How to to have expanding canvas fill more then half the screen
            Asked 2019-Jul-23 at 11:07

            I'm starting to work on some GUI programming and decided to use ltk. Ltk stands for "lisp toolkit" and it provides a lispy syntax layer over the basic tcl / tk commands. It's a lot like Tkinter for python in a way.

            I've however found that, when putting two canvasses in one frame and having one of them expand in both directions. That canvas doesn't expand pas halfway point of the screen.

            To show what I mean, I'll provide some pictures. Here's the window just after creation.

            When expanded it looks like this:

            I'm now trying to get rid of the light gray area, but whatever I do, the left canvas doesn't seem to want to enter the right half of the screen.

            I'm running this on linux mint, but that shouldn't matter to much. And I'm using the ltk version released on 2-2-2019. I've tried messing with the current keyword arguments, but I've gotten nothing to work.

            Here's the code that results in these screens.

            ...

            ANSWER

            Answered 2019-Jul-23 at 11:07

            I sort of figured it out. I'm still not completely sure how tk works, but from this other answer I got the information to fix it.

            Tcl/Tk: Frames misbehave when resizing.

            It took a sligth translation, but removing the :expand option for the right panel managed to solve the issue. The new code now looks like this:

            Source https://stackoverflow.com/questions/57161673

            QUESTION

            Can't cons cells be implemented efficiently at the library level in Clojure?
            Asked 2019-May-28 at 07:51

            Clojure has its own collections, and has no need of the traditional lispy cons cells. But I find the concept interesting, and it is used in some teaching materials (e.g., SICP). I have been wondering if there is any reasons that this cons primitive needs to be a primitive. Can't we just implement it (and the traditional functions that operate on it) in a library? I searched, but I found no such library already written.

            ...

            ANSWER

            Answered 2018-Apr-23 at 15:12

            You could implement it yourself. Here is an attempt:

            Source https://stackoverflow.com/questions/49983613

            QUESTION

            Implementing the Prolog Unification algorithm in Python? Backtracking
            Asked 2019-Apr-14 at 10:04

            I'm trying to implement Unification, but having problems.. already got dozen of examples,but all they do is to muddy the water. I get more confused than enlightened :

            http://www.cs.trincoll.edu/~ram/cpsc352/notes/unification.html

            https://www.doc.ic.ac.uk/~sgc/teaching/pre2012/v231/lecture8.html [code below is based on this intro]

            http://www.cs.bham.ac.uk/research/projects/poplog/paradigms_lectures/lecture20.html#representing

            https://norvig.com/unify-bug.pdf

            How can I implement the unification algorithm in a language like Java or C#?

            The art of Prolog one ...and several others. The biggest problem is that I could not figure clear statement of the problem. More mathy or lispy explanations are confusing me even more.

            As a good start it seems a good idea to follow the representation to be list based (like in the lispy cases) i.e. :

            ...

            ANSWER

            Answered 2018-Mar-08 at 23:50

            I will quickly summarize the chapter about Unification Theory by Baader and Snyder from the Handbook of Automated Reasoning:

            Terms are built from constants (starting with a lower case letter) and variables (starting with an upper case letter):

            • a constant without arguments is a term: e.g. car
            • a constant with terms as arguments, a so called function application, is a term. e.g. date(1,10,2000)
            • a variable is a term, e.g. Date (variables never have arguments)

            A substitution is a map assigning terms to variables. In the literature, this is often written as {f(Y)/X, g(X)/Y} or with arrows {X→f(Y), Y→g(X)}. Applying a substitution to a term replaces each variable by the corresponding term in the list. E.g. the substitution above applied to tuple(X,Y) results in the term tuple(f(Y),g(X)).

            Given two terms s and t, a unifier is a substitution that makes s and t equal. E.g. if we apply the substitution {a/X, a/Y} to the term date(X,1,2000), we get date(a,1,2000) and if we apply it to date(Y,1,2000) we also get date(a,1,2000). In other words, the (syntactic) equality date(X,1,2000) = date(Y,1,2000) can be solved by applying the unifier {a/X,a/Y}. Another, simpler unifier would be X/Y. The simplest such unifier is called the most general unifier. For our purposes it's enough to know that we can restrict ourselves to the search of such a most general unifier and that, if it exists, it is unique (up to the names of some variables).

            Mortelli and Montanari (see section 2.2. of the article and the references there) gave a set of rules to compute such a most general unifier, if it exists. The input is a set of term pairs (e.g. { f(X,b) = f(a,Y), X = Y } ) and the output is a most general unifier, if it exists or failure if it does not exist. In the example, the substitution {a/X, b/Y} would make the first pair equal (f(a,b) = f(a,b)), but then the second pair would be different (a = b is not true).

            The algorithm nondeterministically picks one equality from the set and applies one of the following rules to it:

            • Trivial: an equation s = s (or X=X) is already equal and can be safely removed.
            • Decomposition: an equality f(u,v) = f(s,t) is replaced by the equalities u=s and v=t.
            • Symbol Clash: an equality a=b or f(X) = g(X) terminates the process with failure.
            • Orient: an equality of the form t=X where t is not another variable is flipped to X=t such that the variable is on the left side.
            • Occurs check: if the equation is of the form X=t, t is not X itself and if X occurs somewhere within t, we fail. [1]
            • Variable elimination: of we have an equation X=t where X does not occur in t, we can apply the substitution t/X to all other problems.

            When there is no rule left to apply, we end up with a set of equations {X=s, Y=t, ...} that represents the substitution to apply.

            Here are some more examples:

            • {f(a,X) = f(Y,b)} is unifiable: decompose to get {a=Y, X=b} and flip to get {Y=a, X=b}
            • {f(a,X,X) = f(a,a,b)} is not unifiable: decompose to get {a=a,X=a, X=b}, eliminate a=a by triviality, then eliminate the variable X to get {a=b} and fail with symbol clash
            • {f(X,X) = f(Y,g(Y))} is not unifiable: decompose to get {X=Y, X=g(Y)}, eliminate the variable X to get {Y=g(Y)}, fail with occurs check

            Even though the algorithm is non-deterministic (because we need to pick a equality to work on), the order does not matter. Because you can commit to any order, it is never necessary to undo your work and try a different equation instead. This technique is usually called backtracking and is necessary for the proof search in Prolog, but not for unification itself.

            Now you're only left to pick a suitable data-structure for terms and substitutions and implement the algorithms for applying a substitution to a term as well as the rule based unification algorithm.

            [1] If we try to solve X = f(X), we would see that X needs to be of the form f(Y) to apply decomposition. That leads to solving the problem f(Y) = f(f(Y)) and subsequently Y = f(Y). Since the left hand side always has one application of f less than the right hand side, they can not be equal as long we see a term as a finite structure.

            Source https://stackoverflow.com/questions/49101342

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install lispy

            You can install using 'pip install lispy' or download it from GitHub, PyPI.
            You can use lispy like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            Bug reports and pull requests are welcome on GitHub at @ridwanmsharif.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/ridwanmsharif/lispy.git

          • CLI

            gh repo clone ridwanmsharif/lispy

          • sshUrl

            git@github.com:ridwanmsharif/lispy.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Interpreter Libraries

            v8

            by v8

            micropython

            by micropython

            RustPython

            by RustPython

            otto

            by robertkrimen

            sh

            by mvdan

            Try Top Libraries by ridwanmsharif

            mqueue

            by ridwanmsharifGo

            prsa

            by ridwanmsharifPython

            Algorithms

            by ridwanmsharifPython

            raft

            by ridwanmsharifGo

            goworkerpool

            by ridwanmsharifGo