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

Uses of self referencing lists

I know it is possible to create a self referencing list in languages like Python: >>> my_list = [1,2] >>> my_list.append(my_list) >>> print my_list [1,2,[...]] >>> print my_list[0] 1 >>> print my_list[2] [1,2,[...]] What algorithms benefit from…
Escualo
  • 40,844
  • 23
  • 87
  • 135
11
votes
3 answers

How to declare a self-referential container in C++?

For a typedef of a struct in C, I can't do this: typedef struct { unsigned id; node_t *left; node_t *right; } node_t; because node_t is not known until it is defined, so it can't be used in its own definition. A bit of a Catch-22.…
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
11
votes
4 answers

Recursive reference to a list within itself

So I came across something very weird in python. I tried adding a reference to the list to itself. The code might help demonstrate what I am saying better than I can express. I am using IDLE editor(interactive…
Guy
  • 604
  • 5
  • 21
11
votes
4 answers

self-referential methods with generic return type for multiple inherited classes

It's probably a bit difficult to describe. However, I'll try it ;) Following the fluent style, it is common that a method of a class returns the class instance itself (this). public class A { public A doSomething() { // do something…
zazi
  • 686
  • 1
  • 7
  • 19
10
votes
1 answer

How to get the current script's code in Python?

I want to get the current script as a string in a variable in Python. I found two sub-optimal ways, but I hope there is a better solution. I found: The inspect import has a getsource method, but that only returns the code of one function (or class…
agtoever
  • 1,669
  • 16
  • 22
10
votes
1 answer

Python cx_Freeze name __file__ is not defined

I have a python script which gets an image from the internet, downloads it, sets as desktop background and updates after on minute. The problem is most likely cx_Freeze not including the os module, as the same code with absolute paths works fine. My…
9
votes
3 answers

What do you call a function that calls itself (is this called recursion)?

I am trying to figure out what you call a function that references itself. Is this termed recursion? Or is it simply a self-referencing function?
user858642
  • 187
  • 2
  • 2
  • 6
9
votes
1 answer

self-reference in Haskell functions

I am learning Haskell and I the following expression on Haskell Wiki really puzzled me: fibs = 0 : 1 : zipWith (+) fibs (tail fibs) I can't quite figure out why this works. If I apply standard Currying logic (zipWith (+)) returns a function takes…
9
votes
1 answer

EF Code First with many to many self referencing relationship

I am starting out with using the EF Code First with MVC and am a bit stumped with something. I have the following db structure (Sorry but I was not allowed to post an image unfortunately): Table - Products Table - RelatedProducts 1-Many on…
9
votes
3 answers

has_many :through multiple has_one relationships?

I'm writing a mentorship program for our church in rails (im still farily new to rails).. And i need to model this.. contact has_one :father, :class_name => "Contact" has_one :mother, :class_name => "Contact" has_many :children, :class_name =>…
9
votes
1 answer

Django: Query self referencing objects with no child elements

I have the following django model: class Category(models.Model): name = models.CharField(maxlength=20) parent = models.ForeignKey('self', null=True) Note that the field parent is self referencing i.e. a category can have a parent. How can I…
Frankline
  • 40,277
  • 8
  • 44
  • 75
9
votes
1 answer

Entity Framework Code First: how to map multiple self-referencing many-to-many relationships

I have created an entity type that has multiple collection properties that reference items of the same type. In other words, it reflects a single database table in which the rows are arbitrarily grouped, such that a row may appear in multiple…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
9
votes
2 answers

Fluent NHibernate Self Referencing Many To Many

I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList
Jeremy
  • 93
  • 1
  • 5
8
votes
4 answers

Javascript literal object, reference to itself

I have this example code: var foo = { self: this, init: function(){ self.doStuff(); }, doStuff: function(){ alert('doing stuff'); } } foo.init(); Why the refence "self" doesn't work? Thanks!
mauriblint
  • 1,802
  • 2
  • 29
  • 46
8
votes
1 answer

Entity Framework 4 CTP 5 Self Referencing Many-to-Many

I have the following scenario in my database. It is a record of Studies and those studies have other studies as prerequisites. In my DB design, it looks like this: And my code looks something like this: public class Study { public int ID {…
1 2
3
39 40