yhara / biwascheme Goto Github PK
View Code? Open in Web Editor NEWThis project forked from biwascheme/biwascheme
yhara's private clone of BiwaScheme. The official one is:
Home Page: https://github.com/biwascheme/biwascheme
License: MIT License
This project forked from biwascheme/biwascheme
yhara's private clone of BiwaScheme. The official one is:
Home Page: https://github.com/biwascheme/biwascheme
License: MIT License
Currently, things like ()
, and (lambda)
work, but they shouldn't (reference implementation Chez Scheme gives invalid syntax (lambda)
, for example).
While things like (if)
and (define xif if)
are uncaught errors that cause BiwaScheme to stop working. (Chez Scheme gives invalid syntax if
.)
1. rewrite library functions which return `undefined’ to return undef
2. rewrite define_libfunc not to convert `undefined’ nor`null’
3. add define_libfunc2 (TODO: better name) which does not raise for `undefined’/`null’
I recently tried the biwascheme repl in firefox. The hello world sample code produces this error:
$(this.dumparea) is null
I have tried this in firefox 3.5 on windows, and firefox 3 on linux.
I remember that the previous time I tried it (a few months ago) it didn't work in firefox either, but it was ok in Internet Explorer.
gensym implementation could look like this:
BiwaScheme.gensymcount = 0;
BiwaScheme.define_libfunc('gensym', 0, 0, function(args) {
with(BiwaScheme) {
return new Sym('#' + gensymcount++);
}
});
I've found that there is BiwaScheme.gensym function but it's not accessable from scheme.
BiwaScheme.define_libfunc('gensym', 0, 0, function(args) {
return BiwaScheme.gensym();
}
In line 14404 and 14421 of biwascheme.js, assoc checks for the presence of a pair by running x.car.car though an if(...) statement. This presents a type 2 error in cases where the car of the pair is anything that would return false, like 0 or #f.
I fixed it in my tests by replacing:
if(x.car.car) {
...
}
with
if(typeof(x.car.car) != "undefined") {
...
}
When applying functions like cadr to a list, for which it should not work (and raise the message "Error: Attempt to apply car on nil"), instead the result is "[BUG] library function `cadr' returned JavaScript's undefined". I guess this is a low-priority bug, since it presents itself only when the input is incorrect, but nevertheless I doubt it is what is expected.
The bug also appears when calling caddr and cadddr with similar examples.
Example:
(cadr '(1))
[BUG] library function `cadr' returned JavaScript's undefined
Version is 0.5.7, as seen on repl.it
for picture language
[UPDATE] Updated to general scoping issue.
(define x 1)
(print x) ;;1
(define (i n)
(define x 2)
n)
(print x) ;; #<undef>
(i 1)
(print x) ;; 2
And this is a general block scoping issue, its not confined to define
.
No matter how deep you nest blocks, block structure definitions always escape to the global scope.
The demos at http://www.biwascheme.org/ don't work for me (at least in Google Chrome).
If you use undefined variable in macro, when you use it it will return javascript undefined.
eg.:
(define-macro (foo x) y)
(foo 10) ; this return nothing
above throw "[BUG] library function `macroexpand' returned JavaScript's undefined"
(macroexpand '(foo 10))
This bug makes very dificult to debug macros.
main.scm:
(load "test.scm")
test.scm:
(define TWO_PI (* 2 3.14))
cause error.
due to prototype's Hash
All we need is stack trace, right? :-)
At least, names of called functions should be shown
I think it affects more than just list-ref, but bounds checking is broken:
biwascheme> (list-ref (iota 9) 9)
[BUG] library function `list-ref' returned JavaScript's undefined
biwascheme> (list-ref (iota 9) 11)
d is undefined
In the most recent version, the error is the same, though the variable is named 'o' instead of 'd'. These interactions were taken from the interpreter on biwascheme.org.
It's pretty clear what's causing this in the implementation -- it's just a case of some edge cases slipping through the implementation (returning x.cdr without checking if it is defined, for example).
error on Opera:
Statement on line 937: Type mismatch (usually non-object value supplied where object required) Backtrace: Line 937 of linked script http://www.biwascheme.org/repos/lib/stackbase.js ret = this.find_free(body, b.set_union(vars.to_set()), f); Line 959 of linked script http://www.biwascheme.org/repos/lib/stackbase.js set = set.set_union(this.find_free(p.car, b, f)); Line 930 of linked script http://www.biwascheme.org/repos/lib/stackbase.js ret = this.find_free(x.cdr, b, f); //(ignores improper list) Line 1089 of linked script http://www.biwascheme.org/repos/lib/stackbase.js var free = this.find_free(body, proper.to_set(), f); //free variables Line 1163 of linked script http://www.biwascheme.org/repos/lib/stackbase.js return this.compile(expr, [new Set(), new Set()], new Set(), new Set(), ["halt"]); Line 1168 of linked script http://www.biwascheme.org/repos/lib/stackbase.js return (new Compiler).run(expr, next); Line 1686 of linked script http://www.biwascheme.org/repos/lib/stackbase.js var opc = Compiler.compile(obj); Line 8 of inline#1 script in http://www.biwascheme.org/repos/repl.html: In function bs_eval var opc = biwascheme.compile(str); Line 1 of function script bs_eval() ...
separate-dumper-code brach of
http://devel.srpmix.org/biwascheme.git
example: you can do this in Gauche
(define xif if)
(xif 1 2 3)
There will be nice if funtions in scheme have documentations.
(documentation 'function)
could return documentation string. It could be kept in BiwaScheme.Symbols association array.
BiwaScheme.define_libfunc function could have fifth parameter which hold documentation string.
There is also need to update interpreter and compiler to put first element, after argumets, from procedure definition, if it's string, to BiwaScheme.Symols array for specific procedure name.
Here is the code for extracting documentation from scheme procedure. doc variable holds documentation string and name variable is name of the symbol.
var tokens = (new BiwaScheme.Parser(str)).tokens;
if (tokens[1] == "define") {
var doc = "";
var name = ""
if (tokens[2] == "(") {
//procedure definition
start_scan = 2;
name = tokens[3];
} else if (tokens[3] == "(" && tokens[4] == "lambda") {
//lambda expresion
start_scan = 5;
name = tokens[2];
}
for (i=2; i<tokens.length-1; ++i) {
if (tokens[i] == ")" && tokens[i+1].match(/".*"/)) {
doc = tokens[i+1];
}
}
}
But I don't know where to put it.It could be done with something like:
BiwaScheme.Symbols[name].doc = doc;
The documenation function should look like this
BiwaScheme.define_libfunc('documentation', 1, 1, function(args) {
if (typeof args[0] == BiwaScheme.Symbol) {
name = args[0].to_write();
} else if (typeof args[0] == "string") {
name = args[0];
}
return typeof BiwaScheme.Symbols[name] != "undefined" && BiwaScheme.Symbols[name].documentation() || BiwaScheme.udef;
}
In BiwaScheme,
(eq? "hi" "hi") => #t
but should be #f, since strings should be heap-allocated objects in usual Schemes. This can be solved by making a BiwaScheme String object to take advantage of native JS ==. Additionally, this allows for mutable strings because the String object's wrapped value can simply be replaced.
example:
(+ 1 (lambda ()))
will stop the browser trying to serialize all the elements of the closure array.
The same thing happens when giving wrong typed big object to a function call.
Maybe we should make to_write2 (or something) which snips the output.
then we can paste a 'link' to scheme snippets, like:
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.