master > master: codego - minor cleanup
This commit is contained in:
parent
39be87d52f
commit
9b225b0551
23
codego/aussagenlogik/formulae/formulae_advanced.go
Normal file
23
codego/aussagenlogik/formulae/formulae_advanced.go
Normal file
@ -0,0 +1,23 @@
|
||||
package formulae
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* METHOD Get Atoms
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func schemeGetAtoms(fml Formula, prevValues [](*[]Formula)) *[]Formula {
|
||||
if fml.IsAtom() {
|
||||
return &[]Formula{fml.Copy()}
|
||||
} else {
|
||||
var results = []Formula{}
|
||||
for _, prevValue := range prevValues {
|
||||
results = append(results, *prevValue...)
|
||||
}
|
||||
return &results
|
||||
}
|
||||
}
|
||||
|
||||
var fnGetAtoms = CreateFromSchemeFmlsValued(schemeGetAtoms)
|
||||
|
||||
func (fml Formula) GetAtoms() []Formula {
|
||||
return *fnGetAtoms(fml)
|
||||
}
|
@ -28,18 +28,36 @@ func (fml *Formula) SetExpr(expr string) { fml.expr = expr }
|
||||
|
||||
func (fml Formula) GetExpr() string { return fml.expr }
|
||||
|
||||
func (fml *Formula) SetSubformulae(children [](*Formula)) {
|
||||
fml.subformulae = children
|
||||
fml.valence = len(children)
|
||||
func (fml *Formula) SetSubformulae(subfmls [](*Formula)) {
|
||||
fml.subformulae = subfmls
|
||||
fml.valence = len(subfmls)
|
||||
}
|
||||
|
||||
func (fml Formula) GetSubFormulae() []Formula {
|
||||
var n int = fml.valence
|
||||
var children = make([]Formula, n)
|
||||
var subfmls = make([]Formula, n)
|
||||
for i, subfml := range fml.subformulae {
|
||||
children[i] = *subfml
|
||||
subfmls[i] = *subfml
|
||||
}
|
||||
return children
|
||||
return subfmls
|
||||
}
|
||||
|
||||
func (fml Formula) GetAllSubFormulae() []Formula {
|
||||
var subfml = fml.GetSubFormulae()
|
||||
var result = []Formula{fml.Copy()}
|
||||
for _, child := range subfml {
|
||||
result = append(result, child.GetAllSubFormulae()...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (fml Formula) GetAllSubFormulaeStrict() []Formula {
|
||||
var subfml = fml.GetSubFormulae()
|
||||
var result = []Formula{}
|
||||
for _, child := range subfml {
|
||||
result = append(result, child.GetAllSubFormulae()...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (fml Formula) GetChild(indexOpt ...int) Formula {
|
||||
@ -84,17 +102,27 @@ func (fml Formula) pretty(preindent string, tab string, prepend string, depth in
|
||||
}
|
||||
}
|
||||
|
||||
// shallow copy
|
||||
func (fml Formula) Copy() Formula {
|
||||
return Formula{
|
||||
expr: fml.expr,
|
||||
kind: fml.kind,
|
||||
valence: fml.valence,
|
||||
subformulae: fml.subformulae,
|
||||
}
|
||||
}
|
||||
|
||||
func (fml Formula) Deepcopy() Formula {
|
||||
var children = make([](*Formula), len(fml.subformulae))
|
||||
for i, child := range fml.subformulae {
|
||||
childCopy := child.Deepcopy()
|
||||
children[i] = &childCopy
|
||||
var subfmls = make([](*Formula), len(fml.subformulae))
|
||||
for i, subfml := range fml.subformulae {
|
||||
subfmlCopy := subfml.Deepcopy()
|
||||
subfmls[i] = &subfmlCopy
|
||||
}
|
||||
return Formula{
|
||||
expr: fml.expr,
|
||||
kind: fml.kind,
|
||||
valence: fml.valence,
|
||||
subformulae: children,
|
||||
subformulae: subfmls,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user