I used Expr to express a very very complicated math expression. I used println(io,expr) to put it into a file.
The size of the file is 480KB.
When I opened the file (using vscode,so I’m sure the problem is not here), I found it ended in -, with unclosed (, by the way there’s no new line.
# does derivation
function der(a::Symbol)
if a==:x
return 1
else
return 0
end
end
function der(a::Int)
return 0
end
function der(a::Expr)
f=a.args[1]
if f==:+
return Expr(:call,:+,der(a.args[2]),der(a.args[3]))
elseif f==:-
return Expr(:call,:-,der(a.args[2]),der(a.args[3]))
elseif f==:*
return Expr(:call,:+,Expr(:call,:*,a.args[2],der(a.args[3])),Expr(:call,:*,der(a.args[2]),a.args[3]))
elseif f==:/
return :($(der(a.args[2]))*$(a.args[3])-$(a.args[2])*$(der(a.args[3]))/$(a.args[3])^2)
elseif f==:ln
return :($(der(a.args[2]))/$(a.args[2]))
elseif f==:^
return :($(der(a.args[3]))*($(a.args[3])*$(a.args[2])^($(a.args[3])-1)+ln($(a.args[2]))*$(a.args[2])^$(a.args[3])))
else # can ignore
return Expr(:call,0)
end
end
f=:(x^x^x^x^x^x)
io=open("D:/1.txt","w")
println(io,der(der(der(der(f)))))