Naming Conventions

Scalar

Vector

Matrix

Any
rank

Non-
scalar

Boolean

BS

BV

BM

BA

BN

Integer

IS

IV

IM

IA

IN

Float

FS

FV

FM

FA

FN

Numeric

NS

NV

NM

NA

NN

Character

CS

CV

CM

CA

CN

Enclosed
vector

ES

EV

EM

EA

EN

enclosed
Text vector

TS

TV

TM

TA

TN

Simple

SS

SV

SM

SA

SN

Any

AS

AV

AM

AA

AN

phrase e.g.: .X...Y. ⍝ X←BS; Y←IV

combinations: use ISV for Integer scalarvector

B3, I4 &c. to specify higher ranks.

Open full technical reference

DeleteTrailingBlanks

The task to delete trailing blanks from a string is a very common one. APL dialects might provide a utility function for this. Common names are rtb (remove trailing blanks) and dtb (delete trailing blanks). There are a couple of approaches available but one which is supposed to run in all flavours of APL is this one:

          (-+/∧\' '=⌽CV)↓CV

Examples

      ⎕FX ⊃'r←dtb cv' 'r←(-+/∧\'' ''=⌽cv)↓cv'
      (dtb 'Hello, world    '),'|'
Hello, world|

Specialities

Dyalog

Show more information

Strangely, there is no idiom available for this in Dyalog at present (2010-08). However, there is an idiom for removing leading blanks. Question is whether one can take advantage of that idiom by saying

          ⌽{(+/∧\' '=⍵)↓⍵}⌽⍵

Indeed this is the case. Here the general expression is compared with the expression that makes use of the idiom:

      t1←'⌽{(+/∧\'' ''=⍵)↓⍵}⌽'' hello  world    '''
      t2←'{(-+/∧\'' ''=⌽⍵)↓⍵}'' hello  world    '''
      cmpx t1 t2
⌽{(+/∧\' '=⍵)↓⍵}⌽' hello  world    ' → 1.8E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕              
 {(-+/∧\' '=⌽⍵)↓⍵}' hello  world    ' → 2.8E¯6 | +53% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕

Although the second expression adds two operation it's still significantly faster. (The cmpx function is from JohnScholes brilliant dfns workspace from the "Samples" lib)

Compatibility

Checked with: APL21, APLX, Dyalog, NARS2000

Test Cases

Show test cases

 Test
 ⎕IO←0      ⍝ You may change this; however, zero IS the default in the Phrasebook
⍝⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
 ⎕FX⊃'r←dtb cv' 'r←(-+/∧\'' ''=⌽cv)↓cv'
⍝ ---- Start Test cases (do not delete this!)
 ''≡dtb''
 (,'a')≡dtb'a'
 (,'a')≡dtb'a '
 ' hello,  world'≡dtb' hello,  world  '

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: DeleteLeadingBlanks and DeleteMultipleBlanks

Mentor: KaiJaeger

Tags: <Blanks> <DeleteBlanks> <RemoveBlanks>


CategoryPhrasesAll - CategoryPhraseCharacterManipulation

  1. APL2: see Apl2Problems (1)

PhraseBook/DeleteTrailingBlanks (last edited 2011-12-26 10:37:04 by KaiJaeger)