Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: Quotations Date: Sun, 05 Jun 2016 21:20:59 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: <87shwraqxg.fsf@jester.gateway.pace.com> References: <94c723eb-affc-4c0b-a17c-cd761faa8ebb@googlegroups.com> <691a9a5f-5318-4dcb-83fe-85e09c8d7f80@googlegroups.com> <511607a1-a5ea-49fc-94df-aaa200d31c4d@googlegroups.com> <2016May30.172423@mips.complang.tuwien.ac.at> <58c4638d-3015-4b2a-bfc1-b7abb368dbd3@googlegroups.com> <2016Jun1.162929@mips.complang.tuwien.ac.at> <87zir3czkc.fsf@jester.gateway.pace.com> <87d1nxcx3s.fsf@jester.gateway.pace.com> <87wpm3awv0.fsf@jester.gateway.pace.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="a4ba9f006d4fba7a97cec7431fc63985"; logging-data="22241"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g6luu9Ww4ypEifu2vRjWv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:o/tbNzlogxZSPOhlsYj1uaxf0c4= sha1:VOOWUVMhEVSllplOqcL497M7aw0= Xref: csiph.com comp.lang.forth:47855 Paul Rubin writes: > Hmm, so maybe it's ok to call the closure after the parent has returned, > if there are no captured reference args. I just tried modifying a captured-by-value variable inside a C++ lambda and got a compile time error saying I'd tried to change a read-only variable. Also, it looks like the value is copied to the closure at the time the closure is made (changes between calls aren't reflected in the later calls). So I guess that explains. The code I tested: #include main() { int n = 7; auto clo = [n]() { std::cout << "n: " << n << "\n"; return 1; }; clo(); n++; clo(); } It prints "n: 7" twice. I think this is more complicated behaviour than one would expect to find in Forth.