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
4
votes
3 answers

Implement a self-reference/pointer in a pure/functional language (Elm/Haskell)

Abstract Problem: I'd like to implement a self-reference / pointer in Elm. Specific Problem: I'm writing a toy LISP interpreter in Elm inspired by mal. I'm attempting to implement something like letrec to support recursive and mutually-recursive…
advait
  • 6,355
  • 4
  • 29
  • 39
4
votes
1 answer

self referencing relationship with spring data jpa

I am building an application with spring boot and have to setup a self-referencing relationship. In order to make the scenario simple and easy to understand, I have tried to work on a similar scenario with a department entity example. Following is…
4
votes
1 answer

DELETE recursive PostgreSQL

I have a table upload_temp as it follows: CREATE TABLE upload_temp ( codigo serial PRIMARY KEY NOT NULL, codigo_upload_temp_pai INTEGER, nome TEXT NOT NULL, codigo_extensao INTEGER, data_inclusao TIMESTAMP NOT NULL DEFAULT…
Siipe
  • 468
  • 1
  • 5
  • 13
4
votes
3 answers

PostgreSQL self referential table - how to store parent ID in script?

I've the following table: DROP SEQUENCE IF EXISTS CATEGORY_SEQ CASCADE; CREATE SEQUENCE CATEGORY_SEQ START 1; DROP TABLE IF EXISTS CATEGORY CASCADE; CREATE TABLE CATEGORY ( ID BIGINT NOT NULL DEFAULT…
Opal
  • 81,889
  • 28
  • 189
  • 210
4
votes
1 answer

c# - How do self-referencing classes or circular-referencing classes within same assembly compile successfully

I would like to know how C# and .Net compiler is able to successfully compile a self-referenced class or circular referenced classes within same assembly. Consider the following code is present within the same assembly. class X{ X x; } class Y{ Z z;…
4
votes
2 answers

Self-referential CASE WHEN clause in SQL

I'm trying to migrate some poorly formed data into a database. The data comes from a CSV, and is first loaded into a staging table of all varchar columns (as I cannot enforce type safety at this stage). The data might look like COL1 | COL2 |…
J. Doe
  • 43
  • 5
4
votes
4 answers

Referencing this pointer in constructor

Following is another example of forward declaration, which might be useful if the application needs a self-sustaining array of objects which is able to add and remove objects from itself during run-time: File a.h: class A { public: static A…
q126y
  • 1,589
  • 4
  • 18
  • 50
4
votes
2 answers

Java Self-Referential Generics With Wildcards

Is it possible to specify that an unknown generic type is self-referential? A failed attempt: import java.util.*; class Generics { public enum A { A1, A2 } public enum B { B1, B2 } public static List>…
Michaelll
  • 85
  • 7
4
votes
1 answer

Validating a self-referential association doesn't link back to the original instance in rails

I have a many-to-many model, following the example in this great railscast My model links authors to each other. I'd like to validate that an author cannot friend himself. I know I can handle this at the UI level, but I'd love to have a validation…
4
votes
2 answers

How to duplicate rows of self-referenced table

Suppose we have a self-referenced table like this CREATE TABLE Month ( Id int IDENTITY(1,1) PRIMARY KEY, Title char(128) ) CREATE TABLE Entity ( Id int IDENTITY(1,1) PRIMARY KEY, MonthId int FOREIGN KEY REFERENCES Month(Id), Name…
4
votes
2 answers

Recursive calls to database in perl

I know there's an easy way of doing this, but my recursion abilities are out of practice. Given a database table that has three fields: id label child_id I should be able to put together a recursive function that will give output like this: child…
coding_hero
  • 1,759
  • 3
  • 19
  • 34
4
votes
8 answers

Self referential type

What type T makes the following code compilable? T f(){ return &f; } I'd prefer a C answer, but I marked the question as C and C++ in case there is only an answer using templates.
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
4
votes
1 answer

How to define a one to one self reference using Entity Framework Code First

I want to implement versioning on my entity Stuff. Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity…
4
votes
1 answer

Bidirectional self referential associations

Taking Ryan Bates' asciicast as an example: http://asciicasts.com/episodes/163-self-referential-association He ends with two associations of User :friends :inverse_friends Given that a user would not care who instigated the friendship, you would…
Kevin Monk
  • 1,434
  • 1
  • 16
  • 23
4
votes
2 answers

Python: deletion of self referencing object

I want to ask how to delete an object with a self-reference in Python. Let's think a class, which is a simple example to know when it is created and when it is deleted: #!/usr/bin/python class TTest: def __init__(self): self.sub_func= None …
Akihiko
  • 362
  • 3
  • 14