Thanks to all for your ideas.
Independently of Gray, I arrived at something pretty similar, as follows.
It then turned out that this wasn't in the end what I needed for my
package, but I am working on something very similar.
transform(a::BigFloat) = a
transform(a::Number) = :(
El viernes, 19 de septiembre de 2014 08:34:05 UTC-5, David P. Sanders
escribió:
Hi, for a package I'm writing (or, more precisely, trying to write), I
need to do the following:
Change `:(3 + pi)`
into `:(3 + big(pi))`
or `:(BigFloat(3) + BigFloat(pi))`
I forgot to say that I need
In fact, I will also need to wrap floating-point constants like 2.1 as
BigFloat(2.1),
I believe.
(Apologies for the self-replies.)
To do what you want, very briefly:
x.args[3] == :pi x.args[3] = Expr(:call, :BigFloat, :pi)
This will make more sense if you look at `xdump` output to see how Exprs
are structured
(and `xdump` is quite handy to know about in general). Try:
xdump(:(big(3) + big(pi)))
...
On Fri, Sep 19,
BigFloat(pi) is undefined, so that should be `Expr(:call, :big, :pi)`, but
hopefully the rest makes sense.
On Fri, Sep 19, 2014 at 9:58 AM, Isaiah Norton isaiah.nor...@gmail.com
wrote:
To do what you want, very briefly:
x.args[3] == :pi x.args[3] = Expr(:call, :BigFloat, :pi)
This will
El viernes, 19 de septiembre de 2014 08:58:56 UTC-5, Isaiah escribió:
To do what you want, very briefly:
x.args[3] == :pi x.args[3] = Expr(:call, :BigFloat, :pi)
This will make more sense if you look at `xdump` output to see how Exprs
are structured
(and `xdump` is quite handy to know
El viernes, 19 de septiembre de 2014 09:26:09 UTC-5, David P. Sanders
escribió:
El viernes, 19 de septiembre de 2014 08:58:56 UTC-5, Isaiah escribió:
To do what you want, very briefly:
x.args[3] == :pi x.args[3] = Expr(:call, :BigFloat, :pi)
This will make more sense if you look at
Depth-first search and replace?
— John
On Sep 19, 2014, at 7:32 AM, David P. Sanders dpsand...@gmail.com wrote:
El viernes, 19 de septiembre de 2014 09:26:09 UTC-5, David P. Sanders
escribió:
El viernes, 19 de septiembre de 2014 08:58:56 UTC-5, Isaiah escribió:
To do what you
Yes, that's what I need, thanks. Now I need to iterate over the (in
principle arbitrarily complex, i.e. nested) syntax tree and do this
everywhere.
Is there a standard method for this kind of iteration?
I guess some kind of recursion. I'll give it a go...
Beyond that, you might find some
Hi,
you might try something like this:
function mapleaves(f,expr)
if typeof(expr) == Expr
expr.args[2:end]=map(e-mapleaves(f,e),expr.args[2:end])
return expr
else
return :($f($expr))
end
end
you can apply it like this:
eval(mapleaves(BigFloat,:(1+sin(1
I
On Friday, September 19, 2014 9:32:09 AM UTC-5, David P. Sanders wrote:
El viernes, 19 de septiembre de 2014 09:26:09 UTC-5, David P. Sanders
escribió:
El viernes, 19 de septiembre de 2014 08:58:56 UTC-5, Isaiah escribió:
To do what you want, very briefly:
x.args[3] == :pi x.args[3]
Oops, the second method was a mutating biggen! It should have been
function biggen(x::Expr)
Meta.isexpr(x, :call) || error(Only works for calls right now)
x = copy(x) ## Otherwise we'll rewrite the arguments of the original
expression
for i in 2:length(x.args)
x.args[i] =
The Expr method had an error and would overwrite the expressions in its
argument. Here's a better version.
function biggen(x::Expr)
Meta.isexpr(x, :call) || error(Only works for calls right now)
y = copy(x);
for i in 2:length(y.args)
y.args[i] = biggen(x.args[i])
end
Additional examples in base/cartesian
On Friday, September 19, 2014 07:26:09 AM David P. Sanders wrote:
El viernes, 19 de septiembre de 2014 08:58:56 UTC-5, Isaiah escribió:
To do what you want, very briefly:
x.args[3] == :pi x.args[3] = Expr(:call, :BigFloat, :pi)
This will make more
14 matches
Mail list logo