Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 56c9c2542faa5f15915725d8bc67ca34ddd93bf6
Ticket: 1932618fffffffffffffffffffffffffffffffff
Enhance [proc] for anonymous functions and closures
User & Date: dkf on 2016-07-14 07:26:05
Changes

  1. assignee changed to: "dkf"
  2. icomment:
    This is genuinely tricky to do without introducing some whopper incompatibilities at the deep semantic level. In particular, "capturing the current environment" is difficult without causing deep trouble with values that are not properly serializable (unlike <i>all</i> current Tcl-defined values). The problem is that <tt>proc</tt> creates commands, and command handles are single values with an expectation that they can be used transparently.
    
    However, you can do a lot with <tt>coroutine</tt> and <tt>apply</tt> without tackling the deeply difficult parts. You can also do a lot more if you're creating a <tt>method</tt> and not a procedure call; the extra context (and the expectation of calling the code via an object handle) make a big difference. Finally, you also gain options if you drop the expectation of being able to modify captured variables and have those modifications persist. (There are also issues relating to what the expected captured stack would look like; I <i>really</i> recommend not trying to capture that without a <tt>coroutine</tt>!) For example, if you drop being usable a single value and modifying the captures, you can do it with <tt>apply</tt> and some creative scripting.
    
  3. login: "dkf"
  4. mimetype: "text/x-fossil-wiki"