Zulip Chat Archive

Stream: new members

Topic: local scope definition?


Shi Zhengyu (Dec 03 2021 at 13:20):

Hi all,
I was reading TPIL, and it says:
image.png
but I tried local keyword, it seems it can only prefix notations, infix, etc. but not definitions? How should I make a definition private scope (similar to private keyword in java or c++)?
Thanks!

Huỳnh Trần Khanh (Dec 03 2021 at 13:23):

you can't in lean 3

Huỳnh Trần Khanh (Dec 03 2021 at 13:23):

but in lean 4 you can

Shi Zhengyu (Dec 03 2021 at 13:25):

i see. Thanks!

Arthur Paulino (Dec 03 2021 at 13:27):

@Shi Zhengyu Just to mention, you can use markdown quote notation to quote things more easily with ctrl+c ctrl+v
Example:

> this is a quote

will be displayed as

this is a quote

So you don't need to take screenshots

Kyle Miller (Dec 03 2021 at 16:33):

Huỳnh Trần Khanh said:

you can't in lean 3

private works in Lean 3:

private def foo (n : ) :  := n + 1

def bar (n : ) :  := foo n + 1

Making definitions private makes it harder for downstream modules to prove things, though. A nice alternative is protected, which makes definitions require that they be qualified by their namespace:

namespace m

protected def foo (n : ) :  := n + 1

def bar (n : ) :  := m.foo n + 1

end m

open m

#check bar
#check foo -- error
#check m.foo

Last updated: Dec 20 2023 at 11:08 UTC