Git Product home page Git Product logo

zfun's People

Contributors

paltherr avatar

Watchers

 avatar

zfun's Issues

The `var` construct does nothing if the `:=` isn't preceded by a space

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 :{.

var fails to overwrite local non-scalar variables

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.