You are right, I had defined it earlier and apparently the redefinition restriction does not apply to empty immutables. Anyway, this should work:
macro deftype(name) esc(:(immutable $name end)) end On Fri, Mar 6, 2015 at 8:19 PM, Kaj Wiik <kaj.w...@gmail.com> wrote: > Thanks for the reply! > > Hmm, well my intention was to build the definition piecewise inserting the > fields after this line without end, now I see that it will not work. > Perhaps I should make a template and push! fields to ex.args[3].args? > > In fact your suggestion does not work in my Julia: > julia> macro deftype(name) > ex1 = :(immutable $name end) > end > > julia> @deftype foo > > julia> foo() > ERROR: foo not defined > > > > The reason is: > julia> macroexpand(:(@deftype foo)) > :(immutable #133#foo > end) > > > I.e. the type name is modified... How to escape it? > > Thanks, > Kaj > > julia> versioninfo() > Julia Version 0.3.6 > Commit a05f87b* (2015-01-08 22:33 UTC) > Platform Info: > System: Linux (x86_64-linux-gnu) > CPU: AMD A6-4455M APU with Radeon(tm) HD Graphics > WORD_SIZE: 64 > BLAS: libopenblas (NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY) > LAPACK: liblapack.so.3 > LIBM: libopenlibm > LLVM: libLLVM-3.3 > > > On Friday, March 6, 2015 at 5:35:23 PM UTC+2, Isaiah wrote: >> >> Missing an `end` in both expressions. >> >>> >> julia> macro deftype(name) >> >>> ex1 = :(immutable $name end) >> end >> julia> @deftype foo >> julia> foo() >> >> On Thu, Mar 5, 2015 at 5:02 AM, Kaj Wiik <kaj....@gmail.com> wrote: >> >>> I have been trying to write a macro that would generate fields in a >>> for-loop. >>> >>> However, when I try to generate the first line I get an error: >>> >>> julia> macro deftype(name,artype,num) >>> ex1 = :(esc( immutable $name)) >>> ERROR: syntax: unexpected ")" >>> >>> julia> macro deftype(name,artype,num) >>> ex1 = :(esc(quote immutable $name end)) >>> ERROR: syntax: extra token ")" after end of expression >>> >>> >>> There must be a way to do this, I cannot find how... >>> >>> Thanks, >>> Kaj >>> >>> >>