Optional function arguments

Discussions about the RPL and RPL+ programming languages

Optional function arguments

Postby oliver » Mon Oct 31, 2016 10:30 pm

A principal disadvantage of RPL over algebraic is that there's no syntactic structure that bundles function arguments.
You can readily see what params are passed to f(a, b, c), for example, whereas x y z a b c f on the stack gives you no hints that f will consume a b c. The number of args to a function is a priori knowledge about the function you need to have.

This also implies, that there can be no optional arguments.

In v1.6, RPL+ offers the following solution: use a global dictionary by the name of options to pass optional arguments.

For example:
Code: Select all
≪ 1..5 { separator: "." } =options join ≫ evals to ""

Dictionary's are JSON objects. RPL+ function may access these uses the common "." syntax for property access.

The options global can be accessed in user-written RPL+ and JavaScript functions. In RPL, use options (as in options.separator to access the example option shown above). In JavaScript, use vars.options (vars.options.separator).
The properties on the options objects are freely defined and can be of various types. For example, you may pass 1-n strings, booleans, numbers with property names of your choosing.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to RPL / RPL+

Who is online

Users browsing this forum: No registered users and 1 guest