Deutsch English Français Italiano |
<20241222132505.353@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Sun, 22 Dec 2024 21:45:14 -0000 (UTC) Organization: A noiseless patient Spider Lines: 87 Message-ID: <20241222132505.353@kylheku.com> References: <vjlh19$8j4k$1@dont-email.me> <vjn9g5$n0vl$1@raubtier-asyl.eternal-september.org> <vjnhsq$oh1f$1@dont-email.me> <vjnq5s$pubt$1@dont-email.me> <vjpn29$17jub$1@dont-email.me> <86ikrdg6yq.fsf@linuxsc.com> <vk78it$77aa$1@dont-email.me> Injection-Date: Sun, 22 Dec 2024 22:45:15 +0100 (CET) Injection-Info: dont-email.me; posting-host="ccd8ace10f73d1976dbd98bdbf28dd7f"; logging-data="843345"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tntTSCr90WgmcNdw+HprFBqih2Bj21gQ=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:OFWsvfAyuNusR0QKnpSN6tYYzO8= Bytes: 4095 On 2024-12-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > On 21.12.2024 02:28, Tim Rentsch wrote: >> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes: >> >>> On 16.12.2024 00:53, BGB wrote: >>> >>>> [...] >>>> >>>> Pretty much all higher level control flow can be expressed via goto. >>> >>> A 'goto' may be used but it isn't strictly *necessary*. What *is* >>> necessary, though, that is an 'if' (some conditional branch), and >>> either 'goto' or recursive functions. >> >> Conditional branches, including 'if', '?:', etc., are not strictly >> necessary either. > > No? - Can you give an example of your statement? In a functional langauge, we can make a decision by, for instance, putting two lambdas into an array A, and then calling A[0] or A[1], where the index 0 or 1 is comes from some Boolean result. The only reason we have a control construct like if(A, X, Y) where X is only evaluated if A is true, otherwise Y, is that X and Y have side effects. If X and Y don't have side effects, then if(A, X, Y) can be an ordinary function whose arguments are strictly evaluated. Moreover, if we give the functional language lazy evaluation semantics, then anyway we get the behavior that Y is not evaluated if A is true, and that lazy evaluation model can be used as the basis for sneaking effects into the functional language and conctrolling them. Anyway, Turing calculation by primitive recursion does not require conditional branching. Just perhaps an if function which returns either its second or third argument based on the truth value of its first argument. For instance, in certain C preprocessor tricks, conditional expansion is achieved by such macros. When we run the following through the GNU C preprocessor (e.g. by pasting into gcc -E -x c -p -): #define TRUE_SELECT_TRUE(X) X #define TRUE_SELECT_FALSE(X) #define FALSE_SELECT_TRUE(X) #define FALSE_SELECT_FALSE(X) X #define SELECT_TRUE(X) X #define SELECT_FALSE(X) #define PASTE(X, Y) X ## Y #define IF(A, B, C) PASTE(TRUE_SELECT_, A)(B) PASTE(FALSE_SELECT_, A)(C) #define FOO TRUE #define BAR FALSE IF(FOO, foo is true, foo is false) IF(BAR, bar is true, bar is false) We get these tokens: foo is true bar is false Yet, macro expansion has no conditionals. The preprocessing language has #if and #ifdef, but we didn't use those. Just expansion of computed names. This is an example of not strictly needing conditionals to achieve conditional evaluation or expansion: an IF(A, B, C) operator that yields B or C depending on the truth of A, and so forth. John MacCarthy (Lisp inventor) wrote himself such an IF function in Fortran, in a program for calculating chess moves. It evaluated both the B and C expressions, and so it wasn't a proper imperative conditional, but it didn't matter. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca