04-22-2014, 04:22 PM

Hello,

As newRPL slowly progresses, we are in need of small code examples to use in the docs.

Examples need to be short and straight to the point.

But the idea is that the examples should do something cool or fun at the same time, so the docs are not so hard to swallow.

Does anybody know of a collection of userRPL "gems" anywhere?

Or if each of you share their own favorite code snippets here, we can create a small collection of them.

Here's an example that shows how to do linear interpolation, using only stack commands:

given x0 y0 x1 y1 x, returns y corresponding to the point in the same straight line as (x0,y0) and (x1,y1), that has coordinate x.

I know, it isn't that great but shows the use of PICK and ROLL commands, while doing something meaningful. Then we can rewrite the same example but using local variables to show a different way to do it. This is the kind of examples we are looking for.

Thanks

As newRPL slowly progresses, we are in need of small code examples to use in the docs.

Examples need to be short and straight to the point.

But the idea is that the examples should do something cool or fun at the same time, so the docs are not so hard to swallow.

Does anybody know of a collection of userRPL "gems" anywhere?

Or if each of you share their own favorite code snippets here, we can create a small collection of them.

Here's an example that shows how to do linear interpolation, using only stack commands:

given x0 y0 x1 y1 x, returns y corresponding to the point in the same straight line as (x0,y0) and (x1,y1), that has coordinate x.

Code:

<< 3. PICK - 5. ROLL 4. ROLL - / 3. ROLL 3. PICK - * + >>

I know, it isn't that great but shows the use of PICK and ROLL commands, while doing something meaningful. Then we can rewrite the same example but using local variables to show a different way to do it. This is the kind of examples we are looking for.

Thanks