-
Notifications
You must be signed in to change notification settings - Fork 1
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
Replacing the # symbol #5
Comments
My idea is to replace it with \ (backslash). Backslash is illegal outside string literals, so it must be good. And this proposal is similar to De Bruijn indices, which is for representing λ calculus, and λ looks similar to \. Examples using \: [1,2,3,4,5,6,7,8,9].map(\1+?); // partially apply an operator
//=> [2,3,4,5,6,7,8,9,10]
[1,2,3,4,5,6,7,8,9].reduce(\?+?); // use an operator as a function
//=> 45
['cat', 'coconut', 'carrot', 'dog', 'sun'].filter(\?.startsWith('c')); // partially apply a function/method
//=> ['cat', 'coconut', 'carrot'] Examples using @: [1,2,3,4,5,6,7,8,9].map(@1+?); // partially apply an operator
//=> [2,3,4,5,6,7,8,9,10]
[1,2,3,4,5,6,7,8,9].reduce(@?+?); // use an operator as a function
//=> 45
['cat', 'coconut', 'carrot', 'dog', 'sun'].filter(@?.startsWith('c')); // partially apply a function/method
//=> ['cat', 'coconut', 'carrot'] |
The backslash const u0061 = 'donut';
const a = 'apple';
x = \u0061; Is |
For a moment of scrolling I had a hope that What do you think of simple [1, 2, 3].map({ 1 + ? }) |
Hey!:) I think the About Combining those could work, namely using something like [1, 2, 3].map(\{ 1 + ? }) But well, that's ugly. I think that out of all of these, [1, 2, 3].map(\ 1 + ?) // => [1, 2, 3].map((x) => 1 + x)
[1, 2, 3].map(\ add(1, ?)) // => [1, 2, 3].map((x) => add(1, x))
[1, 2, 3].map(\ ?.toString()) // => [1, 2, 3].map((x) => x.toString()) Edit: I've removed the comment's precedence part since that already came up in #3, just didn't remember. |
Or a binary-only operator could be used instead as syntactic marker (like [1, 2, 3].map(^1+?) // => [1, 2, 3].map((x) => 1 + x)
[1, 2, 3].map(^add(1, ?)) // => [1, 2, 3].map((x) => add(1, x))
[1, 2, 3].map(^?.toString()) // => [1, 2, 3].map((x) => x.toString()) |
Yeah, . Regarding let a = { x }; // Object
let a = { x + ? }; // Partial expression, ≈ n => x + n
let a = {{ x: ? }}; // Partial expression, ≈ n => ({ x: n })
// therefore
[1,2,3].map({ x }); // mapping with an object, runtime error
[1,2,3].map({ x + ? }); // mapping with partial expression, ≈ [x + 1, x + 2, x + 3]
[1,2,3].map({{ x: ? }}); // mapping to an object, ≈ [ {x: 1}, {x: 2}, {x: 3} ] And with bubbling to the top of an expression, we could make some let a = { x: ? }; // Partial expression, ≈ n => ({ x: n }) . The While the syntax might not be obvious at first glance and can be puzzling in complex cases (though, imho, partial What do you think? |
I feel like the need for a lookahead is not nice - is there any other language feature which needs it? Other than that, your proposed syntax is neat, I think. const a = (() => {
const b = {
c: ?
}
})()
// Is a or b a function? One thing that I would add is that the The arguments I can think of against your proposed syntax is the need for a lookahead, which comes hand-in-hand with the garden-path problem. A good thing about it is that it only introduces one new symbol, so that the |
I agree, lookahead is a big downside. Afau, similar lookahead is done to distinguish // Block w/ a labelled loop
{
abc: while(true) break abc;
}
// inline object
{
abc: 1
} though it's not a reason to add to this syntax pile. . Regarding partial expressions w/ statements: Regarding optional markings: . And we'll probably get more insights if we try playing with the code. |
Nah, you cannot define an inline object where a statement can go. Your inline object example does not result in an object. Try writing I do find the expression-restriction a bit too quirky - again, there is no existing syntax which doesn't allow an expression to contain a statement in the mentioned sense. Since the syntax will be used for simple function definitions, practically speaking this shouldn't be a problem, but I feel like JavaScript has more than enough gotchas already. The other thing is that if one sees |
I think, it's trickier in eval mode: but indeed if a context is understood, either can be predetermined. . I now agree that Again, we need hands-on experience. |
Private fields in the Class field declarations proposal does seem to conflict with the # symbol, and it's in Stage 3. So the # should be replaced with a symbol which is one of these:
!@#$%^&*()_+-=[]{};:'",<.>/?
Pointed out by Isiah Meadows & Sebastian Cholewa.
The text was updated successfully, but these errors were encountered: