For your first point, I'm pretty sure you are questioning Julia's design, and I don't think my macro changes the default behavior, so I'm not the person to answer your question. For example, this works in Julia: function stuff(x::Int=(1+1)) end
For the second point, I've added some tests and such to the gist, and added a bit better error message. If I run into a situation where it breaks, I'll update the gist. Please let me know if you have a reproducible case where it breaks. For the third point, this macro is only intended for use when declaring typed function parameters, and I added an error message to clarify. If you are just using "Any" by leaving off the type, then there is no point in calling this macro in the first place, since you'll get Julia's default behavior and don't even have a type to make a Union with. On Friday, May 9, 2014 11:04:41 AM UTC-4, David Moon wrote: > > Google groups wouldn't let me send this by email. I apologize if there is > any duplication. > > On May 9, 2014, at 10:37 AM, Adam Smith wrote: > > > My main reason for using eval() is to convert from a Symbol to a > > Type. If they supplied a full expression like (1 + 1) as the > > default value for an argument, well, Julia supports that anyway, so > > eval()ing it once inside the macro and saving the result for all > > future calls matches the behavior of python (I don't know if Julia > > matches python behavior here). > > > 1 + 1 is still a constant. What if the default value is not a > > constant? Even worse, what if the default expression has side- > > effects when evaluated? > > > I'm really not sure what to make of your statement "the unfortunate > > need to throw in esc in a couple places to trick Julia into using > > the intended context for ptype and default." The macro seems to be > > working well right now; where do I need to add esc()? > > > I think the problem will show up if the macro is defined in one > > module and used by a function definition in another module and the > > default or the ptype uses symbols that are not visible in the module > > where the @maybe macro is defined. Julia's hygiene does not > > currently really work in a correct way, so you have to insert esc > > calls here and there. This makes Julia macros harder to use than is > > really necessary, but it has not been fixed yet. > > > By the way, instead of @assert argexpr.head == :(::) it would be > > better to handle the case where the ptype is not specified and > > defaults to Any, even though means the macro does not really need to > > do anything. Don't you think that would be less surprising to users? > >
