Thank you Johan and Jameson.

Johan, I don't know how to make a loop on the fields with a function. For 
example this doesn't work:

function removeLine(poly::Poly, index::Int)

    for op = (:a, :b, :x1, :y1, :x2, :y2, :typ)

        splice!(poly.$op, index)

    end

end


How to do, please ?


Le jeudi 8 mai 2014 15:59:06 UTC+2, Jameson a écrit :
>
> Replace your macro with a function and delete the uses of eval. You code 
> will be faster, and easier to understand. Most of the difficulty people 
> seem to have with macros comes from thinking they are a type of function 
> call -- the @ character is supposed to remind you that this is not true.
>
> On Thursday, May 8, 2014, Johan Sigfrids <[email protected]<javascript:>> 
> wrote:
>
>> I myself have been hitting my head against the wall that is 
>> meta-programming in Julia. I think I can answer your first question at 
>> least.
>>
>> Q1: This is because the line poly = emptyPoly doesn't create a new copy 
>> of a ploygon but a reference to the empty one so that both poly and 
>> emptyPoly 
>> refer to the same data. You need to do poly = deepcopy(emptyPoly) . 
>>
>> On Thursday, May 8, 2014 9:56:27 AM UTC+3, Stéphane Laurent wrote:
>>
>> Hello everybody,
>>
>>  Below I define two new types : Line and Poly. The Poly type is intended 
>> for stacking some lines.  
>>
>> type Line
>>
>>         a::Float64   # intercept
>>
>>         b::BigFloat  # slope
>>
>>         x1::BigFloat # x-coordinate of first vertex
>>
>>         y1::BigFloat # y-coordinate of first vertex
>>
>>         x2::BigFloat # x-coordinate of second vertex
>>
>>         y2::BigFloat # y-coordinate of second vertex
>>
>>         typ::Bool    # type of the line (true:upper, false:lower)
>>
>> end
>>
>>
>> type Poly
>>
>>         a::Vector{Float64}
>>
>>         b::Vector{BigFloat}
>>
>>         x1::Vector{BigFloat}
>>
>>         y1::Vector{BigFloat}
>>
>>         x2::Vector{BigFloat}
>>
>>         y2::Vector{BigFloat}
>>
>>         typ::Vector{Bool}
>>
>> end
>>
>>
>>
>> I also define the empty Poly:
>>
>> emptyPoly = Poly(Array(Float64,0), Array
>>
>> 

Reply via email to