Questions tagged [redefine]

101 questions
66
votes
4 answers

How to redefine a Ruby constant without warning?

I'm running some Ruby code which evals a Ruby file every time its date changes. In the file, I have constant definitions, like Tau = 2 * Pi and, of course, they make the interpreter display the unwanted "already initialized constant" warning every…
Eldritch Conundrum
  • 8,452
  • 6
  • 42
  • 50
54
votes
13 answers

Redefine Class Methods or Class

Is there any way to redefine a class or some of its methods without using typical inheritance? For example: class third_party_library { function buggy_function() { return 'bad result'; } function other_functions(){ return…
SeanDowney
  • 17,368
  • 20
  • 81
  • 90
36
votes
2 answers

How do I declare an array when I don't know the length until run time?

I originally had an array[1..1000] that was defined as a global variable. But now I need that to be n, not 1000 and I don't find out n until later. I know what n is before I fill the array up but I need it to be global therefore need a way to define…
Arthur
  • 3,376
  • 11
  • 43
  • 70
12
votes
2 answers

How do I redefine built-in Perl functions?

I want to do two things: In production code, I want to redefine the open command to enable me to add automagic file logging. I work on data processing applications/flows and as part of that, it's important for the user to know exactly what files are…
mmccoo
  • 8,386
  • 5
  • 41
  • 60
12
votes
1 answer

C preprocessor redefine conflict dependent on include order

I just had a redefine conflict in the project I'm working on and while tracing down why it's not happening on all platforms (turned out to be to order of includes), I stumbled upon the following behavior which I cannot explain. 1. compiles without…
grasbueschel
  • 879
  • 2
  • 8
  • 24
9
votes
2 answers

Can I use enable_if together with typedef?

I want to define a variable for which the type depends on some condition. I want something like this: typedef typename enable_if::type Type; typedef typename enable_if::type Type; But the conpiler says I redefined the…
maple
  • 1,828
  • 2
  • 19
  • 28
9
votes
1 answer

Redefining a function in an R package

I tried to modify and redefine a function (xcmsRaw) in R package xcms by first defining a function my.xcmsRaw <- function(filename, profstep = 1, profmethod = "bin", profparam = list(mzcorrf=1), # PATCH - mzcorrf is the m/z…
Tom Wenseleers
  • 7,535
  • 7
  • 63
  • 103
7
votes
2 answers

redefine __and__ operator

Why I can't redefine the __and__ operator? class Cut(object): def __init__(self, cut): self.cut = cut def __and__(self, other): return Cut("(" + self.cut + ") && (" + other.cut + ")") a = Cut("a>0") b = Cut("b>0") c =…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
7
votes
1 answer

XSD: How to redefine the data type of a simpleType eg. from xs:string to xs:integer

I am trying to extend and tailor an external xsd schema (of the fixml standard). I need to change the data type of some of the elements, without touching the original schema, but by redefining it; but have been finding it exceedingly cumbersome.…
VGDIV
  • 679
  • 1
  • 7
  • 16
5
votes
6 answers

How to reuse and override inherited javascript function

I have a class for mouse events. I'm using dojo b/c I like its OO approach dojo.declare("MouseObject", null, { constructor: function(){}, onclick : function(){...}, _onClick : function(){...} }); _onClick() listens for window generated mouse…
puk
  • 16,318
  • 29
  • 119
  • 199
5
votes
2 answers

Avoid redefinition preprocessor variable

I have various preprocessor variables which have the same name in different libraries. In order to avoid conflicts, what I am doing is (in the example there is only 1 conflicting variable and 1 header to include for simplicity): #ifdef VAR #define…
Marco Agnese
  • 349
  • 4
  • 15
5
votes
3 answers

Python __setattr__ and __getattr__ for global scope?

Suppose I need to create my own small DSL that would use Python to describe a certain data structure. E.g. I'd like to be able to write something like f(x) = some_stuff(a,b,c) and have Python, instead of complaining about undeclared identifiers or…
KT.
  • 10,815
  • 4
  • 47
  • 71
4
votes
5 answers

How to redefine malloc() in Linux for use in C++ new

I have a mem_malloc() and mem_free() defined for me and I want to use them to replace the malloc() and free() and consequently C++'s new and delete. I define them as follows: extern "C" { extern void *mem_malloc(size_t); extern void mem_free(void…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
4
votes
1 answer

Restrict element of type in other namespace

I think what I need to do it's not possible with XSD 1.0, but anyway I'll ask... I have a complexType in a file, say a.xsd. In principle, I cannot touch this file. In particular, I cannot change its targetNamespace. An example would…
J C Gonzalez
  • 861
  • 10
  • 23
3
votes
5 answers

How to redefine the = in python?

I would to know what Python call when I use the =: a = b Where do I look for this information? I would have the "assignment to variables" with my = a would have a similar behaviour l=list() l.append(1) l.append(2) l.append(3) l1=l l1[2]…
fege
  • 547
  • 3
  • 7
  • 19
1
2 3 4 5 6 7