朱莉娅:基本功能的意外扩展

时间:2018-11-22 18:43:30

标签: julia

我有以下不完整的Julia代码:

function delete_table_column_db( $table_name, $column_attrs ){
    global $wpdb;
    $query = "SELECT COUNT(*) AS no_of_columns FROM information_schema.columns WHERE table_name = '{$table_name}'"
    $check_column_count = $wpdb->get_results( $query );
    $nbr_columns = (int) $check_column_count[0]['no_of_columns'];
    if( $check_column_count === 1 ){
        $res = $wpdb->query( "DROP TABLE {$table_name}"  );
    }else{
        $res = $wpdb->query( "ALTER TABLE {$table_name} DROP {$column_attrs['name']}" );
    }
    if( $res === false ){
        error_log( sprintf("The column %s could not be deleted for the table %s", $column_attrs['name'], $table_name ) );
    }
}

当我尝试使用它时,出现以下错误:

  

LoadError:方法定义中的错误:函数Base.step必须为   明确导入以进行扩展   LoadError:方法定义中的错误:函数Base.reset必须为   明确导入以进行扩展

我不知道Base.step和Base.reset是什么,并且我不想扩展它们。

我是否可以通过某种方式保留这些函数名称而不扩展基本函数?如果我只是使用完全不相关的方法扩展基本函数,会不会有问题?

我真的不想更改函数名称,因为我想使其与OpenAI Gym API保持一致。

1 个答案:

答案 0 :(得分:3)

在这样的模块内定义它们

module Gym

mutable struct Env
end

function step(env, action::UInt32)
    return ones(8), 1.0, true, Dict()
end

function reset(env)
    return ones(8)
end

end

然后,您可以在模块内部以stepreset的形式直接调用它们。在模块之外,您必须像这样对它们进行限定:Gym.stepGym.reset

另外-请注意,只有在尝试扩展stepreset模块(例如,通过调用或引用它们)之前在Main模块中引入$ julia _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.0.2 (2018-11-08) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | julia> step(x) = x step (generic function with 1 method) $ julia _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.0.2 (2018-11-08) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | julia> step step (generic function with 4 methods) julia> step(x) = x ERROR: error in method definition: function Base.step must be explicitly imported to be extended 时,才会出现此问题。因此,当启动干净的Julia会话时,它将起作用:

***************************************
* [1] READ FORM CSV FILE :: input.csv *
***************************************
GET DATA
/TYPE=TXT
/FILE='input.csv'
/FIRSTCASE=2
/VARIABLES=
startDate1 ADATE8
endDate1   ADATE8
startDate2 ADATE8
endDate2   ADATE8
startDate3 ADATE8
endDate3   ADATE8
startDate4 ADATE8
endDate4   ADATE8
.

***********************************
* [2] DEFINE VARIABLE :: earliest *
***********************************
Variable earliest:
COMPUTE earliest = MIN(startDate1,startDate2,startDate3,startDate4).
EXECUTE.

**************************************
* [3] SAVE TO CSV FILE :: output.csv *
**************************************
SAVE TRANSLATE
/OUTFILE='output.csv'
/REPLACE
/TYPE=CSV

但这会失败:

output.csv