mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 17:20:29 +02:00
Implement keyword argument parsing
This commit is contained in:
parent
46905ec322
commit
e84f839463
4 changed files with 69 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
var scheme = {
|
||||
obarray : {},
|
||||
primitives : {},
|
||||
utils : {},
|
||||
env : {},
|
||||
cache: [],
|
||||
builtins: [],
|
||||
|
@ -117,6 +118,25 @@ scheme.Keyword = function(s) {
|
|||
return this;
|
||||
};
|
||||
|
||||
scheme.utils.keyword_ref = function(kw, args, start, dflt) {
|
||||
var l = args.length;
|
||||
|
||||
if ((l - start) % 2 == 1) {
|
||||
// FIXME: should error
|
||||
return undefined;
|
||||
}
|
||||
// Need to loop in reverse because last matching keyword wins
|
||||
for (var i = l - 2; i >= start; i -= 2) {
|
||||
if (!(args[i] instanceof scheme.Keyword)) {
|
||||
return undefined;
|
||||
}
|
||||
if (args[i].name === kw.name) {
|
||||
return args[i + 1];
|
||||
}
|
||||
}
|
||||
return dflt;
|
||||
};
|
||||
|
||||
// Vectors
|
||||
scheme.Vector = function () {
|
||||
this.array = Array.prototype.slice.call(arguments);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue