From 74aabb6445ba76fdfece7494358915775458df4a Mon Sep 17 00:00:00 2001 From: zeroflag Date: Sun, 27 Jun 2021 13:36:18 +0200 Subject: [PATCH] share button + hist --- src/main/res/raw/misc.forth | 15 +++++++++++---- src/test/java/com/vectron/fcl/FclTest.java | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/res/raw/misc.forth b/src/main/res/raw/misc.forth index 3713b0a..8299a98 100644 --- a/src/main/res/raw/misc.forth +++ b/src/main/res/raw/misc.forth @@ -1,4 +1,11 @@ -: fib ( n1 n2 -- n1 n2 n3 ) 2dup + ; - -: nfib ( n -- .. ) -> n - 0 1 { fib } n times ; \ No newline at end of file +: hist ( c -- m ) + -> tbl { + -> elem + tbl elem at -> count + count nil = if + tbl elem 1 put + else + tbl elem count 1+ put + then + } each + tbl ; \ No newline at end of file diff --git a/src/test/java/com/vectron/fcl/FclTest.java b/src/test/java/com/vectron/fcl/FclTest.java index dde47b5..17a7ec7 100644 --- a/src/test/java/com/vectron/fcl/FclTest.java +++ b/src/test/java/com/vectron/fcl/FclTest.java @@ -1118,6 +1118,12 @@ public class FclTest { assertEquals(30, fcl.pop().intValue()); } + @Test + public void testHist() { + assertEquals("#[ 'a' 2 'b' 3 'c' 1 ]#", evalPop("'ababbc' hist").toString()); + assertEquals("#[ ]#", evalPop("'' hist").toString()); + } + private String transcript() { return transcript.content(); }