Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Using let in Scheme

Name: Anonymous 2013-01-17 2:23

I remember a post a while back where the author said that it's better to avoid using binding constructs like let in languages like Scheme. I was wondering how you'd rewrite something like this:
(let ((s (find (lambda (a) (char=? x (first a))) *translation-list*)))
 (if s (second s) x))

Name: Anonymous 2013-01-20 10:16

>>8
function fact_helper(f, n) {
  if (n === 0) {
    return 1;
  } else {
    return n * f(f, n - 1);
  }
}

function factorial(n) {
  return fact_helper(fact_helper, n);
}


>>14

function fix_helper(self, f) {
  return function() {
    var args = Array.prototype.slice.call(arguments);
    return f.apply(null, [ self(self, f) ].concat(args));
  }
}

function fix(f) {
  return fix_helper(fix_helper, f);
}

function factorial() {
  return fix(function(f, n) {
    if (n === 0) {
      return 1;
    } else {
      return n * f(n - 1);
    }
  });
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List