Zulip Chat Archive

Stream: general

Topic: Check whether variable exists


Daniel Donnelly (Aug 28 2019 at 18:11):

def object_instance_exists(self, o):
    pass

Hopefully o is a string

Daniel Donnelly (Aug 28 2019 at 18:12):

Part of my algorithm for connecting graphics items with Lean instances needs to check whether an object specified by o already exists. So how can we do that with Lean commands?

Johan Commelin (Aug 28 2019 at 18:13):

There is something like mk_fresh_name or something like that. I don't know anything about meta programming in Lean

Daniel Donnelly (Aug 28 2019 at 18:13):

@Johan Commelin thx, I'll look at my code again and see if I can use that instead

Daniel Donnelly (Aug 28 2019 at 18:14):

Can't really, unless I do a major redesign since I have:

Daniel Donnelly (Aug 28 2019 at 18:14):

def add_category(self, cat):
        if not self.interface().object_instance_exists(cat):
            self.interface().add_object_instance(cat)
        self.categories[id(cat)] = cat

Daniel Donnelly (Aug 28 2019 at 18:15):

Where interface() is the Lean interface

Daniel Donnelly (Aug 28 2019 at 18:15):

Shouldn't #check do the above?

Daniel Donnelly (Aug 28 2019 at 18:16):

I'll do some reading and figure out a way to make it work :)


Last updated: Dec 20 2023 at 11:08 UTC