Trying to extend my answer to maybe cover another idea that may help you find what you are looking for.
Red/System
From my understanding, the Red/System #define
directive can help with optimization (in reducing function calls). Here is a similar example in Red/System. Within Red, it would require using within #system
or #system-global
directive.
#define COMPUTE(x) (3.13159 * 2.0 + x)
b: COMPUTE(1.0)
print b
Processing the macro should result in:
b: (3.13159 * 2.0 + 1.0)
print b
and results
7.26318
Math between types isn't defined yet, so you'll run into issues multiplying/adding float!
and integer!
(hence the above use of float!)
Red/Rebol
You can also take a look at compose
as a higher level way to optimize your code writing. I am unsure of the effect in terms of optimizing speed. What compose does is take a block and evaluate whatever is in parenthesis and not evaluate other elements in the block.
See the Rebol2 help definition for compose
>> help compose
USAGE:
COMPOSE value /deep /only
DESCRIPTION:
Evaluates a block of expressions, only evaluating parens, and returns a block.
COMPOSE is a native value.
ARGUMENTS:
value -- Block to compose (Type: any)
REFINEMENTS:
/deep -- Compose nested blocks
/only -- Inserts a block value as a block
This may be what you're looking for in terms of building expressions
red>> x: 1
== 1
red>> compose [3 + 2 + (x)]
== [3 + 2 + 1]
An example from the Rebol2 documentation:
>> probe compose [time: (now/time) date: (now/date)]
[time: 12:48:53 date: 5-Mar-2014]
== [time: 12:48:53 date: 5-Mar-2014]
for (...; ...; ...)
, curly-braces for blocks, etc.)), and it's probably best to label your code's language correctly. In particular, I would generally avoid labelling Scheme, Clojure, or Arc code as "Lisp". – Fitts