self-reference

Why this works in C# (generic class and self-reference)?

为君一笑 提交于 2021-02-17 04:59:29
问题 I have class X<T> : Base { //For exemple: static T something(); } And I can have class A : X <A> { } To logically have something like this: class A : Base { static A something(); } This works and works well. But in my comprehension, it's kind of self-reference (A is the children of X, while X doesn't exists before A...), which is breaks the foundation of computer science, so I want to know what's wrong with my comprehension?? 回答1: It's totally fine. You can do similar without generics too:

module importing itself

为君一笑 提交于 2021-01-23 06:19:12
问题 I'm trying to import a module from an application-specific terminal (Maya in this case, but eventually others). I've downloaded a project off git, and I have a structure like so: modulename submodule __init.py__ subsubmodule ... submodule ... __init.py__ modulename.py Then in my execution shell, I'm trying to import the module to use on the shell, so I have: import sys,os modulepath = 'C:/path/to/module' sys.path.append(modulepath) import modulename If the modulename.py being imported is

Pure Prolog Scheme Quine

依然范特西╮ 提交于 2021-01-03 06:42:45
问题 There is this paper: William E. Byrd, Eric Holk, Daniel P. Friedman, 2012 miniKanren, Live and Untagged Quine Generation via Relational Interpreters http://webyrd.net/quines/quines.pdf Which uses logic programming to find a Scheme Quine. The Scheme subset that is consider here does not only contain lambda abstraction and application, but also a little list processing by the following reduction, already translated to Prolog: [quote,X] ~~> X [] ~~> [] [cons,X,Y] ~~> [A|B], for X ~~> A and Y ~~>

Pure Prolog Scheme Quine

柔情痞子 提交于 2021-01-03 06:40:14
问题 There is this paper: William E. Byrd, Eric Holk, Daniel P. Friedman, 2012 miniKanren, Live and Untagged Quine Generation via Relational Interpreters http://webyrd.net/quines/quines.pdf Which uses logic programming to find a Scheme Quine. The Scheme subset that is consider here does not only contain lambda abstraction and application, but also a little list processing by the following reduction, already translated to Prolog: [quote,X] ~~> X [] ~~> [] [cons,X,Y] ~~> [A|B], for X ~~> A and Y ~~>

c# generic self-referencing declarations

最后都变了- 提交于 2020-03-12 09:59:09
问题 I've been reading Albaharis' "C# 5.0 in A Nutshell" and I've encountered this in Generics section and it is said to be legal: class Bar<T> where T : Bar<T> { ... } And it meant nothing to me, although I've read the whole chapter carefully. I couldn't understand even a bit of it. Can someone please explain it with some understandable naming, like: class Person<T> where T : Person<T> { ... } And a real-world application scenario where this usage is appropriate and useful? 回答1: It means that T

Generate a typescript interface that references itself

可紊 提交于 2020-03-05 04:08:06
问题 EDIT: I have rewritten this question to be much clearer. I am trying to programmatically infer an interface which references itself. I am writing some code which can encode a recursive structure in binary. For example: const myTreeEncoder = Struct(Self => ({ name: Str, children: List(Self) }); This can encode structures like this from binary and back: const someUint8Array = myTreeEncoder.encode({ name: 'parent', children: [{ name: 'child', children: [] }] }); The problem is, how can the

Defining something to itself in C preprocessor

天涯浪子 提交于 2020-02-14 12:13:31
问题 I ran into these lines: #define bool bool #define false false #define true true I don't think I need to say more than "wtf?", but just to be clear: What is the point of defining something to itself? The lines come from clang stdbool.h 回答1: The C and C++ standards explicitly allow that (and requires that there is no infinite expansion) BTW, function-like recursive (or self-refential) macros are even more useful: #define puts(X) (nblines++,puts(X)) (the inner puts is a call to the standard puts

Implementing the ruler function using `streamInterleave`

强颜欢笑 提交于 2020-01-24 22:14:24
问题 I am doing the homework of CIS 194. The problem is to implement the ruler function by using streamInterleave . The code looks like data Stream a = Cons a (Stream a) streamRepeat :: a -> Stream a streamRepeat x = Cons x (streamRepeat x) streamMap :: (a -> b) -> Stream a -> Stream b streamMap f (Cons x xs) = Cons (f x) (streamMap f xs) streamInterleave :: Stream a -> Stream a -> Stream a streamInterleave (Cons x xs) ys = Cons x (streamInterleave ys xs) ruler :: Stream Integer ruler =