This is specific to the REPL display. If you try:
import Base.Multimedia.displays
then use display(displays[1], fm) instead, you will not get the new lines.
(This might vary depending on setup; on my setup displays[1] is the text
display and displays[2] is the REPL). It's obviously not a good idea to do
this; it's better to just NOT use the REPL for your function.
On Saturday, June 21, 2014 2:21:34 PM UTC+12, Leah Hanson wrote:
>
> My code calls `display` on a bunch of values (of a type I define). Most of
> these values chose not to display anything; only a few of them are meant to
> print anything at all. However, running the code currently generates a lot
> of extra new lines for the non-printing values.
>
> This is the main function being run:
>
> ~~~
> function checkallmodule(m::Module;test=checkreturntypes,kwargs...)
> score = 0
> for n in names(m)
> f = eval(m,n)
> if isgeneric(f) && typeof(f) == Function
> fm = test(f;mod=m,kwargs...)
> score += length(fm.methods)
> display(fm)
> end
> end
> println("The total number of failed methods in $m is $score")
> end
> ~~~
>
> The variable `fm` will be a FunctionSignature. The two relevant custom
> types and their `writemime` methods are below:
>
> ~~~
> type MethodSignature
> typs::Vector{AType}
> returntype::Union(Type,TypeVar) # v0.2 has TypeVars as returntypes; v0.3
> does not
> end
> MethodSignature(e::Expr) = MethodSignature(argumenttypes(e),returntype(e))
> function Base.writemime(io, ::MIME"text/plain", x::MethodSignature)
> println(io,"(",join([string(t) for t in x.typs],","),")::",x.returntype)
> end
>
> type FunctionSignature
> methods::Vector{MethodSignature}
> name::Symbol
> end
>
> function Base.writemime(io, ::MIME"text/plain", x::FunctionSignature)
> for m in x.methods
> print(io,string(x.name))
> display(m)
> end
> end
> ~~~
>
> The call to `display` in `checkallmodule` should end up calling
> `writemime` for `FunctionSignature`. In the case that the
> `FunctionSignature` has no methods, the for-loop will not execute and
> nothing should be displayed. However, there are still a lot of new lines
> appearing when I run the code.
>
> Does anyone have any pointers to what might be going wrong or how I might
> avoid these new lines?
>
> Thanks,
> Leah
>