Giter Club home page Giter Club logo

dart-petitparser-examples's Issues

Magic needs explanation

Hello!

I'm looking for some examples with petitparser that will allow me to create own programming language. I am Java developer itself.
So the closest sample I found is the Lisp interpreter in this repo. And all the main magic about evaluation stuff happening here :

This looks like a recursive function that took an object with just two props head and tail and first calls itself with head to create a function and then uses the resulting function and calls it with tail.
But can't get where the function creation actually happened, and how its evaluation was performed. Can be a bit of explanation on this?

Thanks!

Lisp "quote" implementation

(This is more of a discussion item than an issue, but discussions are not enabled on this repo.)

I've been working on my fork (see #5) of the Lisp example, and when implementing splicing I noticed an interesting consequence of the current implementation of quote syntax.

Currently when a ' is encountered the next atom is wrapped with an instance of the Quote class. This makes the quote-handling code quite succinct and clean, but:

As I understand it, many (most? all?) Lisps implement quote syntax by transforming 'foo into the list (quote foo) where quote is a symbol. The evaluator then recognizes this form and handles it specially.

It's important to note that ' parses into a cons list, because in some edge cases this results in behavior that not only diverges, but cannot even be expressed with the class-based parsing of Petit Lisp. A specific example I happened across:

`',@'(1 2)

Emacs, Guile, and SBCL all agree that this expands to (quote 1 2), which cannot be expressed with the Quote class in Petit Lisp.

((quote 1 2) is not the same as '(1 2) โ†’ (quote (1 2)), which is expressable in Petit Lisp as Quote(Cons(1, Cons(2)). The closest you can get to the former would be Cons(Name('quote'), Cons(1, Cons(2))).)

My question is: What was the motivation behind the class-based quote implementation? Was this divergence intentional? Is this divergence a big enough problem to move to a cons-based implementation?

My feeling is that this is unimportant for basically all real-world purposes, but if for instance one were to aim for passing some sort of compatibility test then it could be a problem.

Extracting the Lisp example

I have a need for a Lisp parser and evaluator. I was going to write one myself, but I realized that the example here is already probably better than what I would have come up with on my own.

I could make a package that consumes this one, but I don't want all the extra dependencies.

Am I best off taking the code from here and starting a separate project? Could I call it "petit_lisp"?

Since the code in this repo is MIT-licensed, I believe I am allowed to do so, so I suppose I am mostly asking about how people feel about it, or if there are better alternative approaches.

(Aside: What I actually need is a near-Elisp, so I will need to add lots of library functions e.g. to an ElispEnvironment and also make a few parsing changes. I also want to add a mechanism for interrupting evaluation after some time i.e. to prevent infinite loops. It looks like I can do all or most of this additively, but I'm not positive about that.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.