Questions tagged [self-reference]

Self-reference is the ability of a program (or logical sentence) to refer to itself, either directly or indirectly.

Self-reference is the ability of a program (or logical sentence) to refer to itself, either directly or indirectly.

Useful Links:

Stanford Encyclopedia 'Self Reference' Entry

Related Tags:

596 questions
20
votes
5 answers

Building Self-Referencing Tuples

After seeing a conversation in a forum from many years ago that was never resolved, it caused me to wonder how one would correctly create a tuple that referenced itself. Technically, this is a very bad idea since tuples are supposed to be immutable.…
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
19
votes
2 answers

Reflexive type parameter constraints: X where T : X ‒ any simpler alternatives?

Every so often I am making a simple interface more complicated by adding a self-referencing ("reflexive") type parameter constraint to it. For example, I might turn this: interface ICloneable { ICloneable Clone(); } class Sheep : ICloneable { …
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
18
votes
2 answers

Is there an identity index value in JavaScript?

In JavaScript, values of objects and arrays can be indexed like the following: objOrArray[index]. Is there an identity "index" value? In other words: Is there a value of x that makes the following always true? let a = [1, 2, 3, 4]; /* Is this true?…
Shivam
  • 1,345
  • 7
  • 28
16
votes
2 answers

MySQL foreign keys on self

I'm currently trying to make a self referencing table in MySQL, however it seems I can't make a foreign key on the table itself, I'm getting an MySQL error: Error Code: 1005. Can't create table 'biological classification' (errno: 150) This is my…
Skeen
  • 4,614
  • 5
  • 41
  • 67
16
votes
4 answers

Java generics self-reference: is it safe?

I have this simple interface: public interface Node> { public E getParent(); public List getChildren(); default List listNodes() { List result = new ArrayList<>(); // ------> is this…
Michele Mariotti
  • 7,372
  • 5
  • 41
  • 73
15
votes
4 answers

Recursive function: Call php function itself

I just want to make sure I do it right and this will not create any conficts. I have a function which calls itself and need your approval if it's OK or not to do so? $value)…
Andrei Surdu
  • 2,281
  • 3
  • 23
  • 32
14
votes
3 answers

In C++, how to make a variant that can contain a vector of of same variant?

I a trying to make a std::variant that can contain a vector of the same variant: class ScriptParameter; using ScriptParameter = std::variant >; I am getting ScriptParameter redefinition.…
JeffV
  • 52,985
  • 32
  • 103
  • 124
14
votes
1 answer

Many-to-many self-referential relationship in sqlalchemy

I'm trying to make a self-referential many-to-many relationship (it means that Line can have many parent lines and many child lines) in sqlalchemy like this: Base = declarative_base() class Association(Base): __tablename__ = 'association' …
mike
  • 141
  • 1
  • 4
14
votes
3 answers

Python: How to refer a class inside itself?

Trying to refer a class inside itself. For e.g. class Test: FOO_DICT = {1 : Test.bar} # NameError: name 'Test' is not defined @staticmethod def bar(): pass Does this usage make sense? Any better alternatives? Thanks!
cheng
  • 6,596
  • 6
  • 25
  • 27
14
votes
1 answer

What method does Python 2 use to print tuples?

Python's print statement normally seems to print the repr() of its input. Tuples don't appear to be an exception: >>> print (1, 2, 3) (1, 2, 3) >>> print repr((1, 2, 3)) (1, 2, 3) But then I stumbled across some strange behavior while messing…
ashastral
  • 2,818
  • 1
  • 21
  • 32
13
votes
1 answer

class (or struct) self-reference by template

Is the following legal? template< typename T > struct tree_node { T t; std::vector children; }; A comment to this post seems to suggest that it is not. EDIT: This doesn't strike me as an "undefined behavior" type of…
Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
13
votes
7 answers

Self referential enum with immutable parameters

Consider the following sscce public enum Flippable A (Z), B (Y), Y (B), Z (A); private final Flippable opposite; private Flippable(Flippable opposite) { this.opposite = opposite; } public Flippable flip() { return opposite; …
durron597
  • 31,968
  • 17
  • 99
  • 158
12
votes
3 answers

Enforce a foreign-key constraint to columns of same table

How to enforce a constraint of foreign key on columns of same table in SQL while entering values in the following table: employee: empid number, manager number (must be an existing employee)
Pop Stack
  • 926
  • 4
  • 19
  • 27
12
votes
3 answers

How to handle readlink() of "/proc/self/exe" when executable is replaced during execution?

In my C++ application, my application does an execv() in a fork()ed child process to use the same executable to process some work in a new child process with different arguments that communicates with pipes to the parent process. To get the…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
11
votes
3 answers

using self referencing in sql server

create table EMP(Eid int primary key) insert into EMP values(11e3) --self referencing alter table EMP add constraint fk_EMP_Eid foreign key (Eid) references EMP(Eid) --now insert insert into EMP values(12e2) But, this insert should fail,…
sqlchild
  • 8,754
  • 28
  • 105
  • 167
1
2
3
39 40