The cl-morse Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-morse Reference Manual

This is the cl-morse Reference Manual, version 1.0.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 03:50:19 2022 GMT+0.

Table of Contents


1 Introduction

cl-morse

unit tests

Morse code translation lib written in Common Lisp.

In version 0.1.0 only letters, spaces and a full stop are supported, more to come. Give me a shout or open an issue if you want to add a new feture to this library, please. Originally this library was created because I was a bit rusty at Common Lisp programming (haven't touched it for years of using Clojure) and to have something to check and try various forms of deployment.

Usage

Translates text (ignoring case) to morse code and back. The morse code follows a convention that each letter is ended by a forward slash (e.g. 'a' becomes '.-/'). Space is a single '/' and a full stop is two '//'. Which in effect means that letters are separated by a single slash, word by two slashes and sentences by three. When converting a morse code back to text, some ambiguities can happen. This library interprets '////' as '. ' although it could be interpreted as multiple spaces.

Some languages have specific coding for a group of characters, e.g. in Czech, 'ch' is considered a single letter and has a special morse code. This is not supported now.

If an unknown character or code is found, an error is signalled. A restart is provided to continue with the next character.

Installation

If you have quicklisp installed

cd ~/quicklisp/local-projects
git clone https://github.com/em7/cl-morse.git

when you run lisp

(ql:quickload "cl-morse")
(asdf:test-system :cl-morse)

otherwise you can clone the repo wherever ASDF finds it and load it.

Dependencies

Running

Package cl-morse exports four symbols:

The functions expect a string to convert as a parameter and returns a converted string. A keyword :skip-unknown-chars might be supplied (default nil). If true, skips unknown characters. If false, signals 'unknown-character when encounters one.

The 'unknown-character condition defines :report and has a reader unknown-ch which returns the character which could not be converted.

Example

see tests/main.lisp

(cl-morse:morse->string ".-/-.../")
> "ab"

(cl-morse:string->morse "ab")
> ".-/-.../"

(cl-morse:string->morse "aěščřb" :skip-unknown-chars t)
> ".-/-.../"

(handler-case  (cl-morse:string->morse "aěščřb")
  (cl-morse:unknown-character (c) (format t "~a~%" c)))
> Unknown charachter 'ě', could not be converted to morse code.

(handler-bind ((cl-morse:unknown-character
                          #'(lambda (c)
                              (format t "~a~%" c)
                              (invoke-restart 'cl-morse:skip-character))))
           (cl-morse:string->morse "aěščřb"))
           
> Unknown charachter 'ě', could not be converted to morse code.
> Unknown charachter 'š', could not be converted to morse code.
> Unknown charachter 'č', could not be converted to morse code.
> Unknown charachter 'ř', could not be converted to morse code.
>

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-morse

Library for translating ASCII letters to morse code and back.

Author

em7

License

BSD-3clause

Version

1.0.0

Dependency

cl-ppcre (system).

Source

cl-morse.asd.

Child Component

src (module).


3 Modules

Modules are listed depth-first from the system components tree.


Previous: , Up: Modules   [Contents][Index]

3.1 cl-morse/src

Source

cl-morse.asd.

Parent Component

cl-morse (system).

Child Component

main.lisp (file).


4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

4.1.1 cl-morse/cl-morse.asd

Source

cl-morse.asd.

Parent Component

cl-morse (system).

ASDF Systems

cl-morse.


Previous: , Up: Lisp   [Contents][Index]

4.1.2 cl-morse/src/main.lisp

Source

cl-morse.asd.

Parent Component

src (module).

Packages

cl-morse.

Public Interface
Internals

5 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

5.1 cl-morse

Source

main.lisp.

Use List
  • cl-ppcre.
  • common-lisp.
Public Interface
Internals

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Public Interface


6.1.1 Ordinary functions

Function: morse->string (morsestr &key skip-unknown-chars)

Converts the string with morse code to string with alpha characters. If :skip-unknown-chars is true,
ignores characters which cannot be converted to a alpha. Otherwise signals
’unknown-character condition with unknown-ch reader to get the unknown character. A restart ’skip-character is provided in case you want to e.g. log the characters but skip them.

Package

cl-morse.

Source

main.lisp.

Function: string->morse (str &key skip-unknown-chars)

Converts the string to a morse code. If :skip-unknown-chars is true,
ignores characters which cannot be converted to a morse code. Otherwise signals
’unknown-character condition with unknown-ch reader to get the unknown character. A restart ’skip-character is provided in case you want to e.g. log the characters but skip them.

Package

cl-morse.

Source

main.lisp.


6.1.2 Conditions

Condition: unknown-character

Is signalled when a character is not known and could not be converted to a morse code representation. The character is accessible through ’unknown-ch reader.

Package

cl-morse.

Source

main.lisp.

Direct superclasses

error.

Direct methods

unknown-ch.

Direct slots
Slot: ch

The unknown character itself.

Initargs

:ch

Readers

unknown-ch.

Writers

This slot is read-only.


6.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

6.2.1 Special variables

Special Variable: *alpha->morse*

Hashtable mapping alpha strings to morse code. Not case sensitive.

Package

cl-morse.

Source

main.lisp.

Special Variable: *morse->alpha*

Hashtable mapping morse code string to alpha.

Package

cl-morse.

Source

main.lisp.

Special Variable: *morselist*

List of tuples alpha morse.

Package

cl-morse.

Source

main.lisp.


6.2.2 Ordinary functions

Function: char->morse (c)

Converts a single character to a morse code. If character could not be converted, signals an error ’unknown-character.
Offers a restart ’skip-character which ignores the character and returns an empty string.

Package

cl-morse.

Source

main.lisp.

Function: init-hashtables ()

Initializes *alpha->morse* and *morse->alpha* hashtables from values in morselist

Package

cl-morse.

Source

main.lisp.

Function: morse->char (morsechr)

Converts one morse code character to alpha character. If character could not be converted, signals an error ’unknown-character. Offers a restart ’skip-character which ignorese the character and returns an empty string.

Package

cl-morse.

Source

main.lisp.

Function: tokenize-string (str)

Returns a list of strings which are morse tokens. The strings are shared with the ‘str‘ parameter. If str cannot be tokenized, returns NULL.

Package

cl-morse.

Source

main.lisp.


6.2.3 Generic functions

Generic Reader: unknown-ch (condition)
Package

cl-morse.

Methods
Reader Method: unknown-ch ((condition unknown-character))
Source

main.lisp.

Target Slot

ch.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts