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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24604 invoked from network); 23 Aug 2022 07:22:18 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Aug 2022 07:22:18 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1661239338; b=hhT1HkWHSkWQnc+FM6ACYwXZjaiUIro1/fCVi8eANz0L8kCvUaM143uN2dnGV77Kdk7mc1FYH4 bwYW95JomnhxCAWeox9Lqzxi5F8sEb9WlfwGNCT71koA6hEibRjL4kj+i281qx6mCTzCU/PTqF 4Bkwc6KhGshF5JQ0VA2lz/909cPHHIvP483GA+7DKa6u+CYDN6dJHfpDY2ipxLhTWDETirT2Mv Qed/unMoxPJxzSBVGKzkDpmkAsbKWV7T2bgde61jvdARidYPlqAr6lfUSairkkB33yGScMT3tU ivgnTopszlmiR+ohvLgd4jKeGDN71JBQdHph7Zn2h6/+0g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1661239338; bh=8VWFmbE8GGHWp81gJD52PhJuJo9NHtUICpZyn/ul2C4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=fBzO08LwHz89NYLAW9i/fXG8sJny5NSjO3jNjssy5FDOiOpFxGmnBXFrn1SEEM8hq2bChRkNKj O0wGAeUM7fs5uiv5C4m/GJLhkPpM9tJc1VCobF/RUFrhOKxTOAxsSw7EoOFcWmjjwCSB2UuNEE wLC1JYnhWGB+0ecgP/c6Shv6Grv2l7cOLUATPY7tva1LfvHs9Edo+Qt+6Deb3DUHrpYL9J6oT+ UBp8BWKDCJLCi9aLnIv+SCyGfiqiYATOnc3HFqn6QLdO/2cGGAzi+6BC2Ox4MsUhWV/cnLBlQj 3Ldv8/hvgVGr8MPTGIgdGlAluiVj61mUWTjkU9XSUfUFcg==; 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-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=E8EkK18ehG34jS5hw16S1kUCoyHMzDjiqz+SBr4ahEc=; b=qtV+uKDnPYUbWKCci0EEh774gv NCttBZEKXx/+t/UVzyusMyIiLrOQG1OpS7R8MS2euDNlJDjpR9N4JC6o+pOw6WsZMBYsCiurE4Fnf b+kNvL4AsBhneFGzQMypWlm3aRocn6CxOFTlPvIl1+G1LT/gIZPY7lGtSkxYQ+ke8G4tJUnJacRIi Saxidq8zW5QK2me5hisSvwOwwuc2yTndd4isn+9AYc0MxMQzysmjzaRrUf/Fi4ZQx/YXzNnBvgZKg eynxikkPuz06Zzy3haec7AikufKQYVE6IzAV0uWL41/hJO1uOkMj4ddJLdj/FkOwoeyo9a3j5b90v nOgsz4yQ==; Received: from authenticated user by zero.zsh.org with local id 1oQOEr-0007mt-QH; Tue, 23 Aug 2022 07:22:17 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f47.google.com ([209.85.221.47]:42809) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oQOEH-00076S-La; Tue, 23 Aug 2022 07:21:42 +0000 Received: by mail-wr1-f47.google.com with SMTP id u14so15863313wrq.9; Tue, 23 Aug 2022 00:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=E8EkK18ehG34jS5hw16S1kUCoyHMzDjiqz+SBr4ahEc=; b=cKFta6jDQJCPtrwuyaXLnDQBep/h45cXwxsMXqkz4TRFoNgltlPLd08ZZFQHILZQ+W jDzZ9z/oe9ObjRsiu+k/Dv+7JpM70nWfU05zzF04YlVRSBWPIgsUYtD5ea7hYvnA46F6 sCDAEyez4wYW/8vZVnpY1NpSLKQm1BVOiEXW8nlgicHZJh9b4+MBoaKsiARXxh63IOBM Q4JtzJ8W+EmUNkpTGfNKfyodInHa84AHP6/L68Ciqi497UhlaNqj0b646DNW0V8Bqlfs 8Qa12e4pQD6suFmv5tmY2wq/ofd+SymGAIpLo4FzVwVaVFneWshgkjuMrgCcyOP/IG5Y W96g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=E8EkK18ehG34jS5hw16S1kUCoyHMzDjiqz+SBr4ahEc=; b=71qJqqDVLIn5B9WwZeTgk0MdqaLxke9y0JAASwEfKVow3X/rA57EsBiXvAQvhULWie i+ZH355FMBq5NkSRHefjtuWFp9owsyBH8yZWWCiUXir2Py255fwhkK+QLrkwbpx2s4pX z6pS/IwmKeovOljXLRm+IabjVCJafbDMzrVQpoZBWO9VsT1a0wKTZJgykvHA2b6dNMcL KbCEdGoaP4urgu0SB6l8FClPUaVzbFsrqPPQ28Q1DQHiDjSUpeQWnaNfw6rjLi6N8qGt Wm4LVOPh8bJEVbEhBce8cbi6YN7ktx+XMuPkwMEvE8yzZVPxIkYNfgCo77+oQwoj+XSE 83Cg== X-Gm-Message-State: ACgBeo2xFKcuPzdPOtrAD2e4ct6UhleEPc6iIUaKvn9rTaGxSfdn3Te1 Eb0TY4lx35eaJZzAs/LsaFf5usp6BG5YStWtY0swX0lz X-Google-Smtp-Source: AA6agR4VAN/0Ptz214a09CIjKEhJgK2AexRd6uiBptXNyEt+jRaq//PEptHsBPPAREF3tE+vY+yKMXeyuU5U6OZzTQ8= X-Received: by 2002:a05:6000:a05:b0:225:6149:20cc with SMTP id co5-20020a0560000a0500b00225614920ccmr2910936wrb.681.1661239300513; Tue, 23 Aug 2022 00:21:40 -0700 (PDT) MIME-Version: 1.0 References: <4f73130d-1d7b-46af-ab04-72a04fc89727@www.fastmail.com> In-Reply-To: <4f73130d-1d7b-46af-ab04-72a04fc89727@www.fastmail.com> From: Roman Perepelitsa Date: Tue, 23 Aug 2022 09:21:27 +0200 Message-ID: Subject: Re: anonymous function question To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= Cc: linuxtechguy@gmail.com, zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 27990 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 Tue, Aug 23, 2022 at 5:37 AM Lawrence Vel=C3=A1zquez wr= ote: > > - Comment removal is performed during parsing. Thus, setting and > unsetting INTERACTIVE_COMMENTS changes how parsing is done. > - A complex command is parsed *in its entirety* before *any* of its > commands are executed. Thus, a command within a complex command > cannot affect how the rest of the complex command is parsed. > > Therefore, a complex command cannot enable or disable comments > within itself. It can affect subsequent commands, though: That's basically correct. Note that *all* options stay constant during parsing, not just INTERACTIVE_COMMENTS. Also note that functions are always parsed in their entirety and only once and aliases are expanded during parsing. This often surprises people. Consider this script: alias foo=3D'echo 1' function bar() { foo alias foo=3D'echo 2' } bar bar bar foo This script prints "1" three times followed by "2". If you add `functions bar` at the bottom to print the body of function bar, it'll reveal what's going on: bar () { echo 1 alias foo=3D'echo 2' } As you can see, the alias within the function has been expanded during pars= ing. There are several more options (in addition to INTERACTIVE_COMMENTS and ALIASES) that affect parsing: SH_GLOB, BRACE_EXPAND, etc. # Set unusual options. setopt no_brace_expand function foo() { # Set the usual options. emulate -L zsh print -- {1,2} } foo This prints "{1,2}" rather than "1 2". Options set by a function affect its execution but not parsing. Another thing that can be surprising is that zcompile parses the whole file all at once with the options and aliases that are active at the time zcompile is invoked. This means that sourcing a file directly may have a different effect from zcompiling and sourcing it afterwards. >script.zsh <<\END alias echo=3D'echo 1' echo 2 END ( source ./script.zsh ) zcompile ./script.zsh ( source ./script.zsh ) This prints "1 2" followed by "2". This is one of the reasons I wouldn't recommend zcompiling zsh startup files. There are other (and more important) reasons, too. Roman.