Path: csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Kaz Kylheku <157-073-9834@kylheku.com> Newsgroups: comp.compilers Subject: Re: Add nested-function support in a language the based on a stack-machine Date: Wed, 14 Mar 2018 14:49:01 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 45 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <18-03-066@comp.compilers> References: <6effed5e-6c90-f5f4-0c80-a03c61fd2127@gkc.org.uk> <18-03-042@comp.compilers> <18-03-049@comp.compilers> <18-03-055@comp.compilers> <18-03-060@comp.compilers> <18-03-064@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="29301"; mail-complaints-to="abuse@iecc.com" Keywords: syntax, design Posted-Date: 14 Mar 2018 17:36:48 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:2007 On 2018-03-14, Kartik Agaram wrote: > On Tue, Mar 13, 2018 at 5:07 PM, Kaz Kylheku <157-073-9834@kylheku.com> wrote: >> Anonymous functions without environments are basically just >> function pointers. >> >> If those are first class functions, then C has first class functions. > > C doesn't have anonymous functions (ignoring a combination of GNU > extensions added sometime after 1988). But you mentioned anonymous > functions, so you must be aware of this. So I'm not sure what you're > saying. That's just a syntactic restriction on where functions are placed in the program text, due to the lack of a function literal syntax. If functions don't require an environment, you can easily add anonymous function literals with a textual preprocessor like GNU m4, by implementing a completely trivial "no-environment lambda lifting". Syntax like: some_fun(LAMBDA{int (int a, int b){ return a + b; }}) is simply replaced by some_fun(f_0013); accompanied by the insertion of static int f_0013(int arg){ return arg + 1; }) into the global scope. This is easy enough that it's usually not a major inconvenience to simply do it by hand. If the C preprocessor were slightly more powerful, it could handle the above. Once we obtain a function as a function pointer by evaluating its name, then it has been anonymized. We can pass it around the program, store it in variables and structures and so on. It has the same power as a lambda-with-no-env. -- TXR Programming Lanuage: http://nongnu.org/txr Music DIY Mailing List: http://www.kylheku.com/diy ADA MP-1 Mailing List: http://www.kylheku.com/mp1