Opened 5 years ago
Closed 5 years ago
#800 closed enhancement (fixed)
Supporting sub-routine in OmegaScript
Reported by: | Gaurav Arora | Owned by: | Olly Betts |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Omega | Version: | |
Severity: | normal | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Operating System: | All |
Description (last modified by )
I was wondering why does OmegaScript have a way to define a sub-routine which can be called multiple times to avoid repetition while writing omegascript template.
For example, if have a subroutine which needs to be executed multiple times. it would be interesting to define a subroutine which can be used multiple times and probably make writing omega-script easy.
$function{$list{$map{$opt{ARGUMENT1}, $lower{$_}, , .}, ARGUMENT1}
So this will define a subroutine. We can call this and this will get a value and the apply map and list. This might be required multiple times. Hence defining sub-routine might be more convenient than copy-pasting same code multiple times.
Is there a reason why it cannot be supported in OmegaScript?
Change History (3)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Component: | Other → Omega |
---|---|
Type: | defect → enhancement |
comment:3 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yes, macros cover the use-case I had in mind initially. Thanks Olly.
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.
E.g. you can do:
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.