3 ms·
That's interesting... I've been thinking about this for a while now and at first I thought it would be incredibly bloated, but now I'm not so sure. Definitely
by koningrobot 18y ago
That's interesting... I've been thinking about this for a while now and at first I thought it would be incredibly bloated, but now I'm not so sure. Definitely interesting.
- lucindo 18y agojust for fun: function copylist(lst) { return mapcar(function (x) { return x; }, lst); } function last(lst) { if (null == lst) { return null; } else if (null == cdr(lst)) { return lst; } else { return last(cdr(lst)); } } ugly append: function append() { var lst = null; var i = 0; for (; i < arguments.length && null == lst; i++) { if (null != arguments[i]) { lst = copylist(arguments[i]); } } for (; i < arguments.length; i++) { if (null != arguments[i]) { setcdr(last(lst), copylist(arguments[i])); } } return lst; } the fun: function qsort(lst) { if (null == lst) { return null; } else { var pivot = car(lst); var nlst = cdr(lst); return append(qsort(filter(function (x) { return x < pivot; }, nlst)), list(pivot), qsort(filter(function (x) { return x >= pivot; }, nlst))); } } function powerset(lst) { if (null == lst) { return null; } else { var first = car(lst); var rest = powerset(cdr(lst)); return append(list(list(first)), mapcar(function (x) { return append(list(first), x); }, rest), rest); } }