zsh-workers
 help / color / mirror / code / Atom feed
* Compiled files ignore aliases
@ 2016-02-05 15:33 Sebastian Gniazdowski
  2016-02-05 16:37 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-05 15:33 UTC (permalink / raw)
  To: Zsh hackers list

Hello,
this is probably expected as aliases are applied on parsing time. But
maybe this wasn't yet recognized?

% cat 2test-script.zsh
#!/bin/zsh
alias autoload="echo Hello; autoload"
#autoload() { echo "Hello"; builtin autoload "$@" }
source "./test-script.zsh"
echo "|"${functions[abc]}"|"


% cat test-script.zsh
#!/bin/zsh
echo "Hello from script, will call a builtin"
autoload abc


Output when using alias in 2test-script.zsh and test-script.zsh is
compiled (there is .zwc file):
% ./2test-script.zsh
Hello from script, will call a builtin
|builtin autoload -X|

Output when using function in 2test-script.zsh:
% ./2test-script.zsh
Hello from script, will call a builtin
Hello
|builtin autoload -X|


Any way to have aliases working when sourcing .zwc file?

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiled files ignore aliases
  2016-02-05 15:33 Compiled files ignore aliases Sebastian Gniazdowski
@ 2016-02-05 16:37 ` Bart Schaefer
  2016-02-05 17:24   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-02-05 16:37 UTC (permalink / raw)
  To: Zsh hackers list

On Feb 5,  4:33pm, Sebastian Gniazdowski wrote:
}
} this is probably expected as aliases are applied on parsing time. But
} maybe this wasn't yet recognized?

This is as expected, yes.

} Any way to have aliases working when sourcing .zwc file?

Typically one needs "zcompile -U" to turn OFF the aliases when creating
the .zwc file.  However, no function, zcompiled or otherwise, will use
aliases that are created after the function body is parsed.

What this means is:  The aliases have to be defined in the shell that
executes the zcompile command.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiled files ignore aliases
  2016-02-05 16:37 ` Bart Schaefer
@ 2016-02-05 17:24   ` Sebastian Gniazdowski
  2016-02-05 18:43     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-05 17:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

Yes I thought about it and it's reasonable, though unsymmetrical. Zwc
changes things, there isn't full symmetry when sourcing file already
parsed or not, but see *. The "reasonable" is that parsing probably
does lookup each word in a hash table to see if there is an alias for
it. Compiling means skipping that time consuming process. So compiling
is maybe all or maybe mostly about ability of ignoring aliases. In my
project I'm being close to able to fully switch to function shadowing,
the only juggling is about compdef which isn't builtin, but that's too
handable by function shadowing (will have to wrap function by
function). Plugin architecture may be simply extended by constraint
"expect no aliases" and that's all, it's a luck that (*) plugin isn't
"a file to source", it's a software package which may have
constraints.

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiled files ignore aliases
  2016-02-05 17:24   ` Sebastian Gniazdowski
@ 2016-02-05 18:43     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-02-05 18:43 UTC (permalink / raw)
  To: Zsh hackers list

On Feb 5,  6:24pm, Sebastian Gniazdowski wrote:
}
} Yes I thought about it and it's reasonable, though unsymmetrical. Zwc
} changes things, there isn't full symmetry when sourcing file already
} parsed or not, but see *. The "reasonable" is that parsing probably
} does lookup each word in a hash table to see if there is an alias for
} it. Compiling means skipping that time consuming process.

By analogy, "alias" in shell is more like "#define" in C.  Once you've
compiled, the macro expansion is already done and doesn't happen again.

You can intentionally trigger alias expansion by using "eval", which is
(in this analogy) re-compiling at run time.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-05 18:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05 15:33 Compiled files ignore aliases Sebastian Gniazdowski
2016-02-05 16:37 ` Bart Schaefer
2016-02-05 17:24   ` Sebastian Gniazdowski
2016-02-05 18:43     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).