[elixir-core:10720] Re: Can I add the Dekatrian Calendar?

2022-01-21 Thread Kip
That's quite a simple calendar (other than Acrônian and Synchronion) so I 
suggest look at the Calendar behaviour 
 and then the very simple 
holocene 
calendar 

 that 
is used in Elixir tests.  I've built quite a few Elixir calendars to happy 
to help.

On Monday, January 10, 2022 at 10:40:17 AM UTC+8 phellp...@gmail.com wrote:

> I want to add implements the Dekatrian calendar 
>  for 
> elixir, I want to know if I can do it and how is the steps to do this.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/97d54152-375a-483e-9ef2-210d152d5eeen%40googlegroups.com.


Re: [elixir-core:10718] [Proposal] Embedded Elixir Expressions in Formatter Plugins

2022-01-21 Thread Jonatan Männchen
I’ll work on a PR and will let you know if I have any questions.

Thanks 😊


On Fri, 21 Jan 2022 at 22:44, José Valim  wrote:

> One option is to process the sigils formatter option early, so we pass
> this option to the Surface formatter (which can then pass it to
> format_to_string). In a nutshell, move this code
> 
> to some place earlier in the stack. A PR is welcome! Feel free to ping if
> you have any questions!
>
> On Fri, Jan 21, 2022 at 10:20 PM Jonatan Männchen 
> wrote:
>
>> Hi All,
>>
>> I would like to propose the ability to format embedded elixir expressions
>> inside of files / sigils being formatted by a formatter plugin.
>>
>> *Situation at the Moment*
>>
>> Formatter Plugins that format files which contain elixir expressions
>> inside do not currently have a way to call the formatter again on the
>> nested expression.
>>
>> *Example Usage*
>>
>> When using both surface 
>> and cldr_messages , one
>> could write a file like this:
>>
>>  {gettext(~M"It's my cat's {year, selectordinal, one {#st} two {#nd}
>> few {#rd} other {#th}} birthday!")} 
>>
>> The HTML should be formatted by the surface formatter, the M sigil by the
>> cldr messages formatter.
>> Since the surface formatter is currently using Code.format_string!/2, the
>> cldr formatter is not applied. Reported to surface formatter as a bug here:
>> https://github.com/surface-ui/surface_formatter/issues/60
>>
>> I expect to see similar questions in formatter plugins like
>> heex_formatter .
>>
>> *Possible Solution*
>>
>> It would be nice if there was an API, that would allow passing embedded
>> elixir expressions back into the formatter.
>>
>> One way to achieve that, would be to pass a function
>> to Mix.Tasks.Format.format/2 into opts.
>>
>> Thanks,
>> Jony
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to elixir-lang-core+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/elixir-lang-core/5b6b6721-c16e-480f-be95-8ef1a46dbb50n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "elixir-lang-core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elixir-lang-core/jFswzSUjsP4/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BQ7VwMr0%2BE2eVcFMpmbsaA3Vr5Ue3OOZbrEJErmRW_UA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CACupubMBqQ%3Djz6g2SMoNJhvKcaKJ_iML1XVnFZ4TpaPsYg_6jg%40mail.gmail.com.


Re: [elixir-core:10717] [Proposal] Embedded Elixir Expressions in Formatter Plugins

2022-01-21 Thread José Valim
One option is to process the sigils formatter option early, so we pass this
option to the Surface formatter (which can then pass it to
format_to_string). In a nutshell, move this code

to some place earlier in the stack. A PR is welcome! Feel free to ping if
you have any questions!

On Fri, Jan 21, 2022 at 10:20 PM Jonatan Männchen 
wrote:

> Hi All,
>
> I would like to propose the ability to format embedded elixir expressions
> inside of files / sigils being formatted by a formatter plugin.
>
> *Situation at the Moment*
>
> Formatter Plugins that format files which contain elixir expressions
> inside do not currently have a way to call the formatter again on the
> nested expression.
>
> *Example Usage*
>
> When using both surface 
> and cldr_messages , one
> could write a file like this:
>
>  {gettext(~M"It's my cat's {year, selectordinal, one {#st} two {#nd}
> few {#rd} other {#th}} birthday!")} 
>
> The HTML should be formatted by the surface formatter, the M sigil by the
> cldr messages formatter.
> Since the surface formatter is currently using Code.format_string!/2, the
> cldr formatter is not applied. Reported to surface formatter as a bug here:
> https://github.com/surface-ui/surface_formatter/issues/60
>
> I expect to see similar questions in formatter plugins like heex_formatter
> .
>
> *Possible Solution*
>
> It would be nice if there was an API, that would allow passing embedded
> elixir expressions back into the formatter.
>
> One way to achieve that, would be to pass a function
> to Mix.Tasks.Format.format/2 into opts.
>
> Thanks,
> Jony
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/5b6b6721-c16e-480f-be95-8ef1a46dbb50n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BQ7VwMr0%2BE2eVcFMpmbsaA3Vr5Ue3OOZbrEJErmRW_UA%40mail.gmail.com.


[elixir-core:10717] [Proposal] Embedded Elixir Expressions in Formatter Plugins

2022-01-21 Thread Jonatan Männchen
Hi All,

I would like to propose the ability to format embedded elixir expressions 
inside of files / sigils being formatted by a formatter plugin.

*Situation at the Moment*

Formatter Plugins that format files which contain elixir expressions inside 
do not currently have a way to call the formatter again on the nested 
expression.

*Example Usage*

When using both surface  
and cldr_messages , one could 
write a file like this:

 {gettext(~M"It's my cat's {year, selectordinal, one {#st} two {#nd} 
few {#rd} other {#th}} birthday!")} 

The HTML should be formatted by the surface formatter, the M sigil by the 
cldr messages formatter.
Since the surface formatter is currently using Code.format_string!/2, the 
cldr formatter is not applied. Reported to surface formatter as a bug here: 
https://github.com/surface-ui/surface_formatter/issues/60

I expect to see similar questions in formatter plugins like heex_formatter 
.

*Possible Solution*

It would be nice if there was an API, that would allow passing embedded 
elixir expressions back into the formatter.

One way to achieve that, would be to pass a function 
to Mix.Tasks.Format.format/2 into opts.

Thanks,
Jony

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/5b6b6721-c16e-480f-be95-8ef1a46dbb50n%40googlegroups.com.


Re: [elixir-core:10716] [Proposal] Add a shortcut to access a struct within the module where it is defined

2022-01-21 Thread Ben Wilson
__MODULE__ is the right answer here IMHO. It is consistent with the other 
"meta constants" like __ENV__, __DIR__ __FILE__ and so on in that they 
desugar to constants, but are file / code relative. It isn't a super common 
pattern, but last time I checked generated phoenix code does a 
%__MODULE__{} pattern match check on the changeset functions.

On Friday, January 21, 2022 at 6:56:42 AM UTC-5 ins...@gmail.com wrote:

> Thanks for the tip Wojtek
> Aliasing __MODULE__ should work in my case
>
> As far as I understand this pattern isn't used too often(at least projects 
> like Plug or Ecto don't use it), so I guess it is not really considered as 
> idiomatic 
>
> I just feel that if you are inside a module there should be a shortcut 
> built-in in the language(like when you call other functions from the module 
> you don't specify the full path) but it might be just old instincts from 
> other languages
>
> пʼятниця, 21 січня 2022 р. о 10:58:56 UTC Wojtek Mach пише:
>
>> Neither `%_{}` nor `%self{}` can be supported because they already have a 
>> meaning in pattern matches. The former means _any_ struct and the latter 
>> binds the matched struct name to the variable `self`.
>>
>> You can give `__MODULE__` another name with an alias:
>>
>> alias __MODULE__, as: Struct
>>
>> def connect(%Struct{} = channel)
>>
>>
>> On January 21, 2022, "gmail.com"  wrote:
>>
>> It is common to define a struct together with various functions that 
>> access that struct in the module:
>>
>> defmodule Chat.Channel do
>>   defstruct name: "", public?: true
>> 
>>   def new do
>> %Chat.Channel{name: "Untitled"}
>>   end
>>
>>   def connect(%Chat.Channel{} = channel) do
>> IO.inspect(channel)
>>   end
>> end
>>
>> It is also common to alias the struct for easier access
>>
>> defmodule Chat.Channel do
>>   defstruct name: "", public?: true
>> 
>>   alias Chat.Channel
>>   
>>   # ...
>> end
>>
>> But, say, renaming the module would require manually replacing all struct 
>> occurrences with the new module name. Aliasing can help, but if the last 
>> bit should be updated too(say Chat.Channel should be updated to Chat.Room) 
>> it would still require to manually replace everything.
>>
>> There is a workaround to use __MODULE__, but IMO the code looks a bit ugly
>>
>> defmodule Chat.Channel do
>>   defstruct name: "", public?: true
>> 
>>   def new do
>> %__MODEUL__{name: "Untitled"}
>>   end
>> 
>>   def connect(%__MODEUL__{} = channel) do
>> IO.inspect(channel)
>>   end
>> end
>>
>> I think It would be great to have some kind of shortcut(syntactic sugar) 
>> to access the struct within the module.
>> First I thought about something like %_(%%, %. etc) but this way it looks 
>> a bit cryptic 
>>
>> def connect(%_{} = channel) do
>>
>> So maybe something like %self would work
>>
>> defmodule Chat.Channel do
>>   defstruct name: "", public?: true
>> 
>>   def new do
>> %self{name: "Untitled"}
>>   end
>> 
>>   def connect(%self{} = channel) do
>> IO.inspect(channel)
>>   end
>> end
>>
>> What do you think?
>>
>>  -- 
>>  You received this message because you are subscribed to the Google 
>> Groups "elixir-lang-core" group.
>>  To unsubscribe from this group and stop receiving emails from it, send 
>> an email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/da49bf41-d4ad-4fc7-a88c-1338e7a463c1n%40googlegroups.com
>>  
>> 
>> .
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/b473f840-3e6e-43d5-b71b-280bb02b55f4n%40googlegroups.com.


Re: [elixir-core:10715] [Proposal] add colored output to 'did you mean' suggestions

2022-01-21 Thread Daniel Kukuła
I used this for the example if someone want's to play with it:

defmodule Colorize do
  def compare() do
"""
IO.inspect-IO.innspect
IO.inspect-IO.ispect
IO.inspect-IO.imspect
IO.inspect-IO.inspcet
"""
|> String.split("\n", trim: true)
|> Enum.each(fn x ->
  [l, r] = String.split(x, "-")
  compare(l, r)
end)
  end

  def compare(expected, expected), do: expected

  def compare(expected, rendered) do
{%ExUnit.Diff{left: {_, _, left}, right: {_, _, right}}, _} =
  ExUnit.Diff.compute(expected, rendered, :==)

IO.puts(["did you mean: ", colorize(left, right)])
  end

  defp colorize([{_, _, added}, r1], [{_, _, deleted}, r2]) do
[added(added), deleted(deleted), colorize(r1, r2)]
  end

  defp colorize([], []), do: []
  defp colorize([{_, _, added} | r1], r2), do: [added(added), colorize(r1, 
r2)]
  defp colorize(r1, [{_, _, deleted} | r2]), do: [deleted(deleted), 
colorize(r1, r2)]
  defp colorize([{_, _, added}], []), do: added(added)
  defp colorize([], [{_, _, deleted}]), do: deleted(deleted)
  defp colorize([h | r1], [h | r2]), do: [h, colorize(r1, r2)]

  defp added(text), do: IO.ANSI.format([:green_background, text])
  defp deleted(text), do: IO.ANSI.format([:red_background, text])
end


On Friday, January 21, 2022 at 6:26:09 PM UTC Daniel Kukuła wrote:

> I think it can be done on the suggestion only - showing different colors 
> like here - second example is currently selected but you can see it with 
> the same background
>
> On Friday, January 21, 2022 at 11:08:14 AM UTC José Valim wrote:
>
>> I would love to see how a prototype of this would work. One difficulty to 
>> keep in mind is that, for a diff to work, you need to show both options 
>> side by side. And I am not sure if repeating what you typed wrong will be 
>> helpful. But someone has to play with those ideas before we are sure. :)
>>
>> On Wed, Jan 19, 2022 at 7:05 PM Daniel Kukuła  wrote:
>>
>>> ExUnit has this nice feature that it's showing the differences between 
>>> the expectation and result in different colors. It would be nice to have 
>>> something similar with the `did you mean suggestions`.
>>> Rationale:
>>> It's not the first time that when I made a typo and the compiler suggest 
>>> the right function/module I'm struggling to see the difference between my 
>>> code and the suggestions. With short strings it's easy but I got deeply 
>>> nested modules and sometimes it takes some time to spot the typo.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to elixir-lang-co...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/elixir-lang-core/5751b69a-1364-4419-8d8a-273252c9755an%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/67614abe-ab76-4a18-a9ab-30c20b4740b1n%40googlegroups.com.


Re: [elixir-core:10714] [Proposal] add colored output to 'did you mean' suggestions

2022-01-21 Thread Daniel Kukuła
I think it can be done on the suggestion only - showing different colors 
like here - second example is currently selected but you can see it with 
the same background

On Friday, January 21, 2022 at 11:08:14 AM UTC José Valim wrote:

> I would love to see how a prototype of this would work. One difficulty to 
> keep in mind is that, for a diff to work, you need to show both options 
> side by side. And I am not sure if repeating what you typed wrong will be 
> helpful. But someone has to play with those ideas before we are sure. :)
>
> On Wed, Jan 19, 2022 at 7:05 PM Daniel Kukuła  wrote:
>
>> ExUnit has this nice feature that it's showing the differences between 
>> the expectation and result in different colors. It would be nice to have 
>> something similar with the `did you mean suggestions`.
>> Rationale:
>> It's not the first time that when I made a typo and the compiler suggest 
>> the right function/module I'm struggling to see the difference between my 
>> code and the suggestions. With short strings it's easy but I got deeply 
>> nested modules and sometimes it takes some time to spot the typo.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/5751b69a-1364-4419-8d8a-273252c9755an%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/57ccd8b3-7162-4888-aabe-fddf80027156n%40googlegroups.com.


Re: [elixir-core:10713] [Proposal] Add a shortcut to access a struct within the module where it is defined

2022-01-21 Thread Tim Masliuchenko
Thanks for the tip Wojtek
Aliasing __MODULE__ should work in my case

As far as I understand this pattern isn't used too often(at least projects 
like Plug or Ecto don't use it), so I guess it is not really considered as 
idiomatic 

I just feel that if you are inside a module there should be a shortcut 
built-in in the language(like when you call other functions from the module 
you don't specify the full path) but it might be just old instincts from 
other languages

пʼятниця, 21 січня 2022 р. о 10:58:56 UTC Wojtek Mach пише:

> Neither `%_{}` nor `%self{}` can be supported because they already have a 
> meaning in pattern matches. The former means _any_ struct and the latter 
> binds the matched struct name to the variable `self`.
>
> You can give `__MODULE__` another name with an alias:
>
> alias __MODULE__, as: Struct
>
> def connect(%Struct{} = channel)
>
>
> On January 21, 2022, "gmail.com"  wrote:
>
> It is common to define a struct together with various functions that 
> access that struct in the module:
>
> defmodule Chat.Channel do
>   defstruct name: "", public?: true
> 
>   def new do
> %Chat.Channel{name: "Untitled"}
>   end
>
>   def connect(%Chat.Channel{} = channel) do
> IO.inspect(channel)
>   end
> end
>
> It is also common to alias the struct for easier access
>
> defmodule Chat.Channel do
>   defstruct name: "", public?: true
> 
>   alias Chat.Channel
>   
>   # ...
> end
>
> But, say, renaming the module would require manually replacing all struct 
> occurrences with the new module name. Aliasing can help, but if the last 
> bit should be updated too(say Chat.Channel should be updated to Chat.Room) 
> it would still require to manually replace everything.
>
> There is a workaround to use __MODULE__, but IMO the code looks a bit ugly
>
> defmodule Chat.Channel do
>   defstruct name: "", public?: true
> 
>   def new do
> %__MODEUL__{name: "Untitled"}
>   end
> 
>   def connect(%__MODEUL__{} = channel) do
> IO.inspect(channel)
>   end
> end
>
> I think It would be great to have some kind of shortcut(syntactic sugar) 
> to access the struct within the module.
> First I thought about something like %_(%%, %. etc) but this way it looks 
> a bit cryptic 
>
> def connect(%_{} = channel) do
>
> So maybe something like %self would work
>
> defmodule Chat.Channel do
>   defstruct name: "", public?: true
> 
>   def new do
> %self{name: "Untitled"}
>   end
> 
>   def connect(%self{} = channel) do
> IO.inspect(channel)
>   end
> end
>
> What do you think?
>
>  -- 
>  You received this message because you are subscribed to the Google Groups 
> "elixir-lang-core" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to elixir-lang-co...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/da49bf41-d4ad-4fc7-a88c-1338e7a463c1n%40googlegroups.com
>  
> 
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/ba1d2529-78e1-4604-9df3-689b0f362560n%40googlegroups.com.


Re: [elixir-core:10711] [Proposal] add colored output to 'did you mean' suggestions

2022-01-21 Thread José Valim
I would love to see how a prototype of this would work. One difficulty to
keep in mind is that, for a diff to work, you need to show both options
side by side. And I am not sure if repeating what you typed wrong will be
helpful. But someone has to play with those ideas before we are sure. :)

On Wed, Jan 19, 2022 at 7:05 PM Daniel Kukuła  wrote:

> ExUnit has this nice feature that it's showing the differences between the
> expectation and result in different colors. It would be nice to have
> something similar with the `did you mean suggestions`.
> Rationale:
> It's not the first time that when I made a typo and the compiler suggest
> the right function/module I'm struggling to see the difference between my
> code and the suggestions. With short strings it's easy but I got deeply
> nested modules and sometimes it takes some time to spot the typo.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/5751b69a-1364-4419-8d8a-273252c9755an%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KZsCqESUVo%3DJKxQiMeQOKNnsT6XY%3DH_9fDXtSJKEf%2BPw%40mail.gmail.com.


Re: [elixir-core:10710] [Proposal] Add a shortcut to access a struct within the module where it is defined

2022-01-21 Thread Wojtek Mach
Neither `%_{}` nor `%self{}` can be supported because they already have
a meaning in pattern matches. The former means _any_ struct and the
latter binds the matched struct name to the variable `self`.

You can give `__MODULE__` another name with an alias:

alias __MODULE__, as: Struct def connect(%Struct{} = channel)

On January 21, 2022, "gmail.com"  wrote:
> It is common to define a struct together with various functions that
> access that struct in the module:
>
>     defmodule Chat.Channel do
>       defstruct name: "", public?: true
>    
>       def new do
>         %Chat.Channel{name: "Untitled"}
>       end
>
>       def connect(%Chat.Channel{} = channel) do
>         IO.inspect(channel)
>       end
>     end
>
> It is also common to alias the struct for easier access
>
>     defmodule Chat.Channel do
>       defstruct name: "", public?: true
>    
>       alias Chat.Channel
>      
>       # ...
>     end
>
> But, say, renaming the module would require manually replacing all
> struct occurrences with the new module name. Aliasing can help, but if
> the last bit should be updated too(say Chat.Channel should be updated
> to Chat.Room) it would still require to manually replace everything.
>
> There is a workaround to use __MODULE__, but IMO the code looks a bit
> ugly
>
>     defmodule Chat.Channel do
>       defstruct name: "", public?: true
>    
>       def new do
>         %__MODEUL__{name: "Untitled"}
>       end
>    
>       def connect(%__MODEUL__{} = channel) do
>         IO.inspect(channel)
>       end
>     end
>
> I think It would be great to have some kind of shortcut(syntactic
> sugar) to access the struct within the module.
> First I thought about something like %_(%%, %. etc) but this way it
> looks a bit cryptic
>
>     def connect(%_{} = channel) do
>
> So maybe something like %self would work
>
>     defmodule Chat.Channel do
>       defstruct name: "", public?: true
>    
>       def new do
>         %self{name: "Untitled"}
>       end
>    
>       def connect(%self{} = channel) do
>         IO.inspect(channel)
>       end
>     end
>
> What do you think?
>  --
>  You received this message because you are subscribed to the Google
> Groups "elixir-lang-core" group.
>  To unsubscribe from this group and stop receiving emails from it,
> send an email to elixir-lang-core+unsubscr...@googlegroups.com
> .
>  To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/da49bf41-d4ad-4fc7-
> a88c-1338e7a463c1n%40googlegroups.com
>  4fc7-a88c-
> 1338e7a463c1n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/38c71ced95b2fe910b644fda40da8cb645914f3f%40hey.com.


[elixir-core:10710] [Proposal] Add a shortcut to access a struct within the module where it is defined

2022-01-21 Thread Tim Masliuchenko
It is common to define a struct together with various functions that access 
that struct in the module:

defmodule Chat.Channel do
  defstruct name: "", public?: true

  def new do
%Chat.Channel{name: "Untitled"}
  end

  def connect(%Chat.Channel{} = channel) do
IO.inspect(channel)
  end
end

It is also common to alias the struct for easier access

defmodule Chat.Channel do
  defstruct name: "", public?: true

  alias Chat.Channel
  
  # ...
end

But, say, renaming the module would require manually replacing all struct 
occurrences with the new module name. Aliasing can help, but if the last 
bit should be updated too(say Chat.Channel should be updated to Chat.Room) 
it would still require to manually replace everything.

There is a workaround to use __MODULE__, but IMO the code looks a bit ugly

defmodule Chat.Channel do
  defstruct name: "", public?: true

  def new do
%__MODEUL__{name: "Untitled"}
  end

  def connect(%__MODEUL__{} = channel) do
IO.inspect(channel)
  end
end

I think It would be great to have some kind of shortcut(syntactic sugar) to 
access the struct within the module.
First I thought about something like %_(%%, %. etc) but this way it looks a 
bit cryptic 

def connect(%_{} = channel) do

So maybe something like %self would work

defmodule Chat.Channel do
  defstruct name: "", public?: true

  def new do
%self{name: "Untitled"}
  end

  def connect(%self{} = channel) do
IO.inspect(channel)
  end
end

What do you think?

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/da49bf41-d4ad-4fc7-a88c-1338e7a463c1n%40googlegroups.com.


Re: [elixir-core:10708] Mix: Allow project specific mix tasks to be called in a project subdirectory

2022-01-21 Thread Jon Rowe
Not a direct response to your proposal, but a handy rubber duck tip, in the 
case of `npm install` you can use the `--prefix` option to avoid changing 
directory from project root, even with umbrella apps I don't find myself 
leaving the project root directory in my nvim / shell / server terminal setup.

Cheers
Jon

On Fri, 21 Jan 2022, at 6:32 AM, Benjamin Philip wrote:
> Hi,
> 
> As of Elixir 1.13, project specific mix tasks such as `mix test`, can only be 
> called from project root.
> 
> This is okay when I have to run `npm install` in the `assets` directory in a 
> phoenix project,  but has the side effect of making repetitive tasks/commands 
> in a subdirectory quite tedious (because I have to cd a lot), especially if I 
> have to run a mix task after running the command.
> 
> Naturally, I have 2 shell sessions while developing - one for running mix 
> tasks, and the other for actual development - editing files, running commands 
> etc. Switching between the two sessions can mean using a quick keystroke at 
> best, or removing my hands from keyboard and using the mouse at worst. This 
> can quickly become irritating if I have to switch sessions often and I don't 
> know the keystroke for my terminal.
> 
> The rake  build tool on the other hand, allows 
> for calling rake in a project subdirectory by changing rake's working 
> directory to project root using this function 
> .
>  Rake then runs the required task.
> 
> This would not be possible for example make, where the buildlogic (Makefiles) 
> are found in directories with project source code.
> 
> However, rake has all build logic in a Rakefile, or in the `rakelib` 
> directory. Similarly, mix has all tasks in `lib/mix/tasks/`. Thus, I feel 
> allowing mix to be called in project subdirs, will not have any problems.
> 
> I propose that mix allows project specific mix tasks to be called in a 
> project subdirectory.
> 
> Regards,
> Benjamin Philip
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/71e3417b-ae1c-48e3-92f3-524d232f88d0n%40googlegroups.com
>  
> .

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/095e5609-7279-43f2-bf59-30e3777583db%40www.fastmail.com.