Comments (1)
I wrote merged parse_pair() into struct_set, and also added is_struct. I was wondering if is_struct should check that there are no duplicated keywords, which might make it slow.
// Function: struct_set()
// Usage:
// struct_set(struct, keyword, value, [grow])
// struct_set(struct, [keyword1, value1, keyword2, value2, ...], [grow])
// Description:
// Sets the keyword(s) in the structure to the specified value(s), returning a new updated structure. If a keyword
// exists its value is changed, otherwise the keyword is added to the structure. If grow is set to false then
// it is an error to set a keyword not already defined in the structure. If you specify the same keyword twice
// that is also an error. If speed matters, use the first form with scalars rather than the list form: this is
// about thirty times faster.
// Arguments:
// struct = input structure
// keyword = keyword to set
// value = value to set the keyword to
// grow = Set to true to allow structure to grow, or false for new keywords to generate an error. Default: true
function struct_set(struct, keyword, value=undef, grow=true) =
let(aa=echo(struct=struct, keyword=keyword, value=value, grow=grow))
!is_list(keyword) ?
let(ind=search([keyword],struct,1,0)[0])
(ind==[] ? assert(grow,str("Unknown keyword \"",keyword))
concat(struct, [[keyword,value]]) :
list_set([ind], [[keyword,value]],struct)) :
_parse_pairs(struct,keyword,grow);
function _parse_pairs(spec, input, grow=true, index=0, result=undef) =
assert(len(input)%2==0,"Odd number of entries in [keyword,value] pair list")
let( result = result==undef ? spec : result)
index == len(input) ? result : let(dd=echo(dd=spec, input, grow,index, result))
_parse_pairs(spec,input,grow,index+2,struct_set(result, input[index], input[index+1],grow));
// Function is_struct()
// Usage:
// is_struct(struct)
// Description: Returns true if the input has the form of a structure, false otherwise.
function is_struct(struct, ind=0) =
struct == [] ||
let(dim = array_dim(struct))
len(dim)==2 && dim[1]==2;
from bosl2.
Related Issues (20)
- Add hex_panel to the BOSL2 library HOT 12
- [BUG] offset_sweep() fails when passed a region HOT 4
- [BUG] path_sweep() weird anchors HOT 25
- end rounding/chamfer for path_sweep() and path_sweep2d() HOT 18
- [BUG] path_merge_collinear(path, closed = true) will not remove a collinear point if it is the first point in a path HOT 2
- Expose unique $idx for each child created by grid_copies() HOT 7
- Feature Request : 2D version of bounding_box() HOT 9
- [BUG] offset_stroke() "round" ending gives pointed ending. HOT 7
- Expose Anchors when using Attachable() HOT 8
- [BUG] nvm fixed after redownloading HOT 1
- Partition Feature Request - Anchor Based Partitioning HOT 5
- [BUG] Inconsistent result when using _root_radius: Too small in some cases. HOT 2
- Partial Texturing of Objects HOT 2
- [BUG] BOSL2 Version Not Incrementing HOT 2
- [BUG] path_sweep() with non uniform path breaks with twist HOT 6
- generic_bottle_cap module fails with variable "thread_od" not specified. HOT 6
- deduplicate does not remove a repeated start and end point HOT 1
- [BUG] partition_cut_mask says it has a width parameter but it doesn't
- Sparse shapes beyond wall HOT 10
- Add a preview_only argument to ruler() ? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bosl2.