Skip to content

Commit

Permalink
added seq pakage and made 'replace' handle DoubleSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
nietoperz809 committed Mar 26, 2023
1 parent 072006f commit fc53ca9
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/jforth/CayleyTable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package jforth;

import jforth.seq.DoubleMatrix;

public class CayleyTable {
private final DoubleMatrix _m;

Expand Down
1 change: 1 addition & 0 deletions src/jforth/JForth.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory;
import guishell.JfTerminalPanel;
import jforth.forthwords.PredefinedWords;
import jforth.seq.*;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.fraction.Fraction;
Expand Down
1 change: 1 addition & 0 deletions src/jforth/StorageWord.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jforth.forthwords.PredefinedWords;
import jforth.forthwords.WordHelpers;
import jforth.seq.DoubleSequence;
import tools.Utilities;

public final class StorageWord extends BaseWord {
Expand Down
3 changes: 2 additions & 1 deletion src/jforth/forthwords/Filler1.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jforth.*;
import jforth.audio.SAMSpeech;
import jforth.audio.WaveTools;
import jforth.seq.*;
import org.apache.commons.math3.analysis.function.*;
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
Expand Down Expand Up @@ -2201,7 +2202,7 @@ else if (o1 instanceof Fraction) {

_fw.add(new PrimitiveWord
(
"toMix", "Create Mixed List from Double List",
"toMix", "Create Mixed List from stack content",
(dStack, vStack) ->
{
MixedSequence mix = new MixedSequence();
Expand Down
24 changes: 18 additions & 6 deletions src/jforth/forthwords/Filler2.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jforth.audio.MusicTones;
import jforth.audio.SynthToneBase;
import jforth.audio.WaveTools;
import jforth.seq.*;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.fraction.Fraction;
import org.mathIT.util.FunctionParser;
Expand Down Expand Up @@ -1701,12 +1702,23 @@ public void run() {
(dStack, vStack) ->
{
try {
StringSequence ss = Utilities.readStringSequence(dStack);
ArrayList<String> sl = ss.get_list();
String in = Utilities.readString(dStack);
String out = in.replaceAll(sl.get(0), sl.get(1));
dStack.push(out);
return 1;
Object o = dStack.pop();
StringSequence ss = Utilities.getStringSequence(o);
if (ss != null) {
ArrayList<String> sl = ss.get_list();
String in = Utilities.readString(dStack);
String out = in.replaceAll(sl.get(0), sl.get(1));
dStack.push(out);
return 1;
} else {
DoubleSequence ds = Utilities.getDoubleSequence(o);
ArrayList<Double> sl = ds.get_list();
DoubleSequence src = Utilities.readDoubleSequence(dStack);
DoubleSequence dst = DoubleSequence.replace (src, sl.get(0), sl.get(1));
dStack.push(dst);
return 1;

}
} catch (Exception e) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/jforth/forthwords/Filler3.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jforth.forthwords;

import jforth.DoubleSequence;
import jforth.seq.DoubleSequence;
import jforth.PrimitiveWord;
import jforth.WordsList;
import org.apache.commons.math3.analysis.function.HarmonicOscillator;
Expand Down
4 changes: 4 additions & 0 deletions src/jforth/forthwords/WordHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import jforth.*;
import jforth.ControlWords.LoopControlWord;
import jforth.seq.DoubleSequence;
import jforth.seq.MixedSequence;
import jforth.seq.SequenceBase;
import jforth.seq.StringSequence;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.fraction.Fraction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jforth;
package jforth.seq;

import org.apache.commons.math3.linear.BlockRealMatrix;
import org.apache.commons.math3.linear.MatrixUtils;
Expand All @@ -16,7 +16,7 @@ public DoubleMatrix (RealMatrix src)
super(src.getData());
}

DoubleMatrix (int rows, int cols)
public DoubleMatrix(int rows, int cols)
{
super(rows, cols);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public static DoubleMatrix fromSequenceArray (ArrayList<DoubleSequence> arr)
return res;
}

static DoubleMatrix parseMatrix (String in, int base)
public static DoubleMatrix parseMatrix(String in, int base)
{
if (base != 10)
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jforth;
package jforth.seq;

import jforth.JForth;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunctionLagrangeForm;
import org.apache.commons.math3.fitting.PolynomialCurveFitter;
Expand Down Expand Up @@ -412,4 +413,17 @@ public double[] transformInnerArray (Func<double[], double[]> action) {
return action.apply(asPrimitiveArray());
}

public static DoubleSequence replace (DoubleSequence in, double old, double nev) {
ArrayList<Double> ar = in._list;
ArrayList ar2 = new ArrayList<Double>();
for (Double aDouble : ar) {
if (aDouble == old)
ar2.add(nev);
else
ar2.add(aDouble);
}
DoubleSequence ret = new DoubleSequence();
ret._list.addAll(ar2);
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jforth;
package jforth.seq;

import org.apache.commons.math3.fraction.Fraction;
import tools.Utilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package jforth;
package jforth.seq;

// TODO: experimental class

import jforth.JForth;
import tools.Utilities;

import java.util.ArrayList;
Expand All @@ -20,35 +21,9 @@ public MixedSequence (ArrayList<?> ar) {
this._list = ar;
}

public void addAnything (Object o)
{
public void addAnything (Object o) {
_list.add(o);
}
//
// public MixedSequence (String[] in)
// {
// for (int s=0; s<in.length; s++) {
// boolean ret = JForth.doForKnownWordsUnmixed(in[s], this._list::add, 10);
// if (!ret)
// _list.add(in[s]);
// }
// }
//
// public MixedSequence (String csv)
// {
// this (csv.split (";"));
// }
//
// public static MixedSequence parseSequence (String in)
// {
// String seq = Utilities.extractSequence (in);
// if (seq == null)
// {
// return null;
// }
// return new MixedSequence (seq);
// }
//

public static MixedSequence parseSequence (String in) {
if (in.startsWith("{") && in.endsWith("}")) {
Expand Down
14 changes: 12 additions & 2 deletions src/jforth/SequenceBase.java → src/jforth/seq/SequenceBase.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jforth;
package jforth.seq;

import org.apache.commons.math3.fraction.Fraction;

Expand All @@ -7,7 +7,7 @@
import java.util.LinkedHashSet;

public class SequenceBase<E extends Comparable<E>> implements Cloneable, java.io.Serializable {
protected ArrayList<E> _list = new ArrayList<>();
public ArrayList<E> _list = new ArrayList<>();

public SequenceBase() {
}
Expand Down Expand Up @@ -216,4 +216,14 @@ public boolean equals(Object other) {
return test.size() == 0;
}

@Override
public SequenceBase<E> clone() {
try {
SequenceBase<E> clone = (SequenceBase<E>) super.clone();
clone._list = new ArrayList<>(_list);
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

// not used

package jforth;
package jforth.seq;


import jforth.StringEscape;
import tools.Utilities;

import java.util.*;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/BuildInfo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tools;

public class BuildInfo {
private static final String BUILD_NUMBER = "3481";
private static final String BUILD_DATE = "02/28/2023 05:59:30 PM";
private static final String BUILD_NUMBER = "3495";
private static final String BUILD_DATE = "03/26/2023 08:40:20 PM";

public static final String buildInfo = "JForth, Build: " + BUILD_NUMBER + ", " + BUILD_DATE
+ " -- " + System.getProperty("java.version");
Expand Down
3 changes: 3 additions & 0 deletions src/tools/Utilities.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package tools;

import jforth.*;
import jforth.seq.DoubleMatrix;
import jforth.seq.DoubleSequence;
import jforth.seq.StringSequence;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.complex.Complex;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue Feb 28 17:59:30 CET 2023
build.number=3482
#Sun Mar 26 20:40:20 CEST 2023
build.number=3496

0 comments on commit fc53ca9

Please sign in to comment.