digitalmars.dip.ideas - __HERE__
- monkyyy (31/31) Jun 17 2024 most user written aliasSeq's are repetitive, yet simply nessery
- Paul Backus (4/15) Jun 18 2024 Point of comparison: in Python, this is a built-in function
- monkyyy (5/36) May 30 https://gist.github.com/crazymonkyyy/639c5284045c65c74457fdc0d182c3c4
most user written aliasSeq's are repetitive, yet simply nessery
for metaprograming
```d
alias foo=...;
alias bar=...;
alias fizz=...;
alias foobar=__HERE__;//seq!(foo,bar,fizz)
alias bar=...;
```
`__HERE__` is a special token that evaluates to an alias seq of
local symbols defined above it
---
```d
auto func1(){...}
auto func2(){...}
auto func3(){...}
static foreach(f;__HERE__){//contains func1, 2 and 3; not f
```
---
like other special tokens it evaluate to the call site
```d
template foo(alias bar=__HERE__){
alias foo=__HERE__;
}
struct foobar{
int i;
float f;
alias fizz=foo!();//i,f
bool b;
}
```
Jun 17 2024
On Monday, 17 June 2024 at 16:24:14 UTC, monkyyy wrote:most user written aliasSeq's are repetitive, yet simply nessery for metaprograming ```d alias foo=...; alias bar=...; alias fizz=...; alias foobar=__HERE__;//seq!(foo,bar,fizz) alias bar=...; ``` `__HERE__` is a special token that evaluates to an alias seq of local symbols defined above itPoint of comparison: in Python, this is a built-in function called `locals()`. https://docs.python.org/3/library/functions.html#locals
Jun 18 2024
On Monday, 17 June 2024 at 16:24:14 UTC, monkyyy wrote:
most user written aliasSeq's are repetitive, yet simply nessery
for metaprograming
```d
alias foo=...;
alias bar=...;
alias fizz=...;
alias foobar=__HERE__;//seq!(foo,bar,fizz)
alias bar=...;
```
`__HERE__` is a special token that evaluates to an alias seq of
local symbols defined above it
---
```d
auto func1(){...}
auto func2(){...}
auto func3(){...}
static foreach(f;__HERE__){//contains func1, 2 and 3; not f
```
---
like other special tokens it evaluate to the call site
```d
template foo(alias bar=__HERE__){
alias foo=__HERE__;
}
struct foobar{
int i;
float f;
alias fizz=foo!();//i,f
bool b;
}
```
https://gist.github.com/crazymonkyyy/639c5284045c65c74457fdc0d182c3c4
found this pattern today, I suggest someone gets in into
std.traits,
special tokens have allot of magic, but this works today.
May 30









Paul Backus <snarwin gmail.com> 