Log In  

Not really a bug, but I accidentally discovered that '!' now gets replaced with 'self' at runtime, except when followed by '=':

> !ish = 42
> ?selfish
42

This is a bit confusing because in other languages, ! is an operator, whereas here it behaves almost like any other letter.

P#75065 2020-04-20 21:34

Whaaaaaaaaaaaaaaaaaaaaaaaaaaaaat.
The "!ish" behaviour is odd but "!.x = 3" is nice.
I'm starting to wonder whether 0.2.0 has more... secret syntax.

P#75096 2020-04-21 05:29

yep, bad idea.

not sure what the deal is with "self" anyway. it's just a very tiny convenience, you don't have to use it.

o = {
    set_a = function(m,x) -- explicit m as "self"
        m.a = x
    end
}

function o:set_b(x) -- implicit self
    self.b = x      --  <-- you really asked for it
end

function o.set_c(m,x) -- explicit m as "self"
    m.c = x
end

-- o passed as implicit "self"
o:set_a(1)
o:set_b(2)
o:set_c(3)
?o.a..o.b..o.c

 -- explicit "self"
o.set_a(o,3)
o.set_b(o,2)
o.set_c(o,1)
?o.a..o.b..o.c

"m" or whatever, just use a cat glyph instead...

P#75109 2020-04-21 11:51

This was something I'd asked for in the past. I actually asked for $ as short for self, but I guess $ as peek4 already existed.

I suspect the fact that it's not delimited properly is just a bug.

Also I wouldn't consider it a done deed. I think there's a reason why it's undocumented. Last I heard, zep wasn't sure if he liked the idea either. You might want to hold off on using it.

P#75125 2020-04-21 17:08 ( Edited 2020-04-22 05:00)

@ultrabrite

It's true you can define your own name for self, but it does require using the full dotted or inline prototype for methods. With this alias, you can still define blah:method() and it'll just work.

P#75126 2020-04-21 17:09

And it's gone. Ah well. :)

P#75293 2020-04-24 15:05

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 10:54:40 | 0.018s | Q:19