[Xapian-tickets] [Xapian] #800: Supporting sub-routine in OmegaScript
Xapian
nobody at xapian.org
Wed Jan 22 17:31:58 GMT 2020
#800: Supporting sub-routine in OmegaScript
--------------------------+-------------------------------
Reporter: Gaurav Arora | Owner: Olly Betts
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Omega | Version:
Severity: normal | Resolution:
Keywords: | Blocked By:
Blocking: | Operating System: All
--------------------------+-------------------------------
Changes (by Olly Betts):
* type: defect => enhancement
* component: Other => Omega
Comment:
We already have "macros" - I guess you searched for "function" and didn't
spot these? Perhaps we should note in the docs they offer a "function-
like" feature or something like that.
{{{
$def{MACRONAME,VALUE}
define a macro which can take 0 to 9 arguments. You can call it
with
``$MACRONAME`` (if it take 0 arguments) or
``$MACRONAME{ARG1,ARG2,ARG3}`` is it takes arguments. In value,
arguments are available as ``$1``, ``$2``, ... ``$9``. In the
current
implementation, macros can override OmegaScript commands, but this
shouldn't be relied on. It's recommended to use capitalised names
for
macros to avoid collision with future OmegaScript commands.
}}}
E.g. you can do:
{{{
$def{PRETTYLIST,$list{$map{$1,$lower{$_}},$. }.}
$PRETTYLIST{$cgilist{FOO}}
$PRETTYLIST{$cgilist{BAR}}
}}}
It seems you're thinking to pass parameters via `$set{...}` which seems
less nice than being able to call a macro with parameters just like you'd
call a built-in !OmegaScript command.
Is there anything you need that macros don't offer?
The main limitations are probably that they don't currently support lazy
evaluation, and there's no checking for the number of arguments passed.
The mechanisms for these exist as macros use the same machinery as built-
in commands - the hardest part is probably coming up a clean way to
specify them when defining a macro.
--
Ticket URL: <https://trac.xapian.org/ticket/800#comment:2>
Xapian <https://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list