How to resolve the algorithm Morse code step by step in the EchoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Morse code step by step in the EchoLisp programming language

Table of Contents

Problem Statement

Morse code is one of the simplest and most versatile methods of telecommunication in existence. It has been in use for more than 175 years — longer than any other electronic encoding system.

Send a string as audible Morse code to an audio device   (e.g., the PC speaker).

As the standard Morse code does not contain all possible characters, you may either ignore unknown characters in the file, or indicate them somehow   (e.g. with a different pitch).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Morse code step by step in the EchoLisp programming language

Source code in the echolisp programming language

(require 'json)
(require 'hash)
(require 'timer)

;; json table from RUBY
(define morse-alphabet 
#'{"0":"-----","1":".----","2":"..---","3":"...--","4":"....-","5":".....","6":"-....","7":"--...","8":"---..","9":"----.","!":"---.","$":"...-..-","'":".----.","(":"-.--.",")":"-.--.-","+":".-.-.",",":"--..--","-":"-....-",".":".-.-.-","/":"-..-.",":":"---...",";":"-.-.-.","=":"-...-","?":"..--..","@":".--.-.","A":".-","B":"-...","C":"-.-.","D":"-..","E":".","F":"..-.","G":"--.","H":"....","I":"..","J":".---","K":"-.-","L":".-..","M":"--","N":"-.","O":"---","P":".--.","Q":"--.-","R":".-.","S":"...","T":"-","U":"..-","V":"...-","W":".--","X":"-..-","Y":"-.--","Z":"--..","[":"-.--.","]":"-.--.-","_":"..--.-"," ":"|"}'#)

(define MORSE (json->hash (string->json morse-alphabet)))

;; translates a string into morse string
;; use "|" as letters separator
(define (string->morse str morse)
(apply append (map string->list
	(for/list [(a (string-diacritics str))]
		(string-append
		(or (hash-ref morse (string-upcase a)) "?") "|")))))
	
(define (play-morse)
	(when EMIT ;; else return #f which stops (at-every)
		(case  (first EMIT)
		((".") (play-sound 'digit) (write "dot"))
		(("-") (play-sound 'tick) (write "dash"))
		(else (writeln) (blink)))
		(set! EMIT (rest EMIT))))


  

You may also check:How to resolve the algorithm Kronecker product based fractals step by step in the Factor programming language
You may also check:How to resolve the algorithm Day of the week step by step in the Julia programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Java programming language
You may also check:How to resolve the algorithm Strip comments from a string step by step in the Raku programming language
You may also check:How to resolve the algorithm Remove duplicate elements step by step in the Inform 7 programming language