hrs / blueprint Goto Github PK
View Code? Open in Web Editor NEWA teeny tiny Scheme implemented in Ruby.
License: GNU General Public License v3.0
A teeny tiny Scheme implemented in Ruby.
License: GNU General Public License v3.0
It'd be slick if we could perform a destructuring-bind
when binding variables. Something like:
(destructuring-bind (a (b c) d) '(1 (2 3) 4)
(list a b c d)) # => '(1 2 3 4)
I think §18 of On Lisp has some good stuff on destructuring. We could probably implement this as a macro in the standard library.
Right now, if we try to enter a multi-line expression on the REPL, it'll throw an error and exit. Instead, we should catch those errors (where appropriate) and let the user keep typing on the next line.
We could also try to determine if an expression is balanced and use that information instead. What do other lisps do?
We've already got map
(since I wanted it for let
), but it'd be nice to complete the trifecta.
Might want to reimplement map
in terms of reduce
while I'm at it.
This'll clean up a lot of nonsense in the code (in particular Repl#format
).
Pros:
Cons:
load
phase, too, since we want to be able to expand macros in other files.Macro
objects from the expander to the evaluator, which means the evaluator won't be any simpler.The terms that Blueprint calls macros are expanded at runtime (rather than in a separate macro-expansion phase). It's not exactly wrong to call them macros, but the more precise term would be "fexprs," and we should refer to them as such in the documentation.
On the topic of fexprs, Kent Pitman wrote Special Forms in Lisp in 1980 recommending against their use because they aren't amenable to static analysis. Blueprint performs exactly no static analysis, and doesn't aspire to, so this isn't a big problem for us. It's something to consider for future languages, though!
They're totally broken right now. Our parser tests need to be a lot more extensive.
Probably pending replacing the parser.
Right now the standard library is basically a collection of raw ASTs, but there's nothing conceptually stopping us from reimplementing it in Blueprint itself. This will require:
let
, etc (as described in #9)This might involve unification of some kind? We'll see!
It is in all the other Lisps, so we might as well.
Norvig has a nice example in Lispy2. SICP also covers it pretty well in §5.
Syntax should probably be something like:
(exit 0)
(exit 1)
We might also want aliases, like:
(exit 'success)
As least negative integers and floats. Rationals would be neat, too!
We've got eval
and apply
now, so we've got almost all we need. We might need support for exceptions.
To avoid accidental variable capture in macros.
We've got function literals in the form of lambdas, and macros are essentially a first-class object in Blueprint anyway, so maybe we should add a syntax to create anonymous macros?
Through a defmacro
special form, or something similar. I'd like to match the syntax up with the Scheme-style define I'm already using, so we'll want something like:
(defmacro (if condition consequent alternative)
`(cond (,condition ,consequent)
(else ,alternative)))
If we're still using chunkier syntax (macro-quote
, macro-escape
, macro-splice
, or whatever) instead of backquotes and commas, then that's just fine, too.
We need forms that serve the purpose of backquote, comma, and ,@
in Common Lisp.
We'll eventually want to add the fancy syntax for them in the parser (or as reader macros, if I ever figure out how those work...) but in the meantime these'll do. Anything beats manually cobbling together macros with list
and quote
.
Standard Scheme uses a dot notation to define functions that take a varying number of arguments:
(define (my-function (a b . the-rest)
...)
We'll need to tell the parser to accept dots and modify lambda
and define
to handle this.
It's be cool if we could write something like:
(map first '((1 2) (3 4)))
Right now we can't, since first
is a special form. We have to do something like this instead:
(map (lambda (x) (first x)) '((1 2) (3 4)))
Which is kinda lame.
Might be helpful when dealing with #14.
Just a simple macro for the standard library. Might be nice, though.
We'll want to be able to write to other streams, too, but for now let's just focus on stdout
.
I think I prefer # to end-of-line
style syntax, like in shell/Perl/Python/Ruby/etc.
let
is currently handled in eval
, which isn't right. It should be a macro which is expanded as part of a general macro-expansion step between parsing and evaluation.
The whole Evaluator
class is a big mess! It'd be much better if each kind of node in the AST was its own class with an eval
function that took an environment and returned an expression and a possibly-updated environment.
I'm not sure how hard this would be, or how difficult it would be to integrate with the pattern-matching function arguments discussed in #31. But it'd sure be neat.
They're not currently defined, but they're pretty important.
We might also consider defining define
as a macro that uses set!
. Gonna have to look into it once we've got macro-expansion.
It'd be nice to know that tests keep on passin'.
Something like:
(load "my-library-file.blu")
eval
and apply
are special forms, so they're not currently accessible to the user. It'd be nice if they were.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.