29 Dec 2023 |
dionisos | Also I am curious about the "(test::MyType)" syntax | 00:05:41 |
qwjyh | Do you want to generate a function based on a type automatically? If normal multiple dispatch doesn't meet your need, you should use macro. | 00:06:12 |
dionisos | * Ok I found how to do that, it should be :
function create_function(MyType)
function test(a::MyType, b::MyType) where MyType
return a+b
end
return test
end
But I admit I don’t really understand why.
| 00:07:15 |
dionisos | In reply to @qwjyh:matrix.org Do you want to generate a function based on a type automatically? If normal multiple dispatch doesn't meet your need, you should use macro. Yes this is what I want | 00:09:11 |
dionisos | Oh, I just realized the "where MyType", just make MyType a variable | 00:10:03 |
qwjyh | Simple example for the syntax:
```
julia> struct MyType
v::Int64
end
julia> function (t::MyType)(a::T, b::T) where {T <: Integer}
a + b + t.v
end
julia> x = MyType(1)
MyType(1)
julia> x(1, 2)
4
``` | 00:10:04 |
dionisos | In reply to @qwjyh:matrix.org Simple example for the syntax: ``` julia> struct MyType v::Int64 end
julia> function (t::MyType)(a::T, b::T) where {T <: Integer} a + b + t.v end
julia> x = MyType(1) MyType(1)
julia> x(1, 2) 4 ``` My problem is that the function is in a closure, and it gives me the error :
ERROR: LoadError: syntax: local variable MyType cannot be used in closure declaration
| 00:11:31 |
dionisos | I am very probably misunderstanding something. | 00:12:22 |
qwjyh | ```
julia> macro genfunc(t)
quote
function test(a::$t, b::$t)
a.v + b.v
end
end
end
@genfunc (macro with 1 method)
julia> test = @genfunc MyType
#83#test (generic function with 1 method)
julia> test(x, y)
3
``` | 00:14:55 |
dionisos | I am wondering if I can do it without a macro, I will do it with a macro if there is not another way, but I feel like there is some hole in my understanding and finding how to do it without a macro will help. | 00:18:07 |
dionisos | In reply to @qwjyh:matrix.org Simple example for the syntax: ``` julia> struct MyType v::Int64 end
julia> function (t::MyType)(a::T, b::T) where {T <: Integer} a + b + t.v end
julia> x = MyType(1) MyType(1)
julia> x(1, 2) 4 ``` I realize I misunderstood you question, but at least now I understand the syntax you where using, thank you. | 00:25:22 |
dionisos | Ok after some testes and research, it seems like I should use a macro for this. | 00:27:20 |
dionisos | Thank you for you help qwjyh | 00:27:34 |
dionisos | In reply to @qwjyh:matrix.org Simple example for the syntax: ``` julia> struct MyType v::Int64 end
julia> function (t::MyType)(a::T, b::T) where {T <: Integer} a + b + t.v end
julia> x = MyType(1) MyType(1)
julia> x(1, 2) 4 ``` * I realize I misunderstood your question, but at least now I understand the syntax you where using, thank you. | 00:27:44 |
30 Dec 2023 |
| @tuxtuxtuxtuxtux:opensuse.org set a profile picture. | 14:54:13 |
| @tuxtuxtuxtuxtux:opensuse.org removed their profile picture. | 14:54:31 |
| @tuxtuxtuxtuxtux:opensuse.org set a profile picture. | 14:56:09 |
| @tuxtuxtuxtuxtux:opensuse.org removed their profile picture. | 14:57:05 |
31 Dec 2023 |
| @jyxu:mozilla.org joined the room. | 08:32:28 |
1 Jan 2024 |
| @tuxtuxtuxtuxtux:opensuse.org left the room. | 10:13:47 |
3 Jan 2024 |
@malte:maltee.de | Can I interpolate a heatmap while plotting? I have a function that takes two values as input and produces a third one as an output. I want to display the output on the x axis and the two inputs on the y and z axis. Typically, heatmaps are laid out on a grid, but I can't produce a grid because I cannot reverse my functions. | 09:11:29 |
13 Jan 2024 |
| psydroid changed their profile picture. | 21:03:16 |
15 Jan 2024 |
| psydroid changed their profile picture. | 08:33:11 |
| uncomfy joined the room. | 12:50:50 |
22 Jan 2024 |
| iqbal1975 set a profile picture. | 10:31:38 |
23 Jan 2024 |
| @waldyrious:matrix.org left the room. | 22:14:03 |
28 Jan 2024 |
| .slt joined the room. | 16:31:46 |
9 Feb 2024 |
| @sirfredrick:matrix.org left the room. | 00:03:25 |
| vwgsymnqkw joined the room. | 10:30:19 |
11 Feb 2024 |
| viplavswamituladhar joined the room. | 11:22:24 |