From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9858 invoked from network); 25 Oct 2021 16:51:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Oct 2021 16:51:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1635180662; b=XvENVmJlmko8XqbtXxZ+cQLxvW0GOt8X8LofyWX7rrUnRiOdu960xW9C7dM0/bZK0n7x9TDR0m 896QQFBB3cgTKmmxqJ9FQ6vOEhpUsKOZToEOHW/l8pJtZASPzhY2kK4hUwkcTtNUHC8tfvV2IO byS5ZkgLNzh2eZcYU1fdnDb9gPZbjKgz5QORTHHk1QSd9G4Sz9jHkNXSHrE8PTUY2tgj45UmxM X0KHH+ElllrnVBr0qhNI3i1CN6tIxkko3fzeG6N8nsGg5fFia6k4W9/HJ5VkZY9qQuQn4uJUTg gTHOvAGvWzc4oFg2wlW69y/ml6vP/+APkDpVfaXVpioVRg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f182.google.com) smtp.remote-ip=209.85.219.182; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1635180662; bh=v1DFkviH7TcqG6GjLbHZuKqRetPlTYZxxFHdzUKcBcE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=R5CCzOkqEwvQJazuLyy8T1jmgs6Ra6be4RQtY1ogcaFN9L8xdpX/Tbhidh5pU/Fgy5JqRqeT6R sJyXcj4KuF0EFd0T/VxWhCpC4Bx5Y3ij9rEhri/+Pd1shsERxu+Qe5EoUyqDJp4bIZ5QDhNp66 D228i3DmafVNuxR4pE+KiwA8v3tJ9nxQmKyjFYf/kHzfyJzHbKmOlZDmDC2KCgBwmd27oSiWfh ehCLtLoJ0GF38C3TsziP98XXtUIgH1uV9KGlJeMuVy8fGFdJN3JdJrZv/HwLqvS56rELPNmQzm PC/1MqvtnnNs/4BMHz1wDCwgcbBfb6ORQkmRniLOCiG9vQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=XHVyGQNmr4C2dCcQJrG8sGa+kTLLcRditaWDXQju13o=; b=EXarNZiTQmq9U8I0kAullQovU4 0MzmOm9Zs0Zn7DZUA39CkqiX+v4DviYPmQnUZLiCWSJ2HHGmiQIf9PHvEE6AixyBSl7l+Szt8PkQq aElm1xPXN4LGljb2TZipcUuJtkQC2TEiGdESYBVBWJAS5uYQSTdajBeXYHy7jPfuYUVw0XoZ3dZzq lOsFTMePJmH9/uyem5ERyH3HYupVH6lNML3992G4S6c4Pwuxz7D8eT2VIp1ayQ8vCS9iKbpJLhB+k 1jxyDPatFpZa4P1/UpDFSkS++0MwM5CqsGYDj4LqDeBdwQHU+GfzorGaDv502gcu1NngaReFX7qEO u/3iVp7Q==; Received: from authenticated user by zero.zsh.org with local id 1mf3Bc-0005y0-OC; Mon, 25 Oct 2021 16:51:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f182.google.com) smtp.remote-ip=209.85.219.182; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f182.google.com ([209.85.219.182]:39443) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mf3AU-0005GJ-9z; Mon, 25 Oct 2021 16:49:51 +0000 Received: by mail-yb1-f182.google.com with SMTP id 67so27606620yba.6 for ; Mon, 25 Oct 2021 09:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XHVyGQNmr4C2dCcQJrG8sGa+kTLLcRditaWDXQju13o=; b=1jktni8ztmR1mQPl3B/odzj2TgRuVGvMpVXYIe5cXFmuMQavj1ICZIb1lz8TvWwIFp ViZzZbHYqW9sDp0xFtnyR9cVZz9HxnGh/1MafxeO5NarmaT4reZKbYer2NGwiee0pIrN Y7RMxHfo3cto2LREhuYJUGyrXMlxwg/TjjG+XYyl0ZdfsY3C+2+ylBkuAKoiiUPNBtNK 3p5bYIuoIzZ99rYTGddt8JHXflphsKtAcK/gy9EQEGZFljbrPu3k3V+edsZWusCnrd69 pXFcE5FfuTqca1WjrvvHsnqsg0wNXoGgi1ikcNwzO2GFC8gHNEc4UlSjXfTzGVqHI3Ub mwrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XHVyGQNmr4C2dCcQJrG8sGa+kTLLcRditaWDXQju13o=; b=QSJ+LQXXKT11kGW33W7GdK6LWL1f7RMu0hsU/igs3RegsfN3yZJrSkkP+uRqwtWVe9 Hy7zznSCgSJxkCu4fU9U+YuEbJl3JIrzf0JnOGoG5hu6Ek6dwY7Q6Mg7yCFXYXhIkCPt BXvPUg/coLVXLv+G4p3E67Mke439aX1m4m+dBv4ojnd/8Zcog0IG1lLYEtZUvs7bhwWA 4gviqRWDtkyN6dXOzBhl/fMvUTbc3mjTs9/FFJ2at3R47Pt82H1m8U1sfRuREmd4HTaR hXcpBrKLT8ZHciKNIOKwn7vLFmePBnlvbAcjbskhXZKM2hFL0TuIPwBJVXmHI4Jcmunl /VWA== X-Gm-Message-State: AOAM5335Bf/YjyWBUbDu0m1BrK/UNIKHhtWakqUAWa5P2nGmiQzowtby 2rOBOUsSuqOLP84bkJ6VChkY3pN0zIK9oUUxQsHWeg== X-Google-Smtp-Source: ABdhPJyFzQCOT7BXZxrG+2og7DKsqd1yX95JbH5LQC8gP+BljGsyWi4Cmb5eYK7uaIijuEgn4zhsaaR2crrII28kviY= X-Received: by 2002:a25:2541:: with SMTP id l62mr18419875ybl.365.1635180588785; Mon, 25 Oct 2021 09:49:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Mon, 25 Oct 2021 09:49:37 -0700 Message-ID: Subject: =?UTF-8?Q?Re=3A_How_to_=E2=80=9Cnamespace=E2=80=9D_an_autoloaded_function=3F?= To: Marlon Richert Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27287 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Mon, Oct 25, 2021 at 12:36 AM Marlon Richert wrote: > > On 10/25/21, Bart Schaefer wrote: > > On Sun, Oct 24, 2021 at 2:17 AM Marlon Richert > > wrote: > >> > >> What would be the canonical way to make the body of function 'foo.bar' be > >> autoloaded from '/some/path/to/bar'? > > > > There isn't a "canonical" way, really. The autoload mechanism is > > entirely dependent on the file name and the function name being the > > same. > > Can you think of another way to do this than to autoload the function > and copy it to a new function? No. There is no mechanism for changing the name of a function while autoloading it. There is a way you could automatically initialize such a namespace, but it's not exactly the same as loading it on demand in the way your use of the term "autoload" implies. Also, if a function bar calls another function baz, invoking the body of bar as foo.bar won't run foo.baz under any circumstances I can imagine, so this whole idea of namespaces falls apart pretty quickly if there is any interdependency (or recursion that doesn't reference $0). > Also, what would be the best way to do this in batch form? That is, I > want to autoload _all_ function files from a particular dir as > foo. instead of just . Initializing the namespace goes something like this: source <( unfunction -m \* fpath=(/some/path/to) autoload +X $^fpath/*(N) for f in ${(k)functions} do functions -c $f foo.$f unfunction $f done functions ) To get something more like on-demand loading, replace the "functions" at the end with zcompile -c $TMPPREFIX.foo print "fpath+=($TMPPREFIX.foo.zwc); autoload ${(k)functions}" but that mostly saves memory rather than time because you still have to pre-load all the function sources. (Note I did not actually test this, so it may need adjustment.) If your namespaces are known in advance you can create the zcompile files in a more permanent location, and then you only have to build them once (or each time /some/path/to changes contents). > > alias -s bar='namespacedfunction' > > Would this work when calling foo.bar from inside a function that was > loaded with `autoload -U`? No, it would not.