build icon indicating copy to clipboard operation
build copied to clipboard

List unpacking

Open Kojoley opened this issue 5 years ago • 3 comments

It is quite often happens that you know the size of a list and you would want to give its elements names instead of indexing them. Something like:

local name version = [ MATCH "^(\w+)-(.*)" : $(toolset) ] ;

However, that syntax is already taken by multiple assignment operation, so in example above both variables will contain the same value. Is it documented? I had no luck finding anything in documentation about it. May be there is list unpacking already too? Or may be we can repurposed the syntax for it? I grepped Boost and only found the use in some B2 tests:

>grep --include "[Jj]am[fr]*" --include "*.jam" -PR "^\s*(local\s+)?+(\w+\s+){2,}=" .
./tools/build/src/build/feature.jam:        local p fullp = $(x[1]) ;
./tools/build/test/core-language/test.jam:    local v1 v2 = d e f ;
./tools/build/test/core-language/test.jam:    local v1 v1 = d e f ;

Kojoley avatar May 29 '20 01:05 Kojoley

It sounds reasonable that we implement a real multi-assign feature as what's already there seems just broken to me. I don't know what the original Perforce Jam behavior was on this. But I don't think it matters. As we abandoned compatibility with that long ago. The semantics I would like to see is to have:

local first rest = one two three ;
ECHO >> $(first) ;
ECHO >> $(rest) ;

To be:

>> one
>> two three

grafikrobot avatar Jun 02 '20 00:06 grafikrobot

The semantics I would like to see is to have:

local first rest = one two three ;
ECHO >> $(first) ;
ECHO >> $(rest) ;

To be:

>> one
>> two three

I do not think it is a good idea, but I indeed would like to have it with a different syntax, something with Python-like first *rest = one two three ;

Kojoley avatar Jun 02 '20 16:06 Kojoley

Thank you for your contributions. Main development of B2 has moved to https://github.com/bfgroup/b2 This issue has been automatically marked as "transition" to indicate the potential for needing transition to the new B2 development project.

stale[bot] avatar May 29 '21 17:05 stale[bot]