]> gitweb.factorcode.org Git - factor.git/commitdiff
fix morse for characters that don't exist like "\n". "resource:core/kernel/kernel...
authorDoug Coleman <erg@jobim.local>
Sun, 26 Apr 2009 06:25:19 +0000 (01:25 -0500)
committerDoug Coleman <erg@jobim.local>
Sun, 26 Apr 2009 06:25:19 +0000 (01:25 -0500)
extra/morse/morse-tests.factor
extra/morse/morse.factor

index fd52df1c4d54987bf06ca7fe78e480c9554d04b6..13818a06a019f4105ed827b689813c2c077a9626 100644 (file)
@@ -41,3 +41,4 @@ IN: morse.tests
     MORSE] ] unit-test
 ! [ ] [ "sos" 0.075 play-as-morse* ] unit-test
 ! [ ] [ "Factor rocks!" play-as-morse ] unit-test
+! [ ] [ "\n" play-as-morse ] unit-test
index ef4b9d4b889520b12d93ea6a05950472f410ef02..20989f2f2f45e4480a081d4bf7de334e5d2e1805 100644 (file)
@@ -3,13 +3,15 @@
 USING: accessors ascii assocs biassocs combinators hashtables kernel lists literals math namespaces make multiline openal parser sequences splitting strings synth synth.buffers ;
 IN: morse
 
+ERROR: no-morse-code ch ;
+
 <PRIVATE
 
 CONSTANT: dot-char CHAR: .
 CONSTANT: dash-char CHAR: -
 CONSTANT: char-gap-char CHAR: \s
 CONSTANT: word-gap-char CHAR: /
-CONSTANT: unknown-char CHAR: ?
+CONSTANT: unknown-char "?"
 
 PRIVATE>
 
@@ -74,10 +76,10 @@ CONSTANT: morse-code-table $[
 ]
 
 : ch>morse ( ch -- morse )
-    ch>lower morse-code-table at [ unknown-char ] unless* ;
+    ch>lower morse-code-table at unknown-char or ;
 
 : morse>ch ( str -- ch )
-    morse-code-table value-at [ char-gap-char ] unless* ;
+    morse-code-table value-at char-gap-char or ;
     
 <PRIVATE
     
@@ -148,12 +150,13 @@ CONSTANT: beep-freq 880
         source get source-play
     ] with-scope ; inline
 
-: play-char ( ch -- )
+: play-char ( string -- )
     [ intra-char-gap ] [
         {
             { dot-char [ dot ] }
             { dash-char [ dash ] }
             { word-gap-char [ intra-char-gap ] }
+            [ drop intra-char-gap ]
         } case
     ] interleave ;