Skip to content

How to use cuecontext.Context to compile definitions and concrete values in multiple passes #988

Answered by cueckoo
cueckoo asked this question in Q&A
Discussion options

You must be logged in to vote

Original reply by @mpvl in cuelang/cue#988 (comment)

The Context does not retain anything. The context just holds indices for mapping field names, builtins, etc. But there is no retention otherwise.

However, you can pass a "scope" which is used to resolve all unresolved identifiers:

	ctx := cuecontext.New()

	def := ctx.CompileString(`
#Def: {
	id: string
    version: string
}`)

	val := ctx.CompileString(`
v: #Def & { id: "hi" }
	`, cue.Scope(def)) // USE def to RESOLVE UNRESOLVED IDENTIFIERS, LIKE #Def

Replies: 1 comment 2 replies

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
2 replies
@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

Answer selected by cueckoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant