Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to specify whether a list should use commas or spaces. #3341

Closed
calvinjuarez opened this issue Dec 7, 2018 · 7 comments
Closed

A way to specify whether a list should use commas or spaces. #3341

calvinjuarez opened this issue Dec 7, 2018 · 7 comments

Comments

@calvinjuarez
Copy link
Member

Per seanCodes/bootstrap-less-port#13 (comment)

Currently, when pulling out all arguments as a list (using ...), the list is space-separated. It'd be nice to have a function that could force using a comma or force using a specified delimiter when outputting.

If this isn't suited to core Less, I could use some help understanding the best way to do this with a plugin.

@matthew-dean
Copy link
Member

matthew-dean commented Dec 7, 2018

To clarify @calvinjuarez's post, Less will essentially change the "model" of what is considered the list based on how many members are in the list.

As in:

@breakpoints:
  small 600px,
  medium 800px,
  large 1200px;

Less considers that a list with 3 items, and each item is a list with 2 items. So, if you have an each(), you might do

each(@breakpoints, .(@set) {
  screen: extract(@set, 1);
  size: extract(@set, 2);
})

But say you change your original value to only hold one pair.

@breakpoints:
  small 600px;

In the developer's mind, only 2 sets have been deleted. But now Less treats this as a list with 2 items, not a list of 1 item, which contains a single list of 2 items. Therefore any functions / mixins etc relying on multiple pairs will now break.

I wasn't sure if this needs to be addressed in core or not, since it could just be a simple plugin.

@seven-phases-max
Copy link
Member

seven-phases-max commented Dec 7, 2018

Less will essentially change the "model" of what is considered the list based on how many members are in the list

Just to clarify - Less does not of course actually decide anything here (the behaviour is solely decided by the input code itself - not by the compiler). I.e. essentially it's just a fundamental flaw of the particular pattern ("using nested lists as maps") and not a language or compiler defect as such. Hence more classical maps like {small: 600px} are to be preferred in this case.

since it could just be a simple plugin.

Yep. In particular to comment seanCodes/bootstrap-less-port#13 (comment):

but the tree.Expression class doesn't seem to have a way to specify that the list output should be comma- or space-separated.

It should not. See less/less-docs#446
(you can learn how to work with different list types in https://github.com/seven-phases-max/less-plugin-lists code-base for example).

@matthew-dean
Copy link
Member

matthew-dean commented Dec 7, 2018

@seven-phases-max

Just to clarify - Less does not of course actually decide anything here (the behaviour is solely decided by the input code itself - not by the compiler). I.e. essentially it's just a fundamental flaw of the particular pattern ("using nested lists as maps") and not a language or compiler defect as such

That's a good perspective.

If there's nothing to change here, behaviorally, and @calvinjuarez is fine with it, I'm fine to close as a won't-change, and anything specific someone wants to do to handle this case sounds like maybe the @plugin route is indeed the way to go.

Sound good?

@calvinjuarez
Copy link
Member Author

DRs as maps is way better. Anyone coming here for maps should do that instead.

@matthew-dean
Copy link
Member

@calvinjuarez That's a good point. There's no change in "interpretation" of lists of lists. It's a well-defined structure of key/value pairs.

@seven-phases-max
Copy link
Member

DRs as maps is way better.

Just note that DR is not the only way to define a map and its has its issues if compared to other methods.

@matthew-dean
Copy link
Member

@seven-phases-max

Right, if we address #3368 to evaluate the scope before returning a value, then the difference between rulesets as maps and lists as maps may be evaluation scope & order. That is, a list has no distinct "internal scope".

Btw, unrelated, but sometimes it's easy to miss Github notifications, @seven-phases-max @calvinjuarez, if you have time to look at #3363, that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants