rafaqz / mixers.jl Goto Github PK
View Code? Open in Web Editor NEWJulia mixin macros. Mixed, not stirred
License: Other
Julia mixin macros. Mixed, not stirred
License: Other
This is a neat idea to copy fields from one type to another. Is there a convenient way to do the same for functions?
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
MWE:
using Mixers
@mix Base.@kwdef struct Foo
bar = 1
end
fails with error:
ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:205
Symbol(::Any...) at strings/basic.jl:229
Stacktrace:
[1] push!(a::Vector{Symbol}, item::Expr)
@ Base ./array.jl:932
[2] chained_macros!(macros::Vector{Symbol}, ex::Expr)
@ Mixers ~/.julia/packages/Mixers/f3AVv/src/Mixers.jl:87
[3] chained_macros
@ ~/.julia/packages/Mixers/f3AVv/src/Mixers.jl:83 [inlined]
[4] defmacro(ex::Expr, prepend::Bool)
@ Mixers ~/.julia/packages/Mixers/f3AVv/src/Mixers.jl:37
[5] var"@mix"(__source__::LineNumberNode, __module__::Module, ex::Any)
@ Mixers ~/.julia/packages/Mixers/f3AVv/src/Mixers.jl:24
[6] eval
@ ./boot.jl:360 [inlined]
[7] eval
@ ./Base.jl:39 [inlined]
[8] repleval(m::Module, code::Expr, #unused#::String)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:157
[9] (::VSCodeServer.var"#69#71"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:123
[10] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging ./logging.jl:491
[11] with_logger
@ ./logging.jl:603 [inlined]
[12] (::VSCodeServer.var"#68#70"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:124
[13] #invokelatest#2
@ ./essentials.jl:708 [inlined]
[14] invokelatest(::Any)
@ Base ./essentials.jl:706
[15] macro expansion
@ ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
[16] (::VSCodeServer.var"#53#54")()
@ VSCodeServer ./task.jl:411
in expression starting at REPL[10]:1
but
using Mixers
using Base: @kwdef
@mix @kwdef struct Foo
bar = 1
end
works fine.
Mixers v0.1.1 on:
julia> versioninfo()
Julia Version 1.6.5
Commit 9058264a69 (2021-12-19 12:30 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 4
Someithing like:
abstract type Drink
@premix @with_kw struct Fruitjuice{P,B} {link to Drink}
pommegranite::P
orange::B
end
@mix @with_kw struct Soda{J} {link to Drink}
soda::J = 2u"L"
end
So that
struct Punch{L} <: Drink
vodka::L
end
would be equivalent to
@Fruitjuice @Soda struct Punch{L}
vodka::L
end
Sorry If I've misunderstood the proper usage.
First, great package, thanks for that!
Is there any fancy way to use @mix
or @premix
on existing mixed structs? I need a bit more nested levels...
Here is a non-working dummy example:
@premix struct FooTemplate
x
end
@FooTemplate struct Bar
y
end
# now create a @BarTemplate which contains both x and y
@premix BarTemplate Bar # this will of course not work
@BarTemplate Baz
z
end
So that Baz
now has the fields x
, y
and z
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.