paltherr / zfun Goto Github PK
View Code? Open in Web Editor NEWEnhanced function support for zsh
License: MIT License
Enhanced function support for zsh
License: MIT License
The var
construct doesn't work if the variable is already locally declared as a non-scalar value.
File zfun-bug.zsh
:
#!/bin/zsh
. zfun.zsh;
v=x
fun f:s :{ r:set y; };
var v:= f;
echo "v=$v"
Command:
zfun-bug.zsh
Expected result:
Some error message
Actual result:
v=x
The root is that the global alias :=
isn't recognized and expended when it's not preceded by a space. The function var
should be defined in such a way that it fails if there is no :=
, similar to what fun
does if there is no :{
.
The var
construct doesn't work if the variable is already locally declared as a non-scalar value.
File zfun-bug.zsh
:
#!/bin/zsh
. zfun.zsh;
fun foo:a :{
r:set a b c;
}
global_scalar="x y z";
global_array=( x y z );
function outer() {
local enclosing_scalar="x y z";
local -a enclosing_scalar=( x y z )
inner;
}
function inner() {
local local_scalar="x y z";
local -a local_array=( x y z );
var undeclared := foo;
echo ${(q+)undeclared};
var global_scalar := foo;
echo ${(q+)global_scalar};
var global_array := foo;
echo ${(q+)global_array};
var enclosing_scalar := foo;
echo ${(q+)enclosing_scalar};
var enclosing_array := foo;
echo ${(q+)enclosing_array};
var local_scalar := foo;
echo ${(q+)local_scalar};
var local_array := foo;
echo ${(q+)local_array};
}
outer;
Command:
zfun-bug.zsh
Expected result:
a b c
a b c
a b c
a b c
a b c
a b c
a b c
Actual result:
a b c
a b c
a b c
a b c
a b c
a b c
inner:local:22: local_array: inconsistent type for assignment
The root cause is that :=
expands to local VAR=
, which only works for scalar or locally undeclared variables. For non-scalar local variables local VAR=()
should be used instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.