digitalmars.dip.ideas - allow unaccessable default arguments
- monkyyy (5/5) Jun 18 `void foo(Args...)(Args args,int line=__LINE__)`
- Nick Treleaven (10/13) Jun 21 The above works because once instantiated, it's a non-variadic
- monkyyy (11/20) Jun 21 Im suggesting its just made greedy, allowing special tokens to do
- Nick Treleaven (3/7) Jun 25 I don't know what verbose syntax you mean. A sequence
- monkyyy (23/30) Jun 25 nested templates are always possible but the syntax rapidly
- Nick Treleaven (16/42) Jun 27 OK. There is another option if we're considering API changes:
- monkyyy (18/62) Jun 27 the builder pattern works rn, I think Id want foo!(...)!(...) to
`void foo(Args...)(Args args,int line=__LINE__)` `template foo(T...,int line=__LINE__)` `void foo(T)(T[] array...,T magic=Bar!T)` While I have work arounds, it would be better just to let this happen; special tokens and dual context magic happens in headers.
Jun 18
On Wednesday, 18 June 2025 at 19:11:36 UTC, monkyyy wrote:`void foo(Args...)(Args args,int line=__LINE__)`The above works because once instantiated, it's a non-variadic function.`template foo(T...,int line=__LINE__)`Could be made to work, but then, what if there's a constraint on T that forbids int value elements (e.g. `if (is(T))`)? People might then expect that when the last instantiation argument is an int, it matches `line`.`void foo(T)(T[] array...,T magic=Bar!T)`Again, that specific case seems OK, but what about when `magic` is not compatible with T? People might expect they can pass a `magic` argument in that case.
Jun 21
On Saturday, 21 June 2025 at 10:28:27 UTC, Nick Treleaven wrote:Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a `T...` before other arguments to a template you could always nest them with terrible verbose syntax. But I think you should probably reach for that awful "builder" pattern first; special tokens on the other hand would become stylistic land mines in a builder pattern`template foo(T...,int line=__LINE__)`Could be made to work, but then, what if there's a constraint on T that forbids int value elements (e.g. `if (is(T))`)? People might then expect that when the last instantiation argument is an int, it matches `line`.Im giving a hard case; I dont know other people using this sort of pattern of templated default arguments it can be quite tricky to get right`void foo(T)(T[] array...,T magic=Bar!T)`Again, that specific case seems OK, but what about when `magic` is not compatible with T? People might expect they can pass a `magic` argument in that case.
Jun 21
On Saturday, 21 June 2025 at 15:57:45 UTC, monkyyy wrote:Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a `T...` before other arguments to a template you could always nest them with terrible verbose syntax.I don't know what verbose syntax you mean. A sequence automatically expands.
Jun 25
On Wednesday, 25 June 2025 at 11:44:01 UTC, Nick Treleaven wrote:On Saturday, 21 June 2025 at 15:57:45 UTC, monkyyy wrote:nested templates are always possible but the syntax rapidly breaks down into something quite hard to read and unclear for users how to call ```d alias seq(T...)=T; template pair(alias T,alias S){alias _1=T; alias _2=S;} template foo(T...){ template foo(S...){ alias foo=seq!(); static foreach(I;0..T.length<S.length?T.length:S.length){ foo=seq!(foo,pair!(T[I],S[I])); }}} unittest{ alias _=foo!(int,bool,float); alias bar=_!(1,2); import std; bar.stringof.writeln; } ``` If you tried to do the same with special tokens, how the user sets up the call site would effect `__LINE__` is it offset by 1? did they manage to inline it entirely?Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a `T...` before other arguments to a template you could always nest them with terrible verbose syntax.I don't know what verbose syntax you mean. A sequence automatically expands.
Jun 25
On Wednesday, 25 June 2025 at 17:09:26 UTC, monkyyy wrote:On Wednesday, 25 June 2025 at 11:44:01 UTC, Nick Treleaven wrote:OK. There is another option if we're considering API changes: ```d template Pack(T...) { alias Expand = T; } template MyTemplate(alias pack, int line=__LINE__) { ... } ``` Then use `MyTemplate!(Pack!(my, args))`. Inside `MyTemplate` the `pack` parameter has to use the `Expand` member to access the sequence.I don't know what verbose syntax you mean. A sequence automatically expands.nested templates are always possible but the syntax rapidly breaks down into something quite hard to read and unclear for users how to call```d alias seq(T...)=T; template pair(alias T,alias S){alias _1=T; alias _2=S;} template foo(T...){ template foo(S...){ alias foo=seq!(); static foreach(I;0..T.length<S.length?T.length:S.length){ foo=seq!(foo,pair!(T[I],S[I])); }}} unittest{ alias _=foo!(int,bool,float); alias bar=_!(1,2); import std; bar.stringof.writeln; } ``` If you tried to do the same with special tokens, how the user sets up the call site would effect `__LINE__` is it offset by 1? did they manage to inline it entirely?Incidentally, I've never understood why `(foo!(int,bool,float))!(1,2)` isn't supported. Then we could remove: https://dlang.org/phobos/std_meta.html#Instantiate
Jun 27
On Friday, 27 June 2025 at 11:38:29 UTC, Nick Treleaven wrote:On Wednesday, 25 June 2025 at 17:09:26 UTC, monkyyy wrote:the builder pattern works rn, I think Id want foo!(...)!(...) to work to be better api, lisp ()'s that way lies ```d alias seq(T...)=T; template pair(alias T,alias S){alias _1=T; alias _2=S;} template foo(T...){ template sndlist(S...){ alias foo=seq!(); static foreach(I;0..T.length<S.length?T.length:S.length){ foo=seq!(foo,pair!(T[I],S[I])); }}} unittest{ alias bar=foo!(int,bool,float).sndlist!(1,2); import std; bar.stringof.writeln; } ```On Wednesday, 25 June 2025 at 11:44:01 UTC, Nick Treleaven wrote:OK. There is another option if we're considering API changes: ```d template Pack(T...) { alias Expand = T; } template MyTemplate(alias pack, int line=__LINE__) { ... } ``` Then use `MyTemplate!(Pack!(my, args))`. Inside `MyTemplate` the `pack` parameter has to use the `Expand` member to access the sequence.I don't know what verbose syntax you mean. A sequence automatically expands.nested templates are always possible but the syntax rapidly breaks down into something quite hard to read and unclear for users how to call```d alias seq(T...)=T; template pair(alias T,alias S){alias _1=T; alias _2=S;} template foo(T...){ template foo(S...){ alias foo=seq!(); static foreach(I;0..T.length<S.length?T.length:S.length){ foo=seq!(foo,pair!(T[I],S[I])); }}} unittest{ alias _=foo!(int,bool,float); alias bar=_!(1,2); import std; bar.stringof.writeln; } ``` If you tried to do the same with special tokens, how the user sets up the call site would effect `__LINE__` is it offset by 1? did they manage to inline it entirely?Incidentally, I've never understood why `(foo!(int,bool,float))!(1,2)` isn't supported. Then we could remove: https://dlang.org/phobos/std_meta.html#Instantiate
Jun 27