Yuce's Blog

Cognitive dissonance is yoga for the brain.*

Accumulator Generator

2005-04-26

In his ac­cu­mu­la­tor generator page, Paul Graham compares several languages to solve a particular problem that is quoted below (apparently, he has chosen this example in favor of his new Lisp-like language Arc):

The problem: Write a function foo that takes a number n and returns a function that takes a number i, and returns n in­cre­ment­ed by i.

Note: (a) that's number, not integer, (b) that's in­cre­ment­ed by, not plus.

My trial with Marvin was a failure, and could not satisfy all the 5 re­quire­ments given here. But now with Marvin2 (a rewrite of the language) this can be ac­com­plished with the following line:

@foo !n [ %n + ^n ] ;

Nice... You can then run the sample code like this:

1 'foo new !x
5 \x
3 'foo new
2.3 \x println

And the result is 8.3, as expected.

marvin, accumulator generator, Paul Graham

comments powered by Disqus