Re: "Subclassing" int in Pike code

Chris Angelico <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <CAPTjJmr7XbDZ-0Yki_XtWQbRyRrKvDoKDb0Wobf_DiXdgUC6VA@mail.gmail.com>
On Tue, Sep 30, 2014 at 10:00 PM, Henrik Grubbström <[email protected]> wrote:
>> class x(int num)
>> {
>>    mixed cast(string type) {if (type=="int") return num;}
>>    int(0..1) is_type(string type) {if (type=="int") return 1;}
>>    #define lhs(x) mixed `##x(mixed ... others) {return
>> this_program(`##x(num,@others));}
>
>                ^^^^
> This won't do what you intend (it will just recurse until you run out of
> stack or into MAX_ARGS). You need to prefix the call with predef::.

You sure it won't? What it does is it defines `+() to call `+(num,
@others) - where num is the embedded integer - and then calls
this_program() on the result, to turn it into a hex-flagged integer.
It appears to work; is it working by accident?

ChrisA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.