Skip to content

Language: Remove @splice in favor of a special token indicating to splice? #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fsaad opened this issue Jan 22, 2019 · 3 comments
Closed
Labels

Comments

@fsaad
Copy link
Collaborator

fsaad commented Jan 22, 2019

@gen function foo()
    @addr(normal(0, 1), :y)
end

@gen function bar_splice()
    @addr(bernoulli(0.5), :x)
    @splice(foo())
end

@gen function bar_addr()
    @addr(bernoulli(0.5), :x)
    @addr(foo(), :z)
end;

Is there really a need for the gen macro @splice? It seems like a new concept that can be avoided by reusing @addr. (Moreover, the name is confusing since it is not clear what is being "spliced"---the address---so it should be probably called @addr_splice at least.)

A suggested design which seems cleaner and reuses @addr is to use a sentinel value e.g. the empty tuple (), or nothing as an indicator for requesting splice:

@gen function bar_splice()
    @addr(bernoulli(0.5), :x)
    @addr(foo(), ())
end

and this way there is no need both @addr and @splice.

@marcoct
Copy link
Collaborator

marcoct commented Jan 23, 2019

That's an interesting suggestion. What about just not passing any address token at all:

@gen function bar_splice()
    @addr(bernoulli(0.5), :x)
    @addr(foo()) # splice it
end

This more clearly distinguishes the hierarchical namespace case from the splicing case, than using a reserved address token to represent splicing.

Currently, all Julia values are valid address tokens, and it seems very desirable to keep it this way. This would prohibit using some reserved value like () or nothing to indicate the need to splice.

@fsaad
Copy link
Collaborator Author

fsaad commented Jan 23, 2019

I think either is fine. When I considered @addr(foo()) my sense was that having a special token e.g. @addr(foo, ()) is more consistent with the usual syntax @addr(foo(), :r). Concerns with having nothing i.e. @addr(foo()) are

(i) it might suggest the addresses are gobbled or untraced, as opposed to being prefixed by nothing and "spliced" into the current namespace; and

(ii) something like @addr(normal(0,1)) won't work (although neither will @splice(normal(0,1) so that is probably okay).

I can see the advantage of having all Julia values as valid address tokens (although it is rather strange that Julia allows Dicts to be keyed by mutable structures like a list, unlike Python which will claim list is unhashable).

@marcoct
Copy link
Collaborator

marcoct commented Feb 9, 2019

As of probcomp/GenExperimental.jl#67, @splice(expr) is replaced with @trace(expr) (i.e. the form of @trace, which replaces @addr, but without an address).

@marcoct marcoct closed this as completed Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants