On Fri, Oct 31, 2008 at 1:15 AM, Arnar Birgisson <[EMAIL PROTECTED]> wrote:
> To draw from Python again, both could be implemented with one function
> called "bool". This would convert any object to a boolean.

Nice idea!

> How about a generic "first" function in Iter? Would be
>
> first(someCheck, iterable[, defaultValue=undefined])

This too!

> I'm not sure I understand, JS doesn't have named arguments so this
> would be called with
>
> x = dict({'key1': 'val1', 'key2': 'val2'})
>
> right? Isn't that just the identity function?
>
> function dict(x) { return x; }

My list was a bit too compact perhaps, but the source code explains it all:

/**
* Creates a dictionary object from a list of keys and values. It
* can be used either as a reverse of items(), or as a reverse of
* keys() and values(). That is, either the function take a single
* list where each element contains both key and value, or it takes
* two separate lists, one with keys and the other with values. If
* a key is specified twice, only the last value will be used.
*
* @code dict([['a', 1], ['b', 2]]) --> { a: 1, b: 2 }
* dict(['a','b'], [1, 2]) --> { a: 1, b: 2 }
*
* @param {Array} itemsOrKeys the list of items or keys
* @param {Array} [values] the optional list of values
*
* @return {Object} a dictionary object with all the keys set to the
* corresponding value
*/
MochiKit.Base.dict = function(itemsOrKeys, values) {
    var o = {};
    if (!MochiKit.Base.isArrayLike(itemsOrKeys)) {
        throw new TypeError("First argument must be array-like");
    }
    if (MochiKit.Base.isArrayLike(values) && itemsOrKeys.length !==
values.length) {
        throw new TypeError("Both arrays must be of same length");
    }
    for (var i = 0; i < itemsOrKeys.length; i++) {
        var k = itemsOrKeys[i];
        if (k === null || k === undefined) {
            throw new TypeError("Key at index " + i + " is null or undefined");
        } else if (MochiKit.Base.isArrayLike(k)) {
            o[k[0]] = k[1];
        } else if (MochiKit.Base.isArrayLike(values)) {
            o[k] = values[i];
        } else {
            o[k] = values;
        }
    }
    return o;
}

> If MK is ever used in a command-line JS interpreter, then environment
> would suggest the OS environment variables. I propse platform().
>
> platform() should return an object with keys/values if called with no
> arguments, and return a the value of a key otherwise.. i.e.
>
> platform() == {'kind': 'browser', 'name': 'Google Chrome', 'version': ...}
> platform('name') == 'Google Chrome'

That's the name I was looking for! Thanks!

>> But again. If I'm the only one interested in pushing [Widget] forward it
>> is probably better suited for a separate project.
>
> I think it might. To me, MK is a programmer's utility library. UI
> libraries should be kept separate because everyone want's a different
> UI. Also, UI libraries are huge cans of worms.

I hear what you are saying. MK already has lots of UI stuff, but only
as a thin wrapper on the HTML DOM. And I don't think adding another
layer has to be very intrusive. Actually, it is the very reason for my
recent interest in making it easier to pack your own MochiKit version
when downloading. I'll probably push my prototype for that onto the
download page any year now.

Cheers,

/Per

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to