a = RandomChoice[{a,2}]&
a[]
There are other ways to achieve this example, but I wish to do more complicated things similar to this using this method.
Can I get this to continue until there are no a
s left to resolve, without producing a stack overflow by trying to resolve {a,2}
before making the choice? Instead making the choice and resolving only the symbol chosen.
Here is a way to have
RandomChoice
evaluate a function only when selected:this prints "evaluate g" just when randomly selected and outputs eg.
This is another way, maybe a bit cleaner:
this works fine recursively:
Though as i said in comment it simply returns 2 every time since it recurses until 2 is chosen.
I do not understand the entirety of the question and my guess is there is a better way to accomplish what you want.